wip! services & targets

This commit is contained in:
catvayor 2024-10-06 18:38:36 +02:00
parent 7705bc2a8e
commit e141c0827c
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
3 changed files with 69 additions and 45 deletions

View file

@ -49,9 +49,6 @@ in {
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

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