about summary refs log tree commit diff
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2021-02-13 05:24:04 +0100
committeraszlig <aszlig@nix.build>2021-02-13 05:24:11 +0100
commit2d5a31a3ef2ce5b9b2aca610377e655924999000 (patch)
treebfad81989b0a17c31faa8a87b58302be3974d275
parent29dcf53a5501e4144d00f001ad329dda287cbf9d (diff)
parent97718a3584377f9bce2f2b653c1b927c5d0f9286 (diff)
downloadnixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar.gz
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar.bz2
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar.lz
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar.xz
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.tar.zst
nixlib-2d5a31a3ef2ce5b9b2aca610377e655924999000.zip
Merge pull request #112819 (mkIf in systemd units)
@thelegy writes:

  unitOption is only used inside of attrsOf wich is perfectly capable of
  handling the attrsets from mkIf, though the checkUnitConfig test
  forbids it.

  This commit weakens that restriction to allow the usage of mkIf inside
  of systemd.services.<name>.serviceConfig.<something> etc.

While I personally don't like that we can't easily use
pushDownProperties from the module system and need to rely on internals,
we *already* use internals for the mkOverride case, so adding another
case for mkIf doesn't add a hard-to-find indirection.

I'm merging this, since this fixes a valid use case and it shouldn't
make refactoring worse than before.
-rw-r--r--nixos/modules/system/boot/systemd-lib.nix6
1 files changed, 4 insertions, 2 deletions
diff --git a/nixos/modules/system/boot/systemd-lib.nix b/nixos/modules/system/boot/systemd-lib.nix
index fa109394fedb..2dbf15031a08 100644
--- a/nixos/modules/system/boot/systemd-lib.nix
+++ b/nixos/modules/system/boot/systemd-lib.nix
@@ -92,10 +92,12 @@ in rec {
 
   checkUnitConfig = group: checks: attrs: let
     # We're applied at the top-level type (attrsOf unitOption), so the actual
-    # unit options might contain attributes from mkOverride that we need to
+    # unit options might contain attributes from mkOverride and mkIf that we need to
     # convert into single values before checking them.
     defs = mapAttrs (const (v:
-      if v._type or "" == "override" then v.content else v
+      if v._type or "" == "override" then v.content
+      else if v._type or "" == "if" then v.content
+      else v
     )) attrs;
     errors = concatMap (c: c group defs) checks;
   in if errors == [] then true