From e16bd36ed6821f00c1f443efd76d99414b14afdf Mon Sep 17 00:00:00 2001 From: r-vdp Date: Mon, 24 Nov 2025 12:33:48 -0300 Subject: [PATCH] nixos/activation: avoid generating empty activation scripts --- lib/strings-with-deps.nix | 4 ++-- .../modules/system/activation/activation-script.nix | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/strings-with-deps.nix b/lib/strings-with-deps.nix index 6322cad11995..8fd879df1790 100644 --- a/lib/strings-with-deps.nix +++ b/lib/strings-with-deps.nix @@ -43,7 +43,7 @@ let inherit (lib) - concatStringsSep + concatMapStringsSep head isAttrs listToAttrs @@ -166,7 +166,7 @@ rec { textClosureMap = f: predefined: names: - concatStringsSep "\n" (map f (textClosureList predefined names)); + concatMapStringsSep "\n" f (textClosureList predefined names); noDepEntry = text: { inherit text; diff --git a/nixos/modules/system/activation/activation-script.nix b/nixos/modules/system/activation/activation-script.nix index bd83dd72b436..08ab396e1de2 100644 --- a/nixos/modules/system/activation/activation-script.nix +++ b/nixos/modules/system/activation/activation-script.nix @@ -13,17 +13,16 @@ let addAttributeName = mapAttrs ( a: v: v - // { + // (lib.optionalAttrs (v.text != "") { text = '' #### Activation script snippet ${a}: _localstatus=0 ${v.text} - if (( _localstatus > 0 )); then printf "Activation script snippet '%s' failed (%s)\n" "${a}" "$_localstatus" fi ''; - } + }) ); systemActivationScript = @@ -68,8 +67,11 @@ let # Ensure a consistent umask. umask 0022 - ${textClosureMap id withDrySnippets (attrNames withDrySnippets)} - + ${lib.concatStringsSep "\n" ( + lib.filter (v: v != "") ( + textClosureList withDrySnippets (attrNames (lib.filterAttrs (_: v: v.text != "") withDrySnippets)) + ) + )} '' + optionalString (!onlyDry) '' # Make this configuration the current configuration.