From 4f1249e46fb816cfd299ae27385a63746f914c3f Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 23 Nov 2021 16:31:17 +0300 Subject: refactor(readTree): Move 'drvTargets' into readTree This function is also generally useful for readTree consumers that have the concept of subtargets. Change-Id: Ic7fc03380dec6953fb288763a28e50ab3624d233 --- fun/idual/default.nix | 2 +- nix/readTree/default.nix | 17 +++++++++++++++++ nix/utils/default.nix | 17 ----------------- nix/writers/tests/rust.nix | 2 +- ops/dns/default.nix | 6 +----- third_party/gerrit_plugins/default.nix | 2 +- third_party/nixery/default.nix | 2 +- tools/rust-crates-advisory/default.nix | 2 +- users/Profpatsch/arglib/netencode.nix | 2 +- users/Profpatsch/blog/default.nix | 2 +- users/Profpatsch/execline/default.nix | 2 +- users/Profpatsch/netencode/default.nix | 2 +- users/Profpatsch/netstring/default.nix | 2 +- users/Profpatsch/netstring/tests/default.nix | 2 +- users/Profpatsch/nixpkgs-rewriter/default.nix | 2 +- users/Profpatsch/tree-sitter.nix | 2 +- users/Profpatsch/writers/tests/default.nix | 2 +- users/tazjin/dns/default.nix | 4 +--- web/tvl/logo/default.nix | 2 +- 19 files changed, 34 insertions(+), 40 deletions(-) diff --git a/fun/idual/default.nix b/fun/idual/default.nix index 877ab7d392..0f87f4ae1a 100644 --- a/fun/idual/default.nix +++ b/fun/idual/default.nix @@ -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" '' diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix index 5e805b5f4a..2ad8e40f6c 100644 --- a/nix/readTree/default.nix +++ b/nix/readTree/default.nix @@ -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 {}); + }; } diff --git a/nix/utils/default.nix b/nix/utils/default.nix index d90dee24af..f65d4712a0 100644 --- a/nix/utils/default.nix +++ b/nix/utils/default.nix @@ -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 diff --git a/nix/writers/tests/rust.nix b/nix/writers/tests/rust.nix index 4b87676118..8a12c95ec7 100644 --- a/nix/writers/tests/rust.nix +++ b/nix/writers/tests/rust.nix @@ -60,7 +60,7 @@ let ''); -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit rustTransitiveLib rustWithLib diff --git a/ops/dns/default.nix b/ops/dns/default.nix index 1007be08f7..136a4c58dc 100644 --- a/ops/dns/default.nix +++ b/ops/dns/default.nix @@ -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; diff --git a/third_party/gerrit_plugins/default.nix b/third_party/gerrit_plugins/default.nix index 08a9e17ff9..8131ca2eb0 100644 --- a/third_party/gerrit_plugins/default.nix +++ b/third_party/gerrit_plugins/default.nix @@ -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"; diff --git a/third_party/nixery/default.nix b/third_party/nixery/default.nix index 0220c9cd80..9262f14614 100644 --- a/third_party/nixery/default.nix +++ b/third_party/nixery/default.nix @@ -3,7 +3,7 @@ { depot, pkgs, ... }: let - inherit (depot.nix.utils) drvTargets; + inherit (depot.nix.readTree) drvTargets; commit = "6c4a69fa4280f0154ce257a1dfd23fb463c1ec5b"; src = pkgs.fetchFromGitHub { diff --git a/tools/rust-crates-advisory/default.nix b/tools/rust-crates-advisory/default.nix index 9490e3f474..c0cd4dc03e 100644 --- a/tools/rust-crates-advisory/default.nix +++ b/tools/rust-crates-advisory/default.nix @@ -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 diff --git a/users/Profpatsch/arglib/netencode.nix b/users/Profpatsch/arglib/netencode.nix index 7712bbd5bb..50f4c11c2d 100644 --- a/users/Profpatsch/arglib/netencode.nix +++ b/users/Profpatsch/arglib/netencode.nix @@ -37,4 +37,4 @@ let ''; }; -in depot.nix.utils.drvTargets netencode +in depot.nix.readTree.drvTargets netencode diff --git a/users/Profpatsch/blog/default.nix b/users/Profpatsch/blog/default.nix index 4e24d097e3..6ac3c3eb51 100644 --- a/users/Profpatsch/blog/default.nix +++ b/users/Profpatsch/blog/default.nix @@ -358,7 +358,7 @@ let bins.cdbget "$2" ]; -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit router depotCgitLink diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix index 2d1b911373..1f75b97591 100644 --- a/users/Profpatsch/execline/default.nix +++ b/users/Profpatsch/execline/default.nix @@ -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 ; diff --git a/users/Profpatsch/netencode/default.nix b/users/Profpatsch/netencode/default.nix index db892cc9de..739bda3d78 100644 --- a/users/Profpatsch/netencode/default.nix +++ b/users/Profpatsch/netencode/default.nix @@ -135,7 +135,7 @@ let } ''; -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit netencode-rs pretty-rs diff --git a/users/Profpatsch/netstring/default.nix b/users/Profpatsch/netstring/default.nix index eee5358fdd..dcc29d7e6f 100644 --- a/users/Profpatsch/netstring/default.nix +++ b/users/Profpatsch/netstring/default.nix @@ -55,7 +55,7 @@ let } ''; -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit python-netstring rust-netstring diff --git a/users/Profpatsch/netstring/tests/default.nix b/users/Profpatsch/netstring/tests/default.nix index f64beb9e92..710ba3d305 100644 --- a/users/Profpatsch/netstring/tests/default.nix +++ b/users/Profpatsch/netstring/tests/default.nix @@ -53,7 +53,7 @@ let } ''; -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit python-netstring-test rust-netstring-test diff --git a/users/Profpatsch/nixpkgs-rewriter/default.nix b/users/Profpatsch/nixpkgs-rewriter/default.nix index 9dac018441..787162d497 100644 --- a/users/Profpatsch/nixpkgs-rewriter/default.nix +++ b/users/Profpatsch/nixpkgs-rewriter/default.nix @@ -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 don’t want in tvl for now diff --git a/users/Profpatsch/tree-sitter.nix b/users/Profpatsch/tree-sitter.nix index 1e3f378019..4f81b8e7a7 100644 --- a/users/Profpatsch/tree-sitter.nix +++ b/users/Profpatsch/tree-sitter.nix @@ -169,7 +169,7 @@ let ''; }; -in depot.nix.utils.drvTargets { +in depot.nix.readTree.drvTargets { inherit print-ast tree-sitter-nix diff --git a/users/Profpatsch/writers/tests/default.nix b/users/Profpatsch/writers/tests/default.nix index c4769a28c6..dc760af9e1 100644 --- a/users/Profpatsch/writers/tests/default.nix +++ b/users/Profpatsch/writers/tests/default.nix @@ -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 ; diff --git a/users/tazjin/dns/default.nix b/users/tazjin/dns/default.nix index 14b9d42864..da92b88bea 100644 --- a/users/tazjin/dns/default.nix +++ b/users/tazjin/dns/default.nix @@ -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; } diff --git a/web/tvl/logo/default.nix b/web/tvl/logo/default.nix index 74ab4de7dd..940f67199b 100644 --- a/web/tvl/logo/default.nix +++ b/web/tvl/logo/default.nix @@ -67,7 +67,7 @@ let ''; -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; -- cgit 1.4.1