override-utils: Allow wrapping with environment variables
This commit is contained in:
parent
4c48c44233
commit
b591f3ddb1
1 changed files with 26 additions and 5 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
let
|
||||
inherit (builtins) attrNames elemAt filter functionArgs isAttrs isPath length mapAttrs match pathExists removeAttrs toJSON tryEval;
|
||||
inherit (stable) callPackage fetchFromGitHub;
|
||||
inherit (stable.lib) attrByPath concatMapStringsSep const findFirst getAttrFromPath hasAttrByPath imap1 info optionalAttrs optionalString recurseIntoAttrs showAttrPath throwIf toList versionAtLeast;
|
||||
inherit (stable) callPackage fetchFromGitHub makeWrapper symlinkJoin;
|
||||
inherit (stable.lib) attrByPath concatMapStringsSep concatStringsSep const escapeShellArg findFirst getAttrFromPath hasAttrByPath imap1 info mapAttrsToList optionalAttrs optionalString recurseIntoAttrs showAttrPath throwIf toList versionAtLeast;
|
||||
|
||||
# Utilities
|
||||
composeOverrides = f1: f2: a0: let o1 = f1 a0; o2 = f2 (a0 // o1); in o1 // o2;
|
||||
|
@ -45,6 +45,9 @@ let
|
|||
, overlay ? null
|
||||
, patch ? null
|
||||
|
||||
# Wrapper
|
||||
, env ? null
|
||||
|
||||
# Package input override
|
||||
, ...
|
||||
}:
|
||||
|
@ -55,6 +58,7 @@ let
|
|||
# Specification
|
||||
doOverlay = gappsWrapperArgs != null || overlay != null || patch != null;
|
||||
doOverride = ! isEmpty override;
|
||||
doWrapper = env != null;
|
||||
|
||||
# Package selection
|
||||
path = scope ++ [ pname ];
|
||||
|
@ -85,14 +89,31 @@ let
|
|||
if doOverride then package_with_overlay.override override
|
||||
else package_with_overlay;
|
||||
|
||||
# Wrapper
|
||||
package_with_overlay_with_override_with_wrapper =
|
||||
if doWrapper then
|
||||
symlinkJoin
|
||||
{
|
||||
name = "${pname}-wrapper";
|
||||
paths = [ package_with_overlay_with_override ];
|
||||
buildInputs = [ makeWrapper ];
|
||||
postBuild = ''
|
||||
for program in $out/bin/*; do
|
||||
wrapProgram "$program" \
|
||||
${concatStringsSep " " (mapAttrsToList (k: v: "--set ${escapeShellArg k} ${escapeShellArg v}") env)}
|
||||
done
|
||||
'';
|
||||
}
|
||||
else package_with_overlay_with_override;
|
||||
|
||||
# Report
|
||||
summary = "Resolved ${name}" +
|
||||
(optionalString (version != null) " ${version}") +
|
||||
(optionalString (release != null) " of NixOS ${release}") +
|
||||
(optionalString (doOverlay || doOverride) " with override") +
|
||||
(optionalString (doOverlay || doOverride || doWrapper) " with override") +
|
||||
(optionalString (condition != null) " meeting condition") +
|
||||
(optionalString (! isStable repo) " via ${repoName repo}");
|
||||
unnecessary = isStable repo && !doOverlay && !doOverride;
|
||||
unnecessary = isStable repo && !doOverlay && !doOverride && !doWrapper;
|
||||
unnecessarySearches = concatMapStringsSep ", " repoName (filter (r: r._extra > repo._extra or 0) extra);
|
||||
in
|
||||
if hasAttrByPath (path ++ [ "overrideScope'" ]) stable then
|
||||
|
@ -102,7 +123,7 @@ let
|
|||
else
|
||||
throwIf (unnecessarySearches != "") "${name} no longer requires searching ${unnecessarySearches}"
|
||||
(throwIf unnecessary "${name} no longer requires an override")
|
||||
(info summary package_with_overlay_with_override)
|
||||
(info summary package_with_overlay_with_override_with_wrapper)
|
||||
;
|
||||
in
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue