diff options
author | Yueh-Shun Li <shamrocklee@posteo.net> | 2024-03-15 04:35:36 +0800 |
---|---|---|
committer | Yueh-Shun Li <shamrocklee@posteo.net> | 2024-03-19 02:45:50 +0800 |
commit | e9fd4389d2cc2289150d067623c908870ee556e3 (patch) | |
tree | d656cedf344f40db10040a52a7d749c7309ceb8a /pkgs/build-support/trivial-builders | |
parent | 9b54fb452468f74e0f93cc339a85d7132527b6ab (diff) |
writeClosure: init, replacing writeReferencesToFile
Replace writeReferencesToFile with writeClosure. Make writeClosure accept a list of paths instead of a path. Re-implement with JSON-based exportReferencesGraph interface provided by __structuredAttrs = true. Reword the documentation. Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Someone Serge <sergei.kozlukov@aalto.fi>
Diffstat (limited to 'pkgs/build-support/trivial-builders')
-rw-r--r-- | pkgs/build-support/trivial-builders/default.nix | 24 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix | 23 |
2 files changed, 37 insertions, 10 deletions
diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index df81d67d868da..d7438923a54b8 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, stdenvNoCC, lndir, runtimeShell, shellcheck-minimal }: +{ lib, config, stdenv, stdenvNoCC, jq, lndir, runtimeShell, shellcheck-minimal }: let inherit (lib) @@ -625,18 +625,22 @@ rec { # Docs in doc/build-helpers/trivial-build-helpers.chapter.md # See https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-writeReferencesToFile - writeReferencesToFile = path: runCommand "runtime-deps" + # TODO: Convert to throw after Nixpkgs 24.05 branch-off. + writeReferencesToFile = (if config.allowAliases then lib.warn else throw) + "writeReferencesToFile is deprecated in favour of writeClosure" + (path: writeClosure [ path ]); + + # Docs in doc/build-helpers/trivial-build-helpers.chapter.md + # See https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-writeClosure + writeClosure = paths: runCommand "runtime-deps" { - exportReferencesGraph = [ "graph" path ]; + # Get the cleaner exportReferencesGraph interface + __structuredAttrs = true; + exportReferencesGraph.graph = paths; + nativeBuildInputs = [ jq ]; } '' - touch $out - while read path; do - echo $path >> $out - read dummy - read nrRefs - for ((i = 0; i < nrRefs; i++)); do read ref; done - done < graph + jq -r ".graph | map(.path) | sort | .[]" "$NIX_ATTRS_JSON_FILE" > "$out" ''; # Docs in doc/build-helpers/trivial-build-helpers.chapter.md diff --git a/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix b/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix new file mode 100644 index 0000000000000..fed3a4f2adbcd --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeReferenceClosureToFile-mixed.nix @@ -0,0 +1,23 @@ +{ lib +, runCommandLocal + # Test targets +, writeClosure +, samples +}: +runCommandLocal "test-trivial-builders-writeClosure-mixed" { + __structuredAttrs = true; + references = lib.mapAttrs (n: v: writeClosure [ v ]) samples; + allRefs = writeClosure (lib.attrValues samples); + inherit samples; + meta.maintainers = with lib.maintainers; [ + ShamrockLee + ]; +} '' + set -eu -o pipefail + echo >&2 Testing mixed closures... + echo >&2 Checking all samples "(''${samples[*]})" "$allRefs" + diff -U3 \ + <(sort <"$allRefs") \ + <(cat "''${references[@]}" | sort | uniq) + touch "$out" +'' |