forked from DGNum/liminix
services & targets
This commit is contained in:
parent
7705bc2a8e
commit
9da241d8ec
3 changed files with 69 additions and 45 deletions
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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";
|
wantedBy = [ "default.target" ];
|
||||||
};
|
unitConfig = {
|
||||||
sysinit-target = targetToUnit {
|
Description = "Serial Shell";
|
||||||
name = "sysinit.target";
|
Before = [ "default.target" ];
|
||||||
aliases = [];
|
};
|
||||||
wantedBy = [];
|
script = ''
|
||||||
requiredBy = [];
|
#!/bin/ash
|
||||||
upheldBy = [];
|
# . /etc/profile
|
||||||
unitConfig.Description = "sysinit.target";
|
exec /bin/ash < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0
|
||||||
};
|
'';
|
||||||
agetty = serviceToUnit {
|
|
||||||
name = "getty.service";
|
|
||||||
aliases = [];
|
|
||||||
wantedBy = [ "default.target" ];
|
|
||||||
requiredBy = [];
|
|
||||||
upheldBy = [];
|
|
||||||
environment = {};
|
|
||||||
unitConfig = {
|
|
||||||
Description = "Serial Shell";
|
|
||||||
Before = [ "default.target" ];
|
|
||||||
};
|
};
|
||||||
serviceConfig.ExecStart =
|
};
|
||||||
let
|
targets = {
|
||||||
login = pkgs.writeScript "login" ''
|
default = { };
|
||||||
#!/bin/ash
|
sysinit = { };
|
||||||
. /etc/profile
|
|
||||||
exec /bin/ash
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
"${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
27
modules/systemd/types.nix
Normal file
27
modules/systemd/types.nix
Normal 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
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in a new issue