2020-10-23 13:20:38 +00:00
|
|
|
source common.sh
|
|
|
|
|
2022-03-24 22:36:14 +00:00
|
|
|
clearStore
|
|
|
|
|
2022-04-20 14:39:47 +00:00
|
|
|
# Make sure that 'nix build' returns all outputs by default.
|
|
|
|
nix build -f multiple-outputs.nix --json a b --no-link | jq --exit-status '
|
2020-10-23 13:20:38 +00:00
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
2021-02-12 21:51:36 +00:00
|
|
|
(.outputs |
|
2022-03-25 16:46:28 +00:00
|
|
|
(keys | length == 2) and
|
2021-02-12 21:51:36 +00:00
|
|
|
(.first | match(".*multiple-outputs-a-first")) and
|
|
|
|
(.second | match(".*multiple-outputs-a-second"))))
|
2020-10-23 13:20:38 +00:00
|
|
|
and (.[1] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-b.drv")) and
|
2022-03-25 16:46:28 +00:00
|
|
|
(.outputs |
|
|
|
|
(keys | length == 1) and
|
|
|
|
(.out | match(".*multiple-outputs-b"))))
|
2020-10-23 13:20:38 +00:00
|
|
|
'
|
2022-03-24 22:36:14 +00:00
|
|
|
|
2022-04-22 13:17:01 +00:00
|
|
|
# Test output selection using the '^' syntax.
|
|
|
|
nix build -f multiple-outputs.nix --json a^first --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs | keys == ["first"]))
|
|
|
|
'
|
|
|
|
|
|
|
|
nix build -f multiple-outputs.nix --json a^second,first --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs | keys == ["first", "second"]))
|
|
|
|
'
|
|
|
|
|
|
|
|
nix build -f multiple-outputs.nix --json 'a^*' --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs | keys == ["first", "second"]))
|
|
|
|
'
|
|
|
|
|
|
|
|
# Test that 'outputsToInstall' is respected by default.
|
|
|
|
nix build -f multiple-outputs.nix --json e --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
2023-01-18 13:14:29 +00:00
|
|
|
(.outputs | keys == ["a_a", "b"]))
|
2022-04-22 13:17:01 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
# But not when it's overriden.
|
2023-01-18 13:14:29 +00:00
|
|
|
nix build -f multiple-outputs.nix --json e^a_a --no-link
|
|
|
|
nix build -f multiple-outputs.nix --json e^a_a --no-link | jq --exit-status '
|
2022-04-22 13:17:01 +00:00
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
2023-01-18 13:14:29 +00:00
|
|
|
(.outputs | keys == ["a_a"]))
|
2022-04-22 13:17:01 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
nix build -f multiple-outputs.nix --json 'e^*' --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
2023-01-18 13:14:29 +00:00
|
|
|
(.outputs | keys == ["a_a", "b", "c"]))
|
2022-04-22 13:17:01 +00:00
|
|
|
'
|
|
|
|
|
Make more string values work as installables
As discussed in #7417, it would be good to make more string values work
as installables. That is to say, if an installable refers to a value,
and the value is a string, it used to not work at all, since #7484, it
works somewhat, and this PR make it work some more.
The new cases that are added for `BuiltPath` contexts:
- Fixed input- or content-addressed derivation:
```
nix-repl> hello.out.outPath
"/nix/store/jppfl2bp1zhx8sgs2mgifmsx6dv16mv2-hello-2.12"
nix-repl> :p builtins.getContext hello.out.outPath
{ "/nix/store/c7jrxqjhdda93lhbkanqfs07x2bzazbm-hello-2.12.drv" = { outputs = [ "out" ]; }; }
The string matches the specified single output of that derivation, so
it should also be valid.
- Floating content-addressed derivation:
```
nix-repl> (hello.overrideAttrs (_: { __contentAddressed = true; })).out.outPath
"/1a08j26xqc0zm8agps8anxpjji410yvsx4pcgyn4bfan1ddkx2g0"
nix-repl> :p builtins.getContext (hello.overrideAttrs (_: { __contentAddressed = true; })).out.outPath
{ "/nix/store/qc645pyf9wl37c6qvqzaqkwsm1gp48al-hello-2.12.drv" = { outputs = [ "out" ]; }; }
```
The string is not a path but a placeholder, however it also matches
the context, and because it is a CA derivation we have no better
option. This should also be valid.
We may also want to think about richer attrset based values (also
discussed in that issue and #6507), but this change "completes" our
string-based building blocks, from which the others can be desugared
into or at least described/document/taught in terms of.
Progress towards #7417
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-01-10 22:18:59 +00:00
|
|
|
# test buidling from non-drv attr path
|
|
|
|
|
|
|
|
nix build -f multiple-outputs.nix --json 'e.a_a.outPath' --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
|
|
|
(.outputs | keys == ["a_a"]))
|
|
|
|
'
|
|
|
|
|
|
|
|
# Illegal type of string context
|
|
|
|
expectStderr 1 nix build -f multiple-outputs.nix 'e.a_a.drvPath' \
|
|
|
|
| grepQuiet "has a context which refers to a complete source and binary closure."
|
|
|
|
|
|
|
|
# No string context
|
|
|
|
expectStderr 1 nix build --expr '""' --no-link \
|
|
|
|
| grepQuiet "has 0 entries in its context. It should only have exactly one entry"
|
|
|
|
|
|
|
|
# Too much string context
|
|
|
|
expectStderr 1 nix build --impure --expr 'with (import ./multiple-outputs.nix).e.a_a; "${drvPath}${outPath}"' --no-link \
|
|
|
|
| grepQuiet "has 2 entries in its context. It should only have exactly one entry"
|
|
|
|
|
|
|
|
nix build --impure --json --expr 'builtins.unsafeDiscardOutputDependency (import ./multiple-outputs.nix).e.a_a.drvPath' --no-link | jq --exit-status '
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-15 22:39:04 +00:00
|
|
|
(.[0] | match(".*multiple-outputs-e.drv"))
|
Make more string values work as installables
As discussed in #7417, it would be good to make more string values work
as installables. That is to say, if an installable refers to a value,
and the value is a string, it used to not work at all, since #7484, it
works somewhat, and this PR make it work some more.
The new cases that are added for `BuiltPath` contexts:
- Fixed input- or content-addressed derivation:
```
nix-repl> hello.out.outPath
"/nix/store/jppfl2bp1zhx8sgs2mgifmsx6dv16mv2-hello-2.12"
nix-repl> :p builtins.getContext hello.out.outPath
{ "/nix/store/c7jrxqjhdda93lhbkanqfs07x2bzazbm-hello-2.12.drv" = { outputs = [ "out" ]; }; }
The string matches the specified single output of that derivation, so
it should also be valid.
- Floating content-addressed derivation:
```
nix-repl> (hello.overrideAttrs (_: { __contentAddressed = true; })).out.outPath
"/1a08j26xqc0zm8agps8anxpjji410yvsx4pcgyn4bfan1ddkx2g0"
nix-repl> :p builtins.getContext (hello.overrideAttrs (_: { __contentAddressed = true; })).out.outPath
{ "/nix/store/qc645pyf9wl37c6qvqzaqkwsm1gp48al-hello-2.12.drv" = { outputs = [ "out" ]; }; }
```
The string is not a path but a placeholder, however it also matches
the context, and because it is a CA derivation we have no better
option. This should also be valid.
We may also want to think about richer attrset based values (also
discussed in that issue and #6507), but this change "completes" our
string-based building blocks, from which the others can be desugared
into or at least described/document/taught in terms of.
Progress towards #7417
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-01-10 22:18:59 +00:00
|
|
|
'
|
|
|
|
|
2022-12-12 22:34:57 +00:00
|
|
|
# Test building from raw store path to drv not expression.
|
|
|
|
|
|
|
|
drv=$(nix eval -f multiple-outputs.nix --raw a.drvPath)
|
|
|
|
if nix build "$drv^not-an-output" --no-link --json; then
|
|
|
|
fail "'not-an-output' should fail to build"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if nix build "$drv^" --no-link --json; then
|
|
|
|
fail "'empty outputs list' should fail to build"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if nix build "$drv^*nope" --no-link --json; then
|
|
|
|
fail "'* must be entire string' should fail to build"
|
|
|
|
fi
|
|
|
|
|
|
|
|
nix build "$drv^first" --no-link --json | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs |
|
|
|
|
(keys | length == 1) and
|
|
|
|
(.first | match(".*multiple-outputs-a-first")) and
|
|
|
|
(has("second") | not)))
|
|
|
|
'
|
|
|
|
|
|
|
|
nix build "$drv^first,second" --no-link --json | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs |
|
|
|
|
(keys | length == 2) and
|
|
|
|
(.first | match(".*multiple-outputs-a-first")) and
|
2023-01-18 15:33:39 +00:00
|
|
|
(.second | match(".*multiple-outputs-a-second"))))
|
2022-12-12 22:34:57 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
nix build "$drv^*" --no-link --json | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
|
|
|
(.outputs |
|
|
|
|
(keys | length == 2) and
|
|
|
|
(.first | match(".*multiple-outputs-a-first")) and
|
2023-01-18 15:33:39 +00:00
|
|
|
(.second | match(".*multiple-outputs-a-second"))))
|
2022-12-12 22:34:57 +00:00
|
|
|
'
|
|
|
|
|
2022-05-05 12:53:59 +00:00
|
|
|
# Make sure that `--impure` works (regression test for https://github.com/NixOS/nix/issues/6488)
|
|
|
|
nix build --impure -f multiple-outputs.nix --json e --no-link | jq --exit-status '
|
|
|
|
(.[0] |
|
|
|
|
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
2023-01-18 13:14:29 +00:00
|
|
|
(.outputs | keys == ["a_a", "b"]))
|
2022-05-05 12:53:59 +00:00
|
|
|
'
|
2023-06-12 12:40:17 +00:00
|
|
|
|
|
|
|
# Make sure that `--stdin` works and does not apply any defaults
|
|
|
|
printf "" | nix build --no-link --stdin --json | jq --exit-status '. == []'
|
|
|
|
printf "%s\n" "$drv^*" | nix build --no-link --stdin --json | jq --exit-status '.[0]|has("drvPath")'
|
2024-05-13 18:58:54 +00:00
|
|
|
|
2024-08-25 11:41:56 +00:00
|
|
|
# URL reporting
|
|
|
|
out="$(nix-build fod-failing.nix -A x1 2>&1)" && status=0 || status=$?
|
|
|
|
test "$status" = 102
|
|
|
|
test "$(<<<"$out" grep -E '^error:' | wc -l)" = 1
|
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x1\\.drv'"
|
|
|
|
<<<"$out" grepQuiet -E "likely URL: https://meow.puppy.forge/puppy.tar.gz"
|
|
|
|
|
2024-05-13 18:58:54 +00:00
|
|
|
# --keep-going and FOD
|
|
|
|
out="$(nix build -f fod-failing.nix -L 2>&1)" && status=0 || status=$?
|
|
|
|
test "$status" = 1
|
2024-10-05 12:29:52 +00:00
|
|
|
# at least one "hash mismatch" error, one "build of ... failed"
|
|
|
|
test "$(<<<"$out" grep -E '^error:' | wc -l)" -ge 2
|
2024-09-25 21:57:46 +00:00
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x.\\.drv'"
|
|
|
|
<<<"$out" grepQuiet -E "likely URL: "
|
2024-05-13 18:58:54 +00:00
|
|
|
<<<"$out" grepQuiet -E "error: build of '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out', '.*-x[1-4]\\.drv\\^out' failed"
|
|
|
|
|
|
|
|
out="$(nix build -f fod-failing.nix -L x1 x2 x3 --keep-going 2>&1)" && status=0 || status=$?
|
|
|
|
test "$status" = 1
|
|
|
|
# three "hash mismatch" errors - for each failing fod, one "build of ... failed"
|
|
|
|
test "$(<<<"$out" grep -E '^error:' | wc -l)" = 4
|
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x1\\.drv'"
|
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x3\\.drv'"
|
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|
2024-06-28 05:43:02 +00:00
|
|
|
<<<"$out" grepQuiet -E "likely URL: https://meow.puppy.forge/puppy.tar.gz"
|
|
|
|
<<<"$out" grepQuiet -E "likely URL: https://kitty.forge/cat.tar.gz"
|
|
|
|
<<<"$out" grepQuiet -E "likely URL: \(unknown\)"
|
2024-05-13 18:58:54 +00:00
|
|
|
<<<"$out" grepQuiet -E "error: build of '.*-x[1-3]\\.drv\\^out', '.*-x[1-3]\\.drv\\^out', '.*-x[1-3]\\.drv\\^out' failed"
|
|
|
|
|
|
|
|
out="$(nix build -f fod-failing.nix -L x4 2>&1)" && status=0 || status=$?
|
|
|
|
test "$status" = 1
|
2024-09-28 21:18:35 +00:00
|
|
|
test "$(<<<"$out" grep -E '^error:' | wc -l)" -ge 2
|
|
|
|
<<<"$out" grepQuiet -E "error: [12] dependencies of derivation '.*-x4\\.drv' failed to build"
|
|
|
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x[23]\\.drv'"
|
2024-05-13 18:58:54 +00:00
|
|
|
|
|
|
|
out="$(nix build -f fod-failing.nix -L x4 --keep-going 2>&1)" && status=0 || status=$?
|
|
|
|
test "$status" = 1
|
|
|
|
test "$(<<<"$out" grep -E '^error:' | wc -l)" = 3
|
|
|
|
<<<"$out" grepQuiet -E "error: 2 dependencies of derivation '.*-x4\\.drv' failed to build"
|
|
|
|
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x3\\.drv'"
|
|
|
|
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|