liminix/modules/systemd/default.nix
catvayor 7219e66992
Some checks failed
build liminix / build_vm_qemu_mips (pull_request) Successful in 3m7s
build liminix / build_zyxel-nwa50ax_mips (pull_request) Successful in 3m8s
build liminix / test_hostapd (pull_request) Failing after 4m7s
build liminix / test_shell_customization (pull_request) Failing after 4m8s
reduce closure
2024-10-07 18:03:49 +02:00

150 lines
3.2 KiB
Nix

{
pkgs,
lib,
config,
utils,
...
}:
let
inherit (lib)
mapAttrs'
nameValuePair
mkMerge
mapAttrsToList
mkOption
;
inherit (pkgs.pseudofile) dir symlink;
inherit (utils.systemdUtils.lib)
targetToUnit
serviceToUnit
;
systemd-types = import ./types.nix { inherit pkgs utils lib; busybox = config.programs.busybox.package; };
units-texts = mapAttrs' (
_: unit:
nameValuePair unit.name {
file = unit.text;
mode = "0644";
}
) config.systemd.units;
units-aliases = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (aka: {
${aka} = symlink "${unit.name}";
}) (unit.aliases or [ ])
)
) config.systemd.units
);
units-extraWants = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.wants" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.wantedBy or [ ])
)
) config.systemd.units
);
units-extraUpholds = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.upholds" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.upheldBy or [ ])
)
) config.systemd.units
);
units-extraRequires = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.requires" = dir {
${unit.name} = symlink "../${unit.name}";
};
}) (unit.requiredBy or [ ])
)
) 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 = {
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
'';
};
};
targets = {
default = { };
sysinit = { };
};
};
kernel.config = {
CGROUPS = "y";
DEVTMPFS = "y";
INOTIFY_USER = "y";
SIGNALFD = "y";
TIMERFD = "y";
EPOLL = "y";
UNIX = "y";
SYSFS = "y";
PROC_FS = "y";
FHANDLE = "y";
};
boot.commandLine = [
"systemd.log_level=7"
#"systemd.crash_shell=true"
];
filesystem = dir {
etc = dir {
systemd = dir {
system = dir (mkMerge [
units-texts
units-aliases
units-extraWants
units-extraUpholds
units-extraRequires
]);
};
};
bin = dir {
init = symlink "${pkgs.systemd}/bin/init";
};
};
};
}