diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index 276197d24d8f..127ab7be3b94 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -76,6 +76,7 @@ rec { }; + serviceOptions = unitOptions // { environment = mkOption { @@ -146,4 +147,21 @@ rec { }; + + socketOptions = unitOptions // { + + socketConfig = mkOption { + default = {}; + example = { ListenStream = "/run/my-socket"; }; + type = types.attrs; + description = '' + Each attribute in this set specifies an option in the + [Socket] section of the unit. See + systemd.socket + 5 for details. + ''; + }; + + }; + } \ No newline at end of file diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index 991e09058e83..6603d6126b43 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -167,6 +167,20 @@ let makeJobScript = name: content: "${pkgs.writeScriptBin name content}/bin/${name}"; + unitConfig = { name, config, ... }: { + config = { + unitConfig = + { Requires = concatStringsSep " " config.requires; + Wants = concatStringsSep " " config.wants; + After = concatStringsSep " " config.after; + Before = concatStringsSep " " config.before; + PartOf = concatStringsSep " " config.partOf; + } // optionalAttrs (config.description != "") { + Description = config.description; + }; + }; + }; + serviceConfig = { name, config, ... }: { config = { # Default path for systemd services. Should be quite minimal. @@ -177,15 +191,6 @@ let pkgs.gnused systemd ]; - unitConfig = - { Requires = concatStringsSep " " config.requires; - Wants = concatStringsSep " " config.wants; - After = concatStringsSep " " config.after; - Before = concatStringsSep " " config.before; - PartOf = concatStringsSep " " config.partOf; - } // optionalAttrs (config.description != "") - { Description = config.description; - }; }; }; @@ -342,33 +347,21 @@ in boot.systemd.targets = mkOption { default = {}; type = types.attrsOf types.optionSet; - options = unitOptions; + options = [ unitOptions unitConfig ]; description = "Definition of systemd target units."; }; boot.systemd.services = mkOption { default = {}; type = types.attrsOf types.optionSet; - options = [ serviceOptions serviceConfig ]; + options = [ serviceOptions unitConfig serviceConfig ]; description = "Definition of systemd service units."; }; boot.systemd.sockets = mkOption { default = {}; type = types.attrsOf types.optionSet; - options = unitOptions // { - socketConfig = mkOption { - default = {}; - example = { ListenStream = "/run/my-socket"; }; - type = types.attrs; - description = '' - Each attribute in this set specifies an option in the - [Socket] section of the unit. See - systemd.socket - 5 for details. - ''; - }; - }; + options = [ socketOptions unitConfig ]; description = "Definition of systemd socket units."; };