diff --git a/modules/base.nix b/modules/base.nix index 257200e..1755f83 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -49,9 +49,6 @@ in { type = types.attrsOf type_service; }; - units = mkOption { - type = utils.systemdUtils.types.units; - }; system.callService = mkOption { type = types.functionTo (types.functionTo types.anything); }; diff --git a/modules/systemd/default.nix b/modules/systemd/default.nix index 17cf0cc..8a9a15c 100644 --- a/modules/systemd/default.nix +++ b/modules/systemd/default.nix @@ -11,6 +11,7 @@ let nameValuePair mkMerge mapAttrsToList + mkOption ; inherit (pkgs.pseudofile) dir symlink; inherit (utils.systemdUtils.lib) @@ -18,13 +19,15 @@ let serviceToUnit ; + systemd-types = import ./types.nix { inherit pkgs utils lib; }; + units-texts = mapAttrs' ( _: unit: nameValuePair unit.name { file = unit.text; mode = "0644"; } - ) config.units; + ) config.systemd.units; units-aliases = mkMerge ( mapAttrsToList ( _: unit: @@ -33,7 +36,7 @@ let ${aka} = symlink "${unit.name}"; }) (unit.aliases or [ ]) ) - ) config.units + ) config.systemd.units ); units-extraWants = mkMerge ( mapAttrsToList ( @@ -45,7 +48,7 @@ let }; }) (unit.wantedBy or [ ]) ) - ) config.units + ) config.systemd.units ); units-extraUpholds = mkMerge ( mapAttrsToList ( @@ -57,7 +60,7 @@ let }; }) (unit.upheldBy or [ ]) ) - ) config.units + ) config.systemd.units ); units-extraRequires = mkMerge ( mapAttrsToList ( @@ -69,49 +72,46 @@ let }; }) (unit.requiredBy or [ ]) ) - ) config.units + ) 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 = { - 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" ]; + 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 = '' + #!/bin/ash + # . /etc/profile + exec /bin/ash < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0 + ''; }; - serviceConfig.ExecStart = - let - login = pkgs.writeScript "login" '' - #!/bin/ash - . /etc/profile - exec /bin/ash - ''; - in - "${pkgs.util-linux}/bin/agetty --login-program ${login} ttyS0"; + }; + targets = { + default = { }; + sysinit = { }; }; }; diff --git a/modules/systemd/types.nix b/modules/systemd/types.nix new file mode 100644 index 0000000..239f551 --- /dev/null +++ b/modules/systemd/types.nix @@ -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 + ]); +}