mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
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.
This commit is contained in:
parent
7d6b5d171a
commit
9137e671a2
@ -19,7 +19,8 @@
|
|||||||
command : (FilePath | [ (FilePath | String) ])
|
command : (FilePath | [ (FilePath | String) ])
|
||||||
// Features that the script supports
|
// Features that the script supports
|
||||||
// - commit: (experimental) returns commit message in stdout
|
// - commit: (experimental) returns commit message in stdout
|
||||||
supportedFeatures : ?[ "commit" ]
|
// - silent: (experimental) returns no stdout
|
||||||
|
supportedFeatures : ?[ ("commit" | "silent") ]
|
||||||
// Override attribute path detected by update.nix
|
// Override attribute path detected by update.nix
|
||||||
attrPath : ?String
|
attrPath : ?String
|
||||||
}
|
}
|
||||||
@ -118,11 +119,40 @@ rec {
|
|||||||
in
|
in
|
||||||
let
|
let
|
||||||
scripts = scriptsNormalized;
|
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
|
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.";
|
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" ];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user