Merge pull request #50561 from oxij/lib/setPrio

lib: implement `setPrio`
This commit is contained in:
Michael Raskin 2019-01-18 08:23:31 +00:00 committed by GitHub
commit 4d0e1b792f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -94,7 +94,7 @@ let
callPackageWith callPackagesWith extendDerivation hydraJob callPackageWith callPackagesWith extendDerivation hydraJob
makeScope; makeScope;
inherit (meta) addMetaAttrs dontDistribute setName updateName inherit (meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset lowPrio lowPrioSet hiPrio appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
hiPrioSet; hiPrioSet;
inherit (sources) pathType pathIsDirectory cleanSourceFilter inherit (sources) pathType pathIsDirectory cleanSourceFilter
cleanSource sourceByRegex sourceFilesBySuffices cleanSource sourceByRegex sourceFilesBySuffices

View File

@ -41,16 +41,18 @@ rec {
let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}"); let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}");
/* Apply a function to each derivation and only to derivations in an attrset /* Apply a function to each derivation and only to derivations in an attrset.
*/ */
mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set; mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set;
/* Set the nix-env priority of the package.
*/
setPrio = priority: addMetaAttrs { inherit priority; };
/* Decrease the nix-env priority of the package, i.e., other /* Decrease the nix-env priority of the package, i.e., other
versions/variants of the package will be preferred. versions/variants of the package will be preferred.
*/ */
lowPrio = drv: addMetaAttrs { priority = 10; } drv; lowPrio = setPrio 10;
/* Apply lowPrio to an attrset with derivations /* Apply lowPrio to an attrset with derivations
*/ */
@ -60,8 +62,7 @@ rec {
/* Increase the nix-env priority of the package, i.e., this /* Increase the nix-env priority of the package, i.e., this
version/variant of the package will be preferred. version/variant of the package will be preferred.
*/ */
hiPrio = drv: addMetaAttrs { priority = -10; } drv; hiPrio = setPrio (-10);
/* Apply hiPrio to an attrset with derivations /* Apply hiPrio to an attrset with derivations
*/ */