2024-10-05 11:50:12 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
utils,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-30 19:38:13 +02:00
|
|
|
let
|
2024-10-05 11:50:12 +02:00
|
|
|
inherit (lib)
|
|
|
|
mapAttrs'
|
|
|
|
nameValuePair
|
|
|
|
mkMerge
|
|
|
|
mapAttrsToList
|
2024-10-06 18:38:36 +02:00
|
|
|
mkOption
|
2024-10-05 11:50:12 +02:00
|
|
|
;
|
2024-09-30 19:38:13 +02:00
|
|
|
inherit (pkgs.pseudofile) dir symlink;
|
2024-10-05 11:50:12 +02:00
|
|
|
inherit (utils.systemdUtils.lib)
|
|
|
|
targetToUnit
|
|
|
|
serviceToUnit
|
|
|
|
;
|
|
|
|
|
2024-10-06 23:27:48 +02:00
|
|
|
systemd-types = import ./types.nix { inherit pkgs utils lib; busybox = config.programs.busybox.package; };
|
2024-10-06 18:38:36 +02:00
|
|
|
|
2024-10-05 11:50:12 +02:00
|
|
|
units-texts = mapAttrs' (
|
|
|
|
_: unit:
|
|
|
|
nameValuePair unit.name {
|
|
|
|
file = unit.text;
|
|
|
|
mode = "0644";
|
|
|
|
}
|
2024-10-06 18:38:36 +02:00
|
|
|
) config.systemd.units;
|
2024-10-05 11:50:12 +02:00
|
|
|
units-aliases = mkMerge (
|
|
|
|
mapAttrsToList (
|
|
|
|
_: unit:
|
|
|
|
mkMerge (
|
|
|
|
map (aka: {
|
|
|
|
${aka} = symlink "${unit.name}";
|
|
|
|
}) (unit.aliases or [ ])
|
|
|
|
)
|
2024-10-06 18:38:36 +02:00
|
|
|
) config.systemd.units
|
2024-10-05 11:50:12 +02:00
|
|
|
);
|
|
|
|
units-extraWants = mkMerge (
|
|
|
|
mapAttrsToList (
|
|
|
|
_: unit:
|
|
|
|
mkMerge (
|
|
|
|
map (unit2: {
|
|
|
|
"${unit2}.wants" = dir {
|
|
|
|
${unit.name} = symlink "../${unit.name}";
|
|
|
|
};
|
|
|
|
}) (unit.wantedBy or [ ])
|
|
|
|
)
|
2024-10-06 18:38:36 +02:00
|
|
|
) config.systemd.units
|
2024-10-05 11:50:12 +02:00
|
|
|
);
|
|
|
|
units-extraUpholds = mkMerge (
|
|
|
|
mapAttrsToList (
|
|
|
|
_: unit:
|
|
|
|
mkMerge (
|
|
|
|
map (unit2: {
|
|
|
|
"${unit2}.upholds" = dir {
|
|
|
|
${unit.name} = symlink "../${unit.name}";
|
|
|
|
};
|
|
|
|
}) (unit.upheldBy or [ ])
|
|
|
|
)
|
2024-10-06 18:38:36 +02:00
|
|
|
) config.systemd.units
|
2024-10-05 11:50:12 +02:00
|
|
|
);
|
|
|
|
units-extraRequires = mkMerge (
|
|
|
|
mapAttrsToList (
|
|
|
|
_: unit:
|
|
|
|
mkMerge (
|
|
|
|
map (unit2: {
|
|
|
|
"${unit2}.requires" = dir {
|
|
|
|
${unit.name} = symlink "../${unit.name}";
|
|
|
|
};
|
|
|
|
}) (unit.requiredBy or [ ])
|
|
|
|
)
|
2024-10-06 18:38:36 +02:00
|
|
|
) config.systemd.units
|
2024-10-05 11:50:12 +02:00
|
|
|
);
|
2024-09-30 19:38:13 +02:00
|
|
|
in
|
|
|
|
{
|
2024-10-06 18:38:36 +02:00
|
|
|
options = {
|
|
|
|
systemd = {
|
|
|
|
units = mkOption {
|
|
|
|
type = systemd-types.units;
|
2024-10-05 11:50:12 +02:00
|
|
|
};
|
2024-10-06 18:38:36 +02:00
|
|
|
services = mkOption {
|
|
|
|
type = systemd-types.services;
|
2024-10-05 11:50:12 +02:00
|
|
|
};
|
2024-10-06 18:38:36 +02:00
|
|
|
targets = mkOption {
|
|
|
|
type = systemd-types.targets;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
|
|
|
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 = ''
|
|
|
|
# . /etc/profile
|
|
|
|
exec /bin/ash < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0
|
|
|
|
'';
|
2024-10-05 11:50:12 +02:00
|
|
|
};
|
2024-10-06 18:38:36 +02:00
|
|
|
};
|
|
|
|
targets = {
|
|
|
|
default = { };
|
|
|
|
sysinit = { };
|
2024-10-05 11:50:12 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-01 11:00:15 +02:00
|
|
|
kernel.config = {
|
|
|
|
CGROUPS = "y";
|
|
|
|
DEVTMPFS = "y";
|
|
|
|
INOTIFY_USER = "y";
|
|
|
|
SIGNALFD = "y";
|
|
|
|
TIMERFD = "y";
|
|
|
|
EPOLL = "y";
|
|
|
|
UNIX = "y";
|
|
|
|
SYSFS = "y";
|
|
|
|
PROC_FS = "y";
|
|
|
|
FHANDLE = "y";
|
|
|
|
};
|
2024-09-30 19:38:13 +02:00
|
|
|
boot.commandLine = [
|
|
|
|
"systemd.log_level=7"
|
|
|
|
#"systemd.crash_shell=true"
|
|
|
|
];
|
|
|
|
filesystem = dir {
|
|
|
|
etc = dir {
|
|
|
|
systemd = dir {
|
2024-10-05 11:50:12 +02:00
|
|
|
system = dir (mkMerge [
|
|
|
|
units-texts
|
|
|
|
units-aliases
|
|
|
|
units-extraWants
|
|
|
|
units-extraUpholds
|
|
|
|
units-extraRequires
|
|
|
|
]);
|
2024-09-30 19:38:13 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
bin = dir {
|
|
|
|
init = symlink "${pkgs.systemd}/bin/init";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|