refactor(readTree): Move 'drvTargets' into readTree

This function is also generally useful for readTree consumers that
have the concept of subtargets.

Change-Id: Ic7fc03380dec6953fb288763a28e50ab3624d233
This commit is contained in:
Vincent Ambo 2021-11-23 16:31:17 +03:00 committed by tazjin
parent 5cad3f7b81
commit 4f1249e46f
19 changed files with 34 additions and 40 deletions

View file

@ -14,7 +14,7 @@ let
};
package = python3Packages.buildPythonPackage opts;
script = python3Packages.buildPythonApplication opts;
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit script;
python = python3.withPackages (_: [ package ]);
setAlarm = pkgs.writeShellScriptBin "set-alarm" ''

View file

@ -157,6 +157,10 @@ let
})
(node.meta.targets or []))
else [];
# Determine whether a given value is a derivation.
# Copied from nixpkgs/lib for cases where lib is not available yet.
isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
in {
inherit gather;
@ -210,4 +214,17 @@ in {
#
# It is often required to create the args attribute set.
fix = f: let x = f x; in x;
# Takes an attribute set and adds a meta.targets attribute to it
# which contains all direct children of the attribute set which are
# derivations.
#
# Type: attrs -> attrs
drvTargets = attrs: attrs // {
meta = {
targets = builtins.filter
(x: isDerivation attrs."${x}")
(builtins.attrNames attrs);
} // (attrs.meta or {});
};
}

View file

@ -1,22 +1,6 @@
{ depot, lib, ... }:
let
/* Takes an attribute set and adds a meta.targets
attribute to it which contains all direct children
of the attribute set which are derivations.
Type: attrs -> attrs
*/
drvTargets = attrs:
attrs // {
meta = {
targets = builtins.filter
(x: lib.isDerivation attrs."${x}")
(builtins.attrNames attrs);
} // (attrs.meta or {});
};
/* Get the basename of a store path without
the leading hash.
@ -186,7 +170,6 @@ let
in {
inherit
drvTargets
storePathName
pathType
isDirectory

View file

@ -60,7 +60,7 @@ let
'');
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
rustTransitiveLib
rustWithLib

View file

@ -2,15 +2,11 @@
{ depot, pkgs, ... }:
let
inherit (depot.nix.utils)
drvTargets
;
checkZone = zone: file: pkgs.runCommandNoCC "${zone}-check" {} ''
${pkgs.bind}/bin/named-checkzone -i local ${zone} ${file} | tee $out
'';
in drvTargets {
in depot.nix.readTree.drvTargets {
nixery-dev = checkZone "nixery.dev" ./nixery.dev.zone;
tvl-fyi = checkZone "tvl.fyi" ./tvl.fyi.zone;
tvl-su = checkZone "tvl.su" ./tvl.su.zone;

View file

@ -2,7 +2,7 @@
let
inherit (import ./builder.nix args) buildGerritBazelPlugin;
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
# https://gerrit.googlesource.com/plugins/owners
owners = buildGerritBazelPlugin rec {
name = "owners";

View file

@ -3,7 +3,7 @@
{ depot, pkgs, ... }:
let
inherit (depot.nix.utils) drvTargets;
inherit (depot.nix.readTree) drvTargets;
commit = "6c4a69fa4280f0154ce257a1dfd23fb463c1ec5b";
src = pkgs.fetchFromGitHub {

View file

@ -77,7 +77,7 @@ let
bins.s6-touch "$out"
];
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
check-all-our-crates =
depot.nix.drvSeqL

View file

@ -37,4 +37,4 @@ let
'';
};
in depot.nix.utils.drvTargets netencode
in depot.nix.readTree.drvTargets netencode

View file

@ -358,7 +358,7 @@ let
bins.cdbget "$2"
];
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
router
depotCgitLink

View file

@ -5,7 +5,7 @@ let
name = "exec-helpers";
} (builtins.readFile ./exec_helpers.rs);
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
exec-helpers
;

View file

@ -135,7 +135,7 @@ let
}
'';
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
netencode-rs
pretty-rs

View file

@ -55,7 +55,7 @@ let
}
'';
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
python-netstring
rust-netstring

View file

@ -53,7 +53,7 @@ let
}
'';
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
python-netstring-test
rust-netstring-test

View file

@ -101,7 +101,7 @@ let
"nix-instantiate" "$1" "-A" "{}"
];
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
instantiate-nixpkgs-randomly
# requires hnix, which we dont want in tvl for now

View file

@ -169,7 +169,7 @@ let
'';
};
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
print-ast
tree-sitter-nix

View file

@ -41,7 +41,7 @@ let
assert(test_lib.test() == "test 1 2 3")
'');
in depot.nix.utils.drvTargets {
in depot.nix.readTree.drvTargets {
inherit
pythonWithLib
;

View file

@ -2,13 +2,11 @@
{ depot, pkgs, ... }:
let
inherit (depot.nix.utils) drvTargets;
checkZone = zone: file: pkgs.runCommandNoCC "${zone}-check" {} ''
${pkgs.bind}/bin/named-checkzone -i local ${zone} ${file} | tee $out
'';
in drvTargets {
in depot.nix.readTree.drvTargets {
kontemplate-works = checkZone "kontemplate.works"./kontemplate.works.zone;
tazj-in = checkZone "tazj.in" ./tazj.in.zone;
}

View file

@ -67,7 +67,7 @@ let
</svg>
'';
in depot.nix.utils.drvTargets(lib.fix (self: {
in depot.nix.readTree.drvTargets(lib.fix (self: {
# Expose the logo construction functions.
inherit palette darkCss lightCss animatedCss staticCss;