This commit is contained in:
catvayor 2024-10-05 11:50:12 +02:00
parent 14b59b5b62
commit 7705bc2a8e
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
3 changed files with 133 additions and 38 deletions

View file

@ -25,7 +25,13 @@ let
eval = evalModules { eval = evalModules {
modules = [ modules = [
{ ({ lib, pkgs, ... }: {
_module.args = {
utils = import "${nixpkgs}/nixos/lib/utils.nix" {
inherit lib pkgs;
config.systemd.globalEnvironment = {};
};
};
nixpkgs = { nixpkgs = {
source = nixpkgs; source = nixpkgs;
overlays = [ overlay ]; overlays = [ overlay ];
@ -33,7 +39,7 @@ let
"python-2.7.18.8" "python-2.7.18.8"
]; ];
}; };
} })
device.module device.module
liminix-config liminix-config
]; ];

View file

@ -2,7 +2,7 @@
## ============ ## ============
{ lib, pkgs, config, ...}: { lib, pkgs, utils, config, ...}:
let let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList; inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
@ -43,9 +43,15 @@ in {
''; '';
}; };
}; };
# deprecated
services = mkOption { services = mkOption {
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

@ -1,41 +1,120 @@
{ pkgs, ... }: {
pkgs,
lib,
config,
utils,
...
}:
let let
inherit (lib)
mapAttrs'
nameValuePair
mkMerge
mapAttrsToList
;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
"getty.service" = { inherit (utils.systemdUtils.lib)
file = targetToUnit
let serviceToUnit
login = pkgs.writeScript "login" '' ;
#!/bin/ash
exec /bin/ash
'';
in
''
[Unit]
Description="Serial shell"
[Service] units-texts = mapAttrs' (
ExecStart=${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0 _: unit:
''; nameValuePair unit.name {
file = unit.text;
mode = "0644"; mode = "0644";
}
) config.units;
units-aliases = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (aka: {
${aka} = symlink "${unit.name}";
}) (unit.aliases or [ ])
)
) config.units
);
units-extraWants = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.wants" = dir {
${unit.name} = symlink "../${unit.name}";
}; };
"default.target" = { }) (unit.wantedBy or [ ])
file = '' )
[Unit] ) config.units
Description="target to boot" );
Wants=getty.service units-extraUpholds = mkMerge (
After=getty.service mapAttrsToList (
AllowIsolate=yes _: unit:
''; mkMerge (
map (unit2: {
"${unit2}.upholds" = dir {
${unit.name} = symlink "../${unit.name}";
}; };
"sysinit.target" = { }) (unit.upheldBy or [ ])
file = '' )
[Unit] ) config.units
Description="sysinit.target" );
''; units-extraRequires = mkMerge (
mapAttrsToList (
_: unit:
mkMerge (
map (unit2: {
"${unit2}.requires" = dir {
${unit.name} = symlink "../${unit.name}";
}; };
}) (unit.requiredBy or [ ])
)
) config.units
);
in in
{ {
config = { 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" ];
};
serviceConfig.ExecStart =
let
login = pkgs.writeScript "login" ''
#!/bin/ash
. /etc/profile
exec /bin/ash
'';
in
"${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0";
};
};
kernel.config = { kernel.config = {
CGROUPS = "y"; CGROUPS = "y";
DEVTMPFS = "y"; DEVTMPFS = "y";
@ -55,9 +134,13 @@ in
filesystem = dir { filesystem = dir {
etc = dir { etc = dir {
systemd = dir { systemd = dir {
system = dir { system = dir (mkMerge [
inherit "default.target" "getty.service" "sysinit.target"; units-texts
}; units-aliases
units-extraWants
units-extraUpholds
units-extraRequires
]);
}; };
}; };
bin = dir { bin = dir {