diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index 8f61399465b..9069d03b9f0 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -76,6 +76,12 @@ rec { ''; }; + requiredBy = mkOption { + default = []; + types = types.listOf types.string; + description = "Units that require (i.e. depend on and need to go down with) this unit."; + }; + wantedBy = mkOption { default = []; types = types.listOf types.string; diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index f99eca91ad5..44bf89b907a 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -211,7 +211,7 @@ let as)); targetToUnit = name: def: - { inherit (def) wantedBy enable; + { inherit (def) wantedBy requiredBy enable; text = '' [Unit] @@ -220,7 +220,7 @@ let }; serviceToUnit = name: def: - { inherit (def) wantedBy enable; + { inherit (def) wantedBy requiredBy enable; text = '' [Unit] @@ -267,7 +267,7 @@ let }; socketToUnit = name: def: - { inherit (def) wantedBy enable; + { inherit (def) wantedBy requiredBy enable; text = '' [Unit] @@ -279,7 +279,7 @@ let }; timerToUnit = name: def: - { inherit (def) wantedBy enable; + { inherit (def) wantedBy requiredBy enable; text = '' [Unit] @@ -291,7 +291,7 @@ let }; mountToUnit = name: def: - { inherit (def) wantedBy enable; + { inherit (def) wantedBy requiredBy enable; text = '' [Unit] @@ -343,6 +343,12 @@ let ln -sfn ../${name} $out/${name2}.wants/ '') unit.wantedBy) cfg.units)} + ${concatStrings (mapAttrsToList (name: unit: + concatMapStrings (name2: '' + mkdir -p $out/${name2}.requires + ln -sfn ../${name} $out/${name2}.requires/ + '') unit.requiredBy) cfg.units)} + ln -s ${cfg.defaultUnit} $out/default.target ln -s rescue.target $out/kbrequest.target @@ -387,6 +393,11 @@ in from being started. ''; }; + requiredBy = mkOption { + default = []; + types = types.listOf types.string; + description = "Units that require (i.e. depend on and need to go down with) this unit."; + }; wantedBy = mkOption { default = []; types = types.listOf types.string;