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

Draft
lbailly wants to merge 8 commits from lbailly/liminix:systemd into main
3 changed files with 69 additions and 45 deletions
Showing only changes of commit 9da241d8ec - Show all commits

View file

@ -49,9 +49,6 @@ in {
type = types.attrsOf type_service;
};
units = mkOption {
type = utils.systemdUtils.types.units;
};
system.callService = mkOption {
type = types.functionTo (types.functionTo types.anything);
};

View file

@ -11,6 +11,7 @@ let
nameValuePair
mkMerge
mapAttrsToList
mkOption
;
inherit (pkgs.pseudofile) dir symlink;
inherit (utils.systemdUtils.lib)
@ -18,13 +19,15 @@ let
serviceToUnit
;
systemd-types = import ./types.nix { inherit pkgs utils lib; };
units-texts = mapAttrs' (
_: unit:
nameValuePair unit.name {
file = unit.text;
mode = "0644";
}
) config.units;
) config.systemd.units;
units-aliases = mkMerge (
mapAttrsToList (
_: unit:
@ -33,7 +36,7 @@ let
${aka} = symlink "${unit.name}";
}) (unit.aliases or [ ])
)
) config.units
) config.systemd.units
);
units-extraWants = mkMerge (
mapAttrsToList (
@ -45,7 +48,7 @@ let
};
}) (unit.wantedBy or [ ])
)
) config.units
) config.systemd.units
);
units-extraUpholds = mkMerge (
mapAttrsToList (
@ -57,7 +60,7 @@ let
};
}) (unit.upheldBy or [ ])
)
) config.units
) config.systemd.units
);
units-extraRequires = mkMerge (
mapAttrsToList (
@ -69,49 +72,46 @@ let
};
}) (unit.requiredBy or [ ])
)
) config.units
) config.systemd.units
);
in
{
options = {
systemd = {
units = mkOption {
type = systemd-types.units;
};
services = mkOption {
type = systemd-types.services;
};
targets = mkOption {
type = systemd-types.targets;
};
};
};
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" ];
systemd = {
units = mkMerge [
(mapAttrs' (_: service: nameValuePair service.name (serviceToUnit service)) config.systemd.services)
(mapAttrs' (_: target: nameValuePair target.name (targetToUnit target)) config.systemd.targets)
];
services = {
getty = {
wantedBy = [ "default.target" ];
unitConfig = {
Description = "Serial Shell";
Before = [ "default.target" ];
};
script = ''
#!/bin/ash
# . /etc/profile
exec /bin/ash < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0
'';
};
serviceConfig.ExecStart =
let
login = pkgs.writeScript "login" ''
#!/bin/ash
. /etc/profile
exec /bin/ash
'';
in
"${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0";
};
targets = {
default = { };
sysinit = { };
};
};

27
modules/systemd/types.nix Normal file
View file

@ -0,0 +1,27 @@
{
pkgs,
lib,
utils
}:
let
inherit (utils.systemdUtils.lib) serviceConfig unitConfig;
inherit (utils.systemdUtils.unitOptions) stage2ServiceOptions;
stage2ServiceConfig = {
imports = [ serviceConfig ];
# Default path for systemd services. Should be quite minimal.
config.path = lib.mkAfter [
pkgs.coreutils
# pkgs.gnugrep
# pkgs.gnused
pkgs.systemd
];
};
in
{
inherit (utils.systemdUtils.types) units targets;
services = lib.types.attrsOf (lib.types.submodule [
unitConfig
stage2ServiceOptions
stage2ServiceConfig
]);
}