From 8de00c328a3adc4619c85b3b2dbac3474c9e5f88 Mon Sep 17 00:00:00 2001 From: Mathijs Kwik Date: Fri, 19 Apr 2013 22:28:00 +0200 Subject: [PATCH] systemd: add "requiredBy" option. "require" is a stronger version of "want", and just like wantedBy allows you to specify this relation in reverse, requiredBy does the same. It may seem pointless to be able to specify these stronger relations in reverse, because if something is really required, you would expect the other unit to specify this himself. However, this is still useful for virtual/automatic units (like devices) that are created by systemd on demand and hence have no unit file you can alter. --- modules/system/boot/systemd-unit-options.nix | 6 ++++++ modules/system/boot/systemd.nix | 21 +++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) 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;