summary refs log tree commit diff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-09-04 12:36:11 +0200
committerJan Tojnar <jtojnar@gmail.com>2022-09-07 14:23:28 +0200
commit9137e671a2e2f5b46748ae21b21737b3f4194883 (patch)
treec2904a4ef8efeb25093fe6398801c064d09cd82e
parent7d6b5d171adaf0a7d6808493629556d270c35c47 (diff)
downloadnixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar.gz
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar.bz2
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar.lz
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar.xz
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.tar.zst
nixpkgs-9137e671a2e2f5b46748ae21b21737b3f4194883.zip
update-script-combinators.copyAttrOutputToFile: init
Useful for storing generated files into Nixpkgs repo as a part of an update script to avoid a build time dependency.
-rw-r--r--pkgs/common-updater/combinators.nix38
1 files changed, 34 insertions, 4 deletions
diff --git a/pkgs/common-updater/combinators.nix b/pkgs/common-updater/combinators.nix
index 93fdac52f7c..d60a6e74271 100644
--- a/pkgs/common-updater/combinators.nix
+++ b/pkgs/common-updater/combinators.nix
@@ -19,7 +19,8 @@
       command : (FilePath | [ (FilePath | String) ])
       // Features that the script supports
       // - commit: (experimental) returns commit message in stdout
-      supportedFeatures : ?[ "commit" ]
+      // - silent: (experimental) returns no stdout
+      supportedFeatures : ?[ ("commit" | "silent") ]
       // Override attribute path detected by update.nix
       attrPath : ?String
     }
@@ -118,11 +119,40 @@ rec {
     in
     let
       scripts = scriptsNormalized;
-      validateFeatures = ({ supportedFeatures, ... }: supportedFeatures == [ ]);
+      hasCommitSupport = lib.findSingle ({ supportedFeatures, ... }: supportedFeatures == [ "commit" ]) null null scripts != null;
+      validateFeatures =
+        if hasCommitSupport then
+          ({ supportedFeatures, ... }: supportedFeatures == [ "commit" ] || supportedFeatures == [ "silent" ])
+        else
+          ({ supportedFeatures, ... }: supportedFeatures == [ ]);
     in
 
-    assert lib.assertMsg (lib.all validateFeatures scripts) "Combining update scripts with features enabled is currently unsupported.";
+    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 (builtins.length (lib.unique (builtins.map ({ attrPath ? null, ... }: attrPath) scripts)) == 1) "Combining update scripts with different attr paths is currently unsupported.";
 
-    commandsToShellInvocation (builtins.map ({ command, ... }: command) scripts);
+    {
+      command = commandsToShellInvocation (builtins.map ({ command, ... }: command) scripts);
+      supportedFeatures = lib.optionals hasCommitSupport [
+        "commit"
+      ];
+    };
+
+  /*
+    copyAttrOutputToFile : String → FilePath → UpdateScript
+    EXPERIMENTAL! Simple update script that copies the output of Nix derivation built by `attr` to `path`.
+  */
+  copyAttrOutputToFile =
+    attr:
+    path:
+
+    {
+      command = [
+        "sh"
+        "-c"
+        "cp --no-preserve=all \"$(nix-build -A ${attr})\" \"$0\" > /dev/null"
+        path
+      ];
+      supportedFeatures = [ "silent" ];
+    };
+
 }