From 49606d943aa634938c6b74f35125e6b7a2ba2bc7 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 18 Oct 2024 12:10:05 +0100 Subject: [PATCH] _experimental-update-script-combinators.sequence: handle silent scripts Co-authored-by: Jan Tojnar --- pkgs/common-updater/combinators.nix | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkgs/common-updater/combinators.nix b/pkgs/common-updater/combinators.nix index dadbb1e81ca4..a774328380bb 100644 --- a/pkgs/common-updater/combinators.nix +++ b/pkgs/common-updater/combinators.nix @@ -120,21 +120,33 @@ rec { let scripts = scriptsNormalized; hasCommitSupport = lib.findSingle ({ supportedFeatures, ... }: supportedFeatures == [ "commit" ]) null null scripts != null; + hasSilentSupport = lib.findFirst ({ supportedFeatures, ... }: supportedFeatures == [ "silent" ]) null scripts != null; + # Supported features currently only describe the format of the standard output of the update script. + # Here we ensure that the standard output of the combined update script is well formed. validateFeatures = if hasCommitSupport then + # Exactly one update script declares only “commit” feature and all the rest declare only “silent” feature. ({ supportedFeatures, ... }: supportedFeatures == [ "commit" ] || supportedFeatures == [ "silent" ]) + else if hasSilentSupport then + # All update scripts declare only “silent” feature. + ({ supportedFeatures, ... }: supportedFeatures == [ "silent" ]) else + # No update script declares any supported feature to fail loudly on unknown features rather than silently discard them. ({ supportedFeatures, ... }: supportedFeatures == [ ]); in - assert lib.assertMsg (lib.all validateFeatures scripts) "Combining update scripts with features enabled (other than a single script with “commit” and all other with “silent”) is currently unsupported."; + assert lib.assertMsg (lib.all validateFeatures scripts) "Combining update scripts with features enabled (other than “silent” scripts and an optional single script with “commit”) is currently unsupported."; assert lib.assertMsg (builtins.length (lib.unique (builtins.map ({ attrPath ? null, ... }: attrPath) scripts)) == 1) "Combining update scripts with different attr paths is currently unsupported."; { command = commandsToShellInvocation (builtins.map ({ command, ... }: command) scripts); - supportedFeatures = lib.optionals hasCommitSupport [ - "commit" - ]; + supportedFeatures = + if hasCommitSupport then + [ "commit" ] + else if hasSilentSupport then + [ "silent" ] + else + [ ]; }; /*