WIP: feat(systemd): switch to systemd #33

Draft
lbailly wants to merge 8 commits from lbailly/liminix:systemd into main
3 changed files with 133 additions and 38 deletions
Showing only changes of commit 7705bc2a8e - Show all commits

View file

@ -25,7 +25,13 @@ let
eval = evalModules { eval = evalModules {
modules = [ modules = [
{ ({ lib, pkgs, ... }: {
_module.args = {
utils = import "${nixpkgs}/nixos/lib/utils.nix" {
inherit lib pkgs;
config.systemd.globalEnvironment = {};
};
};
nixpkgs = { nixpkgs = {
source = nixpkgs; source = nixpkgs;
overlays = [ overlay ]; overlays = [ overlay ];
@ -33,7 +39,7 @@ let
"python-2.7.18.8" "python-2.7.18.8"
]; ];
}; };
} })
device.module device.module
liminix-config liminix-config
]; ];

View file

@ -2,7 +2,7 @@
## ============ ## ============
{ lib, pkgs, config, ...}: { lib, pkgs, utils, config, ...}:
let let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList; inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
@ -43,9 +43,15 @@ in {
''; '';
}; };
}; };
# deprecated
services = mkOption { services = mkOption {
type = types.attrsOf type_service; type = types.attrsOf type_service;
}; };
units = mkOption {
type = utils.systemdUtils.types.units;
};
system.callService = mkOption { system.callService = mkOption {
type = types.functionTo (types.functionTo types.anything); type = types.functionTo (types.functionTo types.anything);
}; };

View file

@ -1,41 +1,120 @@
{ pkgs, ... }: {
pkgs,
lib,
config,
utils,
...
}:
let let
inherit (lib)
mapAttrs'
nameValuePair
mkMerge
mapAttrsToList
;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
"getty.service" = { inherit (utils.systemdUtils.lib)
file = targetToUnit
let serviceToUnit
login = pkgs.writeScript "login" '' ;
#!/bin/ash
exec /bin/ash units-texts = mapAttrs' (
''; _: unit:
in nameValuePair unit.name {
'' file = unit.text;
[Unit] mode = "0644";
Description="Serial shell" }
) config.units;
units-aliases = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (aka: {
${aka} = symlink "${unit.name}";
}) (unit.aliases or [ ])
)
) config.units
);
units-extraWants = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.wants" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.wantedBy or [ ])
)
) config.units
);
units-extraUpholds = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.upholds" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.upheldBy or [ ])
)
) config.units
);
units-extraRequires = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.requires" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.requiredBy or [ ])
)
) config.units
);
[Service]
ExecStart=${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0
'';
mode = "0644";
};
"default.target" = {
file = ''
[Unit]
Description="target to boot"
Wants=getty.service
After=getty.service
AllowIsolate=yes
'';
};
"sysinit.target" = {
file = ''
[Unit]
Description="sysinit.target"
'';
};
in in
{ {
config = { config = {
units = {
default-target = targetToUnit {
name = "default.target";
aliases = [];
wantedBy = [];
requiredBy = [];
upheldBy = [];
unitConfig.Description = "target to boot";
};
sysinit-target = targetToUnit {
name = "sysinit.target";
aliases = [];
wantedBy = [];
requiredBy = [];
upheldBy = [];
unitConfig.Description = "sysinit.target";
};
agetty = serviceToUnit {
name = "getty.service";
aliases = [];
wantedBy = [ "default.target" ];
requiredBy = [];
upheldBy = [];
environment = {};
unitConfig = {
Description = "Serial Shell";
Before = [ "default.target" ];
};
serviceConfig.ExecStart =
let
login = pkgs.writeScript "login" ''
#!/bin/ash
. /etc/profile
exec /bin/ash
'';
in
"${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0";
};
};
kernel.config = { kernel.config = {
CGROUPS = "y"; CGROUPS = "y";
DEVTMPFS = "y"; DEVTMPFS = "y";
@ -55,9 +134,13 @@ in
filesystem = dir { filesystem = dir {
etc = dir { etc = dir {
systemd = dir { systemd = dir {
system = dir { system = dir (mkMerge [
inherit "default.target" "getty.service" "sysinit.target"; units-texts
}; units-aliases
units-extraWants
units-extraUpholds
units-extraRequires
]);
}; };
}; };
bin = dir { bin = dir {