1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

Format .nix files

... with nixfmt (rfc style)
This commit is contained in:
Robert Hensing 2025-01-24 13:37:47 +01:00
parent ba6425a7d0
commit 96e550efc5
266 changed files with 7460 additions and 5138 deletions

View file

@ -1,6 +1,25 @@
let
sixteenBytes = "0123456789abcdef";
times16 = s: builtins.concatStringsSep "" [s s s s s s s s s s s s s s s s];
times16 =
s:
builtins.concatStringsSep "" [
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
];
exp = n: x: if n == 1 then x else times16 (exp (n - 1) x);
sixteenMegabyte = exp 6 sixteenBytes;
in

View file

@ -4,24 +4,39 @@ with import ./config.nix;
let
mkDerivation = args:
derivation ({
inherit system;
builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')];
outputHashMode = "recursive";
outputHashAlgo = "sha256";
} // removeAttrs args ["builder" "meta" "passthru"])
// { meta = args.meta or {}; passthru = args.passthru or {}; };
mkDerivation =
args:
derivation (
{
inherit system;
builder = busybox;
args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')
];
outputHashMode = "recursive";
outputHashAlgo = "sha256";
}
// removeAttrs args [
"builder"
"meta"
"passthru"
]
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation {
shell = busybox;
name = "build-remote-input-1";
buildCommand = "echo hi-input1; echo FOO > $out";
requiredSystemFeatures = ["foo"];
requiredSystemFeatures = [ "foo" ];
outputHash = "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=";
};
@ -29,7 +44,7 @@ let
shell = busybox;
name = "build-remote-input-2";
buildCommand = "echo hi; echo BAR > $out";
requiredSystemFeatures = ["bar"];
requiredSystemFeatures = [ "bar" ];
outputHash = "sha256-XArauVH91AVwP9hBBQNlkX9ccuPpSYx9o0zeIHb6e+Q=";
};
@ -41,21 +56,20 @@ let
read x < ${input2}
echo $x BAZ > $out
'';
requiredSystemFeatures = ["baz"];
requiredSystemFeatures = [ "baz" ];
outputHash = "sha256-daKAcPp/+BYMQsVi/YYMlCKoNAxCNDsaivwSHgQqD2s=";
};
in
mkDerivation {
shell = busybox;
name = "build-remote";
passthru = { inherit input1 input2 input3; };
buildCommand =
''
read x < ${input1}
read y < ${input3}
echo "$x $y" > $out
'';
outputHash = "sha256-5SxbkUw6xe2l9TE1uwCvTtTDysD1vhRor38OtDF0LqQ=";
}
mkDerivation {
shell = busybox;
name = "build-remote";
passthru = { inherit input1 input2 input3; };
buildCommand = ''
read x < ${input1}
read y < ${input3}
echo "$x $y" > $out
'';
outputHash = "sha256-5SxbkUw6xe2l9TE1uwCvTtTDysD1vhRor38OtDF0LqQ=";
}

View file

@ -1,39 +1,61 @@
{ busybox, contentAddressed ? false }:
{
busybox,
contentAddressed ? false,
}:
with import ./config.nix;
let
caArgs = if contentAddressed then {
outputHashMode = "recursive";
outputHashAlgo = "sha256";
__contentAddressed = true;
} else {};
caArgs =
if contentAddressed then
{
outputHashMode = "recursive";
outputHashAlgo = "sha256";
__contentAddressed = true;
}
else
{ };
mkDerivation = args:
derivation ({
inherit system;
builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')];
} // removeAttrs args ["builder" "meta" "passthru"]
// caArgs)
// { meta = args.meta or {}; passthru = args.passthru or {}; };
mkDerivation =
args:
derivation (
{
inherit system;
builder = busybox;
args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')
];
}
// removeAttrs args [
"builder"
"meta"
"passthru"
]
// caArgs
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation {
shell = busybox;
name = "build-remote-input-1";
buildCommand = "echo hi-input1; echo FOO > $out";
requiredSystemFeatures = ["foo"];
requiredSystemFeatures = [ "foo" ];
};
input2 = mkDerivation {
shell = busybox;
name = "build-remote-input-2";
buildCommand = "echo hi; echo BAR > $out";
requiredSystemFeatures = ["bar"];
requiredSystemFeatures = [ "bar" ];
};
input3 = mkDerivation {
@ -44,19 +66,18 @@ let
read x < ${input2}
echo $x BAZ > $out
'';
requiredSystemFeatures = ["baz"];
requiredSystemFeatures = [ "baz" ];
};
in
mkDerivation {
shell = busybox;
name = "build-remote";
passthru = { inherit input1 input2 input3; };
buildCommand =
''
read x < ${input1}
read y < ${input3}
echo "$x $y" > $out
'';
}
mkDerivation {
shell = busybox;
name = "build-remote";
passthru = { inherit input1 input2 input3; };
buildCommand = ''
read x < ${input1}
read y < ${input3}
echo "$x $y" > $out
'';
}

View file

@ -1 +1,5 @@
{ inNixShell ? false, ... }@args: import ./shell.nix (args // { contentAddressed = true; })
{
inNixShell ? false,
...
}@args:
import ./shell.nix (args // { contentAddressed = true; })

View file

@ -1,13 +1,21 @@
with import ./config.nix;
let mkCADerivation = args: mkDerivation ({
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
} // args);
let
mkCADerivation =
args:
mkDerivation (
{
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
}
// args
);
in
{ seed ? 0 }:
{
seed ? 0,
}:
# A simple content-addressed derivation.
# The derivation can be arbitrarily modified by passing a different `seed`,
# but the output will always be the same
@ -23,7 +31,11 @@ rec {
};
rootCA = mkCADerivation {
name = "rootCA";
outputs = [ "out" "dev" "foo" ];
outputs = [
"out"
"dev"
"foo"
];
buildCommand = ''
echo "building a CA derivation"
echo "The seed is ${toString seed}"

View file

@ -1,3 +1,3 @@
{
outputs = { self }: import ./content-addressed.nix {};
outputs = { self }: import ./content-addressed.nix { };
}

View file

@ -1,10 +1,16 @@
with import ./config.nix;
let mkCADerivation = args: mkDerivation ({
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
} // args);
let
mkCADerivation =
args:
mkDerivation (
{
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
}
// args
);
in
rec {
@ -15,13 +21,15 @@ rec {
echo $(date) > $out/current-time
'';
};
dep = seed: mkCADerivation {
name = "dep";
inherit seed;
buildCommand = ''
echo ${currentTime} > $out
'';
};
dep =
seed:
mkCADerivation {
name = "dep";
inherit seed;
buildCommand = ''
echo ${currentTime} > $out
'';
};
dep1 = dep 1;
dep2 = dep 2;
toplevel = mkCADerivation {
@ -32,4 +40,3 @@ rec {
'';
};
}

View file

@ -1,7 +1,6 @@
# A derivation that would certainly fail if several builders tried to
# build it at once.
with import ./config.nix;
mkDerivation {

View file

@ -2,11 +2,16 @@ with import ./config.nix;
rec {
dep = import ./dependencies.nix {};
dep = import ./dependencies.nix { };
makeTest = nr: args: mkDerivation ({
name = "check-refs-" + toString nr;
} // args);
makeTest =
nr: args:
mkDerivation (
{
name = "check-refs-" + toString nr;
}
// args
);
src = builtins.toFile "aux-ref" "bla bla";
@ -22,31 +27,31 @@ rec {
test3 = makeTest 3 {
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $dep $out/link";
allowedReferences = [];
allowedReferences = [ ];
inherit dep;
};
test4 = makeTest 4 {
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $dep $out/link";
allowedReferences = [dep];
allowedReferences = [ dep ];
inherit dep;
};
test5 = makeTest 5 {
builder = builtins.toFile "builder.sh" "mkdir $out";
allowedReferences = [];
allowedReferences = [ ];
inherit dep;
};
test6 = makeTest 6 {
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $out $out/link";
allowedReferences = [];
allowedReferences = [ ];
inherit dep;
};
test7 = makeTest 7 {
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $out $out/link";
allowedReferences = ["out"];
allowedReferences = [ "out" ];
inherit dep;
};
@ -58,19 +63,19 @@ rec {
test9 = makeTest 9 {
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $dep $out/link";
inherit dep;
disallowedReferences = [dep];
disallowedReferences = [ dep ];
};
test10 = makeTest 10 {
builder = builtins.toFile "builder.sh" "mkdir $out; echo $test5; ln -s $dep $out/link";
inherit dep test5;
disallowedReferences = [test5];
disallowedReferences = [ test5 ];
};
test11 = makeTest 11 {
__structuredAttrs = true;
unsafeDiscardReferences.out = true;
outputChecks.out.allowedReferences = [];
outputChecks.out.allowedReferences = [ ];
buildCommand = ''echo ${dep} > "''${outputs[out]}"'';
};

View file

@ -22,36 +22,48 @@ rec {
'';
};
makeTest = nr: allowreqs: mkDerivation {
name = "check-reqs-" + toString nr;
inherit deps;
builder = builtins.toFile "builder.sh" ''
mkdir $out
ln -s $deps $out/depdir1
'';
allowedRequisites = allowreqs;
};
makeTest =
nr: allowreqs:
mkDerivation {
name = "check-reqs-" + toString nr;
inherit deps;
builder = builtins.toFile "builder.sh" ''
mkdir $out
ln -s $deps $out/depdir1
'';
allowedRequisites = allowreqs;
};
# When specifying all the requisites, the build succeeds.
test1 = makeTest 1 [ dep1 dep2 deps ];
test1 = makeTest 1 [
dep1
dep2
deps
];
# But missing anything it fails.
test2 = makeTest 2 [ dep2 deps ];
test3 = makeTest 3 [ dep1 deps ];
test2 = makeTest 2 [
dep2
deps
];
test3 = makeTest 3 [
dep1
deps
];
test4 = makeTest 4 [ deps ];
test5 = makeTest 5 [];
test5 = makeTest 5 [ ];
test6 = mkDerivation {
name = "check-reqs";
inherit deps;
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $deps $out/depdir1";
disallowedRequisites = [dep1];
disallowedRequisites = [ dep1 ];
};
test7 = mkDerivation {
name = "check-reqs";
inherit deps;
builder = builtins.toFile "builder.sh" "mkdir $out; ln -s $deps $out/depdir1";
disallowedRequisites = [test1];
disallowedRequisites = [ test1 ];
};
}

View file

@ -1,4 +1,6 @@
{checkBuildId ? 0}:
{
checkBuildId ? 0,
}:
with import ./config.nix;
@ -6,41 +8,38 @@ with import ./config.nix;
nondeterministic = mkDerivation {
inherit checkBuildId;
name = "nondeterministic";
buildCommand =
''
mkdir $out
date +%s.%N > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
'';
buildCommand = ''
mkdir $out
date +%s.%N > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
'';
};
deterministic = mkDerivation {
inherit checkBuildId;
name = "deterministic";
buildCommand =
''
mkdir $out
echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
'';
buildCommand = ''
mkdir $out
echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
'';
};
failed = mkDerivation {
inherit checkBuildId;
name = "failed";
buildCommand =
''
mkdir $out
echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
false
'';
buildCommand = ''
mkdir $out
echo date > $out/date
echo "CHECK_TMPDIR=$TMPDIR"
echo "checkBuildId=$checkBuildId"
echo "$checkBuildId" > $TMPDIR/checkBuildId
false
'';
};
hashmismatch = import <nix/fetchurl.nix> {

View file

@ -1,4 +1,6 @@
{ hashInvalidator ? "" }:
{
hashInvalidator ? "",
}:
with import ./config.nix;
let

View file

@ -2,5 +2,8 @@ derivation {
name = "advanced-attributes-defaults";
system = "my-system";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
args = [
"-c"
"echo hello > $out"
];
}

View file

@ -2,7 +2,13 @@ derivation {
name = "advanced-attributes-structured-attrs-defaults";
system = "my-system";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
outputs = [ "out" "dev" ];
args = [
"-c"
"echo hello > $out"
];
outputs = [
"out"
"dev"
];
__structuredAttrs = true;
}

View file

@ -4,42 +4,58 @@ let
inherit system;
name = "foo";
builder = "/bin/bash";
args = ["-c" "echo foo > $out"];
args = [
"-c"
"echo foo > $out"
];
};
bar = derivation {
inherit system;
name = "bar";
builder = "/bin/bash";
args = ["-c" "echo bar > $out"];
args = [
"-c"
"echo bar > $out"
];
};
in
derivation {
inherit system;
name = "advanced-attributes-structured-attrs";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
args = [
"-c"
"echo hello > $out"
];
__sandboxProfile = "sandcastle";
__noChroot = true;
__impureHostDeps = ["/usr/bin/ditto"];
impureEnvVars = ["UNICORN"];
__impureHostDeps = [ "/usr/bin/ditto" ];
impureEnvVars = [ "UNICORN" ];
__darwinAllowLocalNetworking = true;
outputs = [ "out" "bin" "dev" ];
outputs = [
"out"
"bin"
"dev"
];
__structuredAttrs = true;
outputChecks = {
out = {
allowedReferences = [foo];
allowedRequisites = [foo];
allowedReferences = [ foo ];
allowedRequisites = [ foo ];
};
bin = {
disallowedReferences = [bar];
disallowedRequisites = [bar];
disallowedReferences = [ bar ];
disallowedRequisites = [ bar ];
};
dev = {
maxSize = 789;
maxClosureSize = 5909;
};
};
requiredSystemFeatures = ["rainbow" "uid-range"];
requiredSystemFeatures = [
"rainbow"
"uid-range"
];
preferLocalBuild = true;
allowSubstitutes = false;
}

View file

@ -4,30 +4,42 @@ let
inherit system;
name = "foo";
builder = "/bin/bash";
args = ["-c" "echo foo > $out"];
args = [
"-c"
"echo foo > $out"
];
};
bar = derivation {
inherit system;
name = "bar";
builder = "/bin/bash";
args = ["-c" "echo bar > $out"];
args = [
"-c"
"echo bar > $out"
];
};
in
derivation {
inherit system;
name = "advanced-attributes";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
args = [
"-c"
"echo hello > $out"
];
__sandboxProfile = "sandcastle";
__noChroot = true;
__impureHostDeps = ["/usr/bin/ditto"];
impureEnvVars = ["UNICORN"];
__impureHostDeps = [ "/usr/bin/ditto" ];
impureEnvVars = [ "UNICORN" ];
__darwinAllowLocalNetworking = true;
allowedReferences = [foo];
allowedRequisites = [foo];
disallowedReferences = [bar];
disallowedRequisites = [bar];
requiredSystemFeatures = ["rainbow" "uid-range"];
allowedReferences = [ foo ];
allowedRequisites = [ foo ];
disallowedReferences = [ bar ];
disallowedRequisites = [ bar ];
requiredSystemFeatures = [
"rainbow"
"uid-range"
];
preferLocalBuild = true;
allowSubstitutes = false;
}

View file

@ -1,6 +1,8 @@
with import ./config.nix;
let innerName = "foo"; in
let
innerName = "foo";
in
mkDerivation rec {
name = "${innerName}.drv";

View file

@ -2,28 +2,33 @@ with import ./config.nix;
rec {
printRefs =
''
echo $exportReferencesGraph
while read path; do
read drv
read nrRefs
echo "$path has $nrRefs references"
echo "$path" >> $out
for ((n = 0; n < $nrRefs; n++)); do read ref; echo "ref $ref"; test -e "$ref"; done
done < refs
'';
printRefs = ''
echo $exportReferencesGraph
while read path; do
read drv
read nrRefs
echo "$path has $nrRefs references"
echo "$path" >> $out
for ((n = 0; n < $nrRefs; n++)); do read ref; echo "ref $ref"; test -e "$ref"; done
done < refs
'';
foo."bar.runtimeGraph" = mkDerivation {
name = "dependencies";
builder = builtins.toFile "build-graph-builder" "${printRefs}";
exportReferencesGraph = ["refs" (import ./dependencies.nix {})];
exportReferencesGraph = [
"refs"
(import ./dependencies.nix { })
];
};
foo."bar.buildGraph" = mkDerivation {
name = "dependencies";
builder = builtins.toFile "build-graph-builder" "${printRefs}";
exportReferencesGraph = ["refs" (import ./dependencies.nix {}).drvPath];
exportReferencesGraph = [
"refs"
(import ./dependencies.nix { }).drvPath
];
};
}

View file

@ -2,16 +2,29 @@
with import ./config.nix;
let
mkDerivation = args:
derivation ({
inherit system;
builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')];
} // removeAttrs args ["builder" "meta"])
// { meta = args.meta or {}; };
mkDerivation =
args:
derivation (
{
inherit system;
builder = busybox;
args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')
];
}
// removeAttrs args [
"builder"
"meta"
]
)
// {
meta = args.meta or { };
};
in
{

View file

@ -4,9 +4,12 @@ mkDerivation {
name = "filter";
builder = builtins.toFile "builder" "ln -s $input $out";
input =
let filter = path: type:
type != "symlink"
&& baseNameOf path != "foo"
&& !((import ./lang/lib.nix).hasSuffix ".bak" (baseNameOf path));
in builtins.filterSource filter ((builtins.getEnv "TEST_ROOT") + "/filterin");
let
filter =
path: type:
type != "symlink"
&& baseNameOf path != "foo"
&& !((import ./lang/lib.nix).hasSuffix ".bak" (baseNameOf path));
in
builtins.filterSource filter ((builtins.getEnv "TEST_ROOT") + "/filterin");
}

View file

@ -2,15 +2,20 @@ with import ./config.nix;
rec {
f2 = dummy: builder: mode: algo: hash: mkDerivation {
name = "fixed";
inherit builder;
outputHashMode = mode;
outputHashAlgo = algo;
outputHash = hash;
inherit dummy;
impureEnvVars = ["IMPURE_VAR1" "IMPURE_VAR2"];
};
f2 =
dummy: builder: mode: algo: hash:
mkDerivation {
name = "fixed";
inherit builder;
outputHashMode = mode;
outputHashAlgo = algo;
outputHash = hash;
inherit dummy;
impureEnvVars = [
"IMPURE_VAR1"
"IMPURE_VAR2"
];
};
f = f2 "";
@ -37,7 +42,8 @@ rec {
];
sameAsAdd =
f ./fixed.builder2.sh "recursive" "sha256" "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik";
f ./fixed.builder2.sh "recursive" "sha256"
"1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik";
bad = [
(f ./fixed.builder1.sh "flat" "md5" "0ddd8be4b179a529afa5f2ffae4b9858")

View file

@ -2,38 +2,34 @@ with import ./config.nix;
rec {
x1 = mkDerivation {
name = "x1";
builder = builtins.toFile "builder.sh"
''
echo $name > $out
'';
builder = builtins.toFile "builder.sh" ''
echo $name > $out
'';
outputHashMode = "recursive";
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
x2 = mkDerivation {
name = "x2";
builder = builtins.toFile "builder.sh"
''
echo $name > $out
'';
builder = builtins.toFile "builder.sh" ''
echo $name > $out
'';
outputHashMode = "recursive";
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
x3 = mkDerivation {
name = "x3";
builder = builtins.toFile "builder.sh"
''
echo $name > $out
'';
builder = builtins.toFile "builder.sh" ''
echo $name > $out
'';
outputHashMode = "recursive";
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
x4 = mkDerivation {
name = "x4";
inherit x2 x3;
builder = builtins.toFile "builder.sh"
''
echo $x2 $x3
exit 1
'';
builder = builtins.toFile "builder.sh" ''
echo $x2 $x3
exit 1
'';
};
}

View file

@ -1,6 +1,8 @@
with import ./config.nix;
{ lockFifo ? null }:
{
lockFifo ? null,
}:
rec {

View file

@ -4,14 +4,22 @@ let {
name = "dependencies-input-1";
system = "i086-msdos";
builder = "/bar/sh";
args = ["-e" "-x" ./dummy];
args = [
"-e"
"-x"
./dummy
];
};
input2 = derivation {
name = "dependencies-input-2";
system = "i086-msdos";
builder = "/bar/sh";
args = ["-e" "-x" ./dummy];
args = [
"-e"
"-x"
./dummy
];
outputHashMode = "recursive";
outputHashAlgo = "md5";
outputHash = "ffffffffffffffffffffffffffffffff";
@ -21,9 +29,13 @@ let {
name = "dependencies";
system = "i086-msdos";
builder = "/bar/sh";
args = ["-e" "-x" (./dummy + "/FOOBAR/../.")];
args = [
"-e"
"-x"
(./dummy + "/FOOBAR/../.")
];
input1 = input1 + "/.";
inherit input2;
};
}
}

View file

@ -1,31 +1,51 @@
{ busybox
, seed
# If we want the final derivation output to have references to its
# dependencies. Some tests need/want this, other don't.
, withFinalRefs ? false
{
busybox,
seed,
# If we want the final derivation output to have references to its
# dependencies. Some tests need/want this, other don't.
withFinalRefs ? false,
}:
with import ./config.nix;
let
contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1";
caArgs = if contentAddressedByDefault then {
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
} else {};
caArgs =
if contentAddressedByDefault then
{
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
}
else
{ };
mkDerivation = args:
derivation ({
inherit system;
builder = busybox;
args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')];
} // removeAttrs args ["builder" "meta" "passthru"]
// caArgs)
// { meta = args.meta or {}; passthru = args.passthru or {}; };
mkDerivation =
args:
derivation (
{
inherit system;
builder = busybox;
args = [
"sh"
"-e"
args.builder or (builtins.toFile "builder-${args.name}.sh" ''
if [ -e "$NIX_ATTRS_SH_FILE" ]; then source $NIX_ATTRS_SH_FILE; fi;
eval "$buildCommand"
'')
];
}
// removeAttrs args [
"builder"
"meta"
"passthru"
]
// caArgs
)
// {
meta = args.meta or { };
passthru = args.passthru or { };
};
input1 = mkDerivation {
shell = busybox;
@ -51,14 +71,15 @@ let
in
mkDerivation {
shell = busybox;
name = "hermetic";
passthru = { inherit input1 input2 input3; };
buildCommand =
''
read x < ${input1}
read y < ${input3}
echo ${if (builtins.trace withFinalRefs withFinalRefs) then "${input1} ${input3}" else ""} "$x $y" > $out
'';
}
mkDerivation {
shell = busybox;
name = "hermetic";
passthru = { inherit input1 input2 input3; };
buildCommand = ''
read x < ${input1}
read y < ${input3}
echo ${
if (builtins.trace withFinalRefs withFinalRefs) then "${input1} ${input3}" else ""
} "$x $y" > $out
'';
}

View file

@ -1,10 +1,8 @@
with import ./config.nix;
import (
mkDerivation {
name = "foo";
bla = import ./dependencies.nix {};
buildCommand = "
import (mkDerivation {
name = "foo";
bla = import ./dependencies.nix { };
buildCommand = "
echo \\\"hi\\\" > $out
";
}
)
})

View file

@ -3,10 +3,9 @@ with import <config>;
rec {
bar = mkDerivation {
name = "bar";
builder = builtins.toFile "builder.sh"
''
echo 'builtins.add 123 456' > $out
'';
builder = builtins.toFile "builder.sh" ''
echo 'builtins.add 123 456' > $out
'';
};
value =
@ -16,19 +15,17 @@ rec {
result = mkDerivation {
name = "foo";
builder = builtins.toFile "builder.sh"
''
echo -n FOO${toString value} > $out
'';
builder = builtins.toFile "builder.sh" ''
echo -n FOO${toString value} > $out
'';
};
addPath = mkDerivation {
name = "add-path";
src = builtins.filterSource (path: type: true) result;
builder = builtins.toFile "builder.sh"
''
echo -n BLA$(cat $src) > $out
'';
builder = builtins.toFile "builder.sh" ''
echo -n BLA$(cat $src) > $out
'';
};
step1 = mkDerivation {

View file

@ -4,60 +4,58 @@ rec {
impure = mkDerivation {
name = "impure";
outputs = [ "out" "stuff" ];
buildCommand =
''
echo impure
x=$(< $TEST_ROOT/counter)
mkdir $out $stuff
echo $x > $out/n
ln -s $out/n $stuff/bla
printf $((x + 1)) > $TEST_ROOT/counter
'';
outputs = [
"out"
"stuff"
];
buildCommand = ''
echo impure
x=$(< $TEST_ROOT/counter)
mkdir $out $stuff
echo $x > $out/n
ln -s $out/n $stuff/bla
printf $((x + 1)) > $TEST_ROOT/counter
'';
__impure = true;
impureEnvVars = [ "TEST_ROOT" ];
};
impureOnImpure = mkDerivation {
name = "impure-on-impure";
buildCommand =
''
echo impure-on-impure
x=$(< ${impure}/n)
mkdir $out
printf X$x > $out/n
ln -s ${impure.stuff} $out/symlink
ln -s $out $out/self
'';
buildCommand = ''
echo impure-on-impure
x=$(< ${impure}/n)
mkdir $out
printf X$x > $out/n
ln -s ${impure.stuff} $out/symlink
ln -s $out $out/self
'';
__impure = true;
};
# This is not allowed.
inputAddressed = mkDerivation {
name = "input-addressed";
buildCommand =
''
cat ${impure} > $out
'';
buildCommand = ''
cat ${impure} > $out
'';
};
contentAddressed = mkDerivation {
name = "content-addressed";
buildCommand =
''
echo content-addressed
x=$(< ${impureOnImpure}/n)
printf ''${x:0:1} > $out
'';
buildCommand = ''
echo content-addressed
x=$(< ${impureOnImpure}/n)
printf ''${x:0:1} > $out
'';
outputHashMode = "recursive";
outputHash = "sha256-eBYxcgkuWuiqs4cKNgKwkb3vY/HR0vVsJnqe8itJGcQ=";
};
inputAddressedAfterCA = mkDerivation {
name = "input-addressed-after-ca";
buildCommand =
''
cat ${contentAddressed} > $out
'';
buildCommand = ''
cat ${contentAddressed} > $out
'';
};
}

View file

@ -1,4 +1,3 @@
# Run:
# GC_INITIAL_HEAP_SIZE=$[1024 * 1024] NIX_SHOW_STATS=1 nix eval -f gc-coroutine-test.nix -vvvv
@ -11,55 +10,56 @@ let
# Generate a tree of numbers, n deep, such that the numbers add up to (1 + salt) * 10^n.
# The salting makes the numbers all different, increasing the likelihood of catching
# any memory corruptions that might be caused by the GC or otherwise.
garbage = salt: n:
if n == 0
then [(1 + salt)]
else [
(garbage (10 * salt + 1) (n - 1))
(garbage (10 * salt - 1) (n - 1))
(garbage (10 * salt + 2) (n - 1))
(garbage (10 * salt - 2) (n - 1))
(garbage (10 * salt + 3) (n - 1))
(garbage (10 * salt - 3) (n - 1))
(garbage (10 * salt + 4) (n - 1))
(garbage (10 * salt - 4) (n - 1))
(garbage (10 * salt + 5) (n - 1))
(garbage (10 * salt - 5) (n - 1))
];
garbage =
salt: n:
if n == 0 then
[ (1 + salt) ]
else
[
(garbage (10 * salt + 1) (n - 1))
(garbage (10 * salt - 1) (n - 1))
(garbage (10 * salt + 2) (n - 1))
(garbage (10 * salt - 2) (n - 1))
(garbage (10 * salt + 3) (n - 1))
(garbage (10 * salt - 3) (n - 1))
(garbage (10 * salt + 4) (n - 1))
(garbage (10 * salt - 4) (n - 1))
(garbage (10 * salt + 5) (n - 1))
(garbage (10 * salt - 5) (n - 1))
];
pow = base: n:
if n == 0
then 1
else base * (pow base (n - 1));
pow = base: n: if n == 0 then 1 else base * (pow base (n - 1));
sumNestedLists = l:
if isList l
then foldl' (a: b: a + sumNestedLists b) 0 l
else l;
sumNestedLists = l: if isList l then foldl' (a: b: a + sumNestedLists b) 0 l else l;
in
assert sumNestedLists (garbage 0 3) == pow 10 3;
assert sumNestedLists (garbage 0 6) == pow 10 6;
builtins.foldl'
(a: b:
assert
"${
builtins.path {
path = ./src;
filter = path: type:
# We're not doing common subexpression elimination, so this reallocates
# the fairly big tree over and over, producing a lot of garbage during
# source filtering, whose filter runs in a coroutine.
assert sumNestedLists (garbage 0 3) == pow 10 3;
true;
}
}"
== "${./src}";
assert sumNestedLists (garbage 0 3) == pow 10 3;
assert sumNestedLists (garbage 0 6) == pow 10 6;
builtins.foldl'
(
a: b:
assert
"${builtins.path {
path = ./src;
filter =
path: type:
# We're not doing common subexpression elimination, so this reallocates
# the fairly big tree over and over, producing a lot of garbage during
# source filtering, whose filter runs in a coroutine.
assert sumNestedLists (garbage 0 3) == pow 10 3;
true;
}}" == "${./src}";
# These asserts don't seem necessary, as the lambda value get corrupted first
assert a.okay;
assert b.okay;
{ okay = true; }
)
# These asserts don't seem necessary, as the lambda value get corrupted first
assert a.okay;
assert b.okay;
{
okay = true;
}
)
{ okay = true; }
[
{ okay = true; }
[ { okay = true; } { okay = true; } { okay = true; } ]
{ okay = true; }
{ okay = true; }
]

View file

@ -3,16 +3,23 @@ let
name = "fail";
builder = "/bin/false";
system = "x86_64-linux";
outputs = [ "out" "foo" ];
outputs = [
"out"
"foo"
];
};
drv1 = derivation {
name = "fail-2";
builder = "/bin/false";
system = "x86_64-linux";
outputs = [ "out" "foo" ];
outputs = [
"out"
"foo"
];
};
combo-path = "${drv0.drvPath}${drv1.drvPath}";
in builtins.addDrvOutputDependencies combo-path
in
builtins.addDrvOutputDependencies combo-path

View file

@ -3,7 +3,11 @@ let
name = "fail";
builder = "/bin/false";
system = "x86_64-linux";
outputs = [ "out" "foo" ];
outputs = [
"out"
"foo"
];
};
in builtins.addDrvOutputDependencies drv.outPath
in
builtins.addDrvOutputDependencies drv.outPath

View file

@ -1,9 +1,9 @@
let
countDown = n:
if n == 0
then throw "kaboom"
countDown =
n:
if n == 0 then
throw "kaboom"
else
builtins.addErrorContext
"while counting down; n = ${toString n}"
("x" + countDown (n - 1));
in countDown 10
builtins.addErrorContext "while counting down; n = ${toString n}" ("x" + countDown (n - 1));
in
countDown 10

View file

@ -1,2 +1,8 @@
assert { a = true; } == { a = true; b = true; };
assert
{
a = true;
} == {
a = true;
b = true;
};
throw "unreachable"

View file

@ -1,2 +1,8 @@
assert { a = true; b = true; } == { a = true; };
assert
{
a = true;
b = true;
} == {
a = true;
};
throw "unreachable"

View file

@ -1,5 +1,14 @@
assert
{ foo = { type = "derivation"; outPath = "/nix/store/0"; }; }
==
{ foo = { type = "derivation"; outPath = "/nix/store/1"; devious = true; }; };
throw "unreachable"
{
foo = {
type = "derivation";
outPath = "/nix/store/0";
};
} == {
foo = {
type = "derivation";
outPath = "/nix/store/1";
devious = true;
};
};
throw "unreachable"

View file

@ -1,5 +1,15 @@
assert
{ foo = { type = "derivation"; outPath = "/nix/store/0"; ignored = abort "not ignored"; }; }
==
{ foo = { type = "derivation"; outPath = "/nix/store/1"; ignored = abort "not ignored"; }; };
throw "unreachable"
{
foo = {
type = "derivation";
outPath = "/nix/store/0";
ignored = abort "not ignored";
};
} == {
foo = {
type = "derivation";
outPath = "/nix/store/1";
ignored = abort "not ignored";
};
};
throw "unreachable"

View file

@ -1,7 +1,4 @@
# Note: functions in nested structures, e.g. attributes, may be optimized away by pointer identity optimization.
# This only compares a direct comparison and makes no claims about functions in nested structures.
assert
(x: x)
==
(x: x);
abort "unreachable"
assert (x: x) == (x: x);
abort "unreachable"

View file

@ -1,2 +1,6 @@
assert [ 1 0 ] == [ 10 ];
throw "unreachable"
assert
[
1
0
] == [ 10 ];
throw "unreachable"

View file

@ -1,2 +1,2 @@
assert ./foo == ./bar;
throw "unreachable"
throw "unreachable"

View file

@ -1,6 +1,3 @@
assert
{ a.b = [ { c.d = true; } ]; }
==
{ a.b = [ { c.d = false; } ]; };
assert { a.b = [ { c.d = true; } ]; } == { a.b = [ { c.d = false; } ]; };
abort "unreachable"
abort "unreachable"

View file

@ -1,5 +1,8 @@
let {
x = arg: assert arg == "y"; 123;
x =
arg:
assert arg == "y";
123;
body = x "x";
}
}

View file

@ -1,7 +1,7 @@
let
attrs = {
puppy.doggy = {};
puppy.doggy = { };
};
key = 1;
in
attrs.puppy.${key}
attrs.puppy.${key}

View file

@ -1 +1,8 @@
{ a.b = 1; a = rec { c = d + 2; d = 3; }; }.c
{
a.b = 1;
a = rec {
c = d + 2;
d = 3;
};
}
.c

View file

@ -1,6 +1,16 @@
let
# Basically a "billion laughs" attack, but toned down to simulated `pkgs`.
ha = x: y: { a = x y; b = x y; c = x y; d = x y; e = x y; f = x y; g = x y; h = x y; j = x y; };
ha = x: y: {
a = x y;
b = x y;
c = x y;
d = x y;
e = x y;
f = x y;
g = x y;
h = x y;
j = x y;
};
has = ha (ha (ha (ha (x: x)))) "ha";
# A large structure that has already been evaluated.
pkgs = builtins.deepSeq has has;

View file

@ -1,4 +1,8 @@
{
set = { "${"" + "b"}" = 1; };
set = { "${"b" + ""}" = 2; };
set = {
"${"" + "b"}" = 1;
};
set = {
"${"b" + ""}" = 2;
};
}

View file

@ -1,9 +1,6 @@
# Check that we only omit duplicate stack traces when there's a bunch of them.
# Here, there's only a couple duplicate entries, so we output them all.
let
throwAfter = n:
if n > 0
then throwAfter (n - 1)
else throw "Uh oh!";
throwAfter = n: if n > 0 then throwAfter (n - 1) else throw "Uh oh!";
in
throwAfter 2
throwAfter 2

View file

@ -1 +1,4 @@
builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; }
builtins.fetchurl {
url = "https://example.com/foo.tar.gz";
name = "~wobble~";
}

View file

@ -1,7 +1,12 @@
let n = -1; in builtins.seq n (builtins.flakeRefToString {
type = "github";
owner = "NixOS";
repo = n;
ref = "23.05";
dir = "lib";
})
let
n = -1;
in
builtins.seq n (
builtins.flakeRefToString {
type = "github";
owner = "NixOS";
repo = n;
ref = "23.05";
dir = "lib";
}
)

View file

@ -1,5 +1,5 @@
# Tests that the result of applying op is forced even if the value is never used
builtins.foldl'
(_: f: f null)
null
[ (_: throw "Not the final value, but is still forced!") (_: 23) ]
builtins.foldl' (_: f: f null) null [
(_: throw "Not the final value, but is still forced!")
(_: 23)
]

View file

@ -1,5 +1,16 @@
let
paths = [ ./this-file-is-definitely-not-there-7392097 "/and/neither/is/this/37293620" ];
paths = [
./this-file-is-definitely-not-there-7392097
"/and/neither/is/this/37293620"
];
in
toString (builtins.concatLists (map (hash: map (builtins.hashFile hash) paths) ["md5" "sha1" "sha256" "sha512"]))
toString (
builtins.concatLists (
map (hash: map (builtins.hashFile hash) paths) [
"md5"
"sha1"
"sha256"
"sha512"
]
)
)

View file

@ -1 +1 @@
8++1
8 ++ 1

View file

@ -1 +1,12 @@
({x, y, z}: x + y + z) {x = "foo"; z = "bar";}
(
{
x,
y,
z,
}:
x + y + z
)
{
x = "foo";
z = "bar";
}

View file

@ -19,18 +19,22 @@
# - a few frames of A (skip the rest)
# - a few frames of B (skip the rest, _and_ skip the remaining frames of A)
let
throwAfterB = recurse: n:
if n > 0
then throwAfterB recurse (n - 1)
else if recurse
then throwAfterA false 10
else throw "Uh oh!";
throwAfterB =
recurse: n:
if n > 0 then
throwAfterB recurse (n - 1)
else if recurse then
throwAfterA false 10
else
throw "Uh oh!";
throwAfterA = recurse: n:
if n > 0
then throwAfterA recurse (n - 1)
else if recurse
then throwAfterB true 10
else throw "Uh oh!";
throwAfterA =
recurse: n:
if n > 0 then
throwAfterA recurse (n - 1)
else if recurse then
throwAfterB true 10
else
throw "Uh oh!";
in
throwAfterA true 10
throwAfterA true 10

View file

@ -8,4 +8,27 @@
#
# error: cannot coerce a list to a string: [ [ 1 2 3 4 5 6 7 8 ] [ 1 «4294967290 items elided» ] ]
"" + (let v = [ [ 1 2 3 4 5 6 7 8 ] [1 2 3 4]]; in builtins.deepSeq v v)
""
+ (
let
v = [
[
1
2
3
4
5
6
7
8
]
[
1
2
3
4
]
];
in
builtins.deepSeq v v
)

View file

@ -1 +1 @@
! (throw "uh oh!")
!(throw "uh oh!")

View file

@ -1,4 +1,5 @@
let
a = 9223372036854775807;
b = 1;
in a + b
in
a + b

View file

@ -4,4 +4,5 @@ let
# of range
intMin = -9223372036854775807 - 1;
b = -1;
in builtins.seq intMin (builtins.seq b (intMin / b))
in
builtins.seq intMin (builtins.seq b (intMin / b))

View file

@ -1,3 +1,4 @@
let
a = 4294967297;
in a * a * a
in
a * a * a

View file

@ -1,4 +1,5 @@
let
a = -9223372036854775807;
b = 2;
in a - b
in
a - b

View file

@ -1 +1,4 @@
let a = {} // a; in a.foo
let
a = { } // a;
in
a.foo

View file

@ -1,5 +1,8 @@
let {
attrs = {x = 123; y = 456;};
attrs = {
x = 123;
y = 456;
};
body = (removeAttrs attrs ["x"]).x;
}
body = (removeAttrs attrs [ "x" ]).x;
}

View file

@ -3,8 +3,13 @@ let {
x = "a";
y = "b";
f = {x ? y, y ? x}: x + y;
f =
{
x ? y,
y ? x,
}:
x + y;
body = f {};
body = f { };
}

View file

@ -1 +1,5 @@
({x, z}: x + z) {x = "foo"; y = "bla"; z = "bar";}
({ x, z }: x + z) {
x = "foo";
y = "bla";
z = "bar";
}

View file

@ -1,5 +1,7 @@
let
attr = {foo = "bar";};
key = {};
attr = {
foo = "bar";
};
key = { };
in
attr.${key}
attr.${key}

View file

@ -1,11 +1,34 @@
with builtins;
[ (any (x: x == 1) [])
(any (x: x == 1) [2 3 4])
(any (x: x == 1) [1 2 3 4])
(any (x: x == 1) [4 3 2 1])
(all (x: x == 1) [])
(all (x: x == 1) [1])
(all (x: x == 1) [1 2 3])
(all (x: x == 1) [1 1 1])
[
(any (x: x == 1) [ ])
(any (x: x == 1) [
2
3
4
])
(any (x: x == 1) [
1
2
3
4
])
(any (x: x == 1) [
4
3
2
1
])
(all (x: x == 1) [ ])
(all (x: x == 1) [ 1 ])
(all (x: x == 1) [
1
2
3
])
(all (x: x == 1) [
1
1
1
])
]

View file

@ -2,58 +2,59 @@ with import ./lib.nix;
let {
/* Supposedly tail recursive version:
/*
Supposedly tail recursive version:
range_ = accum: first: last:
if first == last then ([first] ++ accum)
else range_ ([first] ++ accum) (builtins.add first 1) last;
range_ = accum: first: last:
if first == last then ([first] ++ accum)
else range_ ([first] ++ accum) (builtins.add first 1) last;
range = range_ [];
range = range_ [];
*/
x = 12;
err = abort "urgh";
body = sum
[ (sum (range 1 50))
(123 + 456)
(0 + -10 + -(-11) + -x)
(10 - 7 - -2)
(10 - (6 - -1))
(10 - 1 + 2)
(3 * 4 * 5)
(56088 / 123 / 2)
(3 + 4 * const 5 0 - 6 / id 2)
body = sum [
(sum (range 1 50))
(123 + 456)
(0 + -10 + -(-11) + -x)
(10 - 7 - -2)
(10 - (6 - -1))
(10 - 1 + 2)
(3 * 4 * 5)
(56088 / 123 / 2)
(3 + 4 * const 5 0 - 6 / id 2)
(builtins.bitAnd 12 10) # 0b1100 & 0b1010 = 8
(builtins.bitOr 12 10) # 0b1100 | 0b1010 = 14
(builtins.bitXor 12 10) # 0b1100 ^ 0b1010 = 6
(builtins.bitAnd 12 10) # 0b1100 & 0b1010 = 8
(builtins.bitOr 12 10) # 0b1100 | 0b1010 = 14
(builtins.bitXor 12 10) # 0b1100 ^ 0b1010 = 6
(if 3 < 7 then 1 else err)
(if 7 < 3 then err else 1)
(if 3 < 3 then err else 1)
(if 3 < 7 then 1 else err)
(if 7 < 3 then err else 1)
(if 3 < 3 then err else 1)
(if 3 <= 7 then 1 else err)
(if 7 <= 3 then err else 1)
(if 3 <= 3 then 1 else err)
(if 3 <= 7 then 1 else err)
(if 7 <= 3 then err else 1)
(if 3 <= 3 then 1 else err)
(if 3 > 7 then err else 1)
(if 7 > 3 then 1 else err)
(if 3 > 3 then err else 1)
(if 3 > 7 then err else 1)
(if 7 > 3 then 1 else err)
(if 3 > 3 then err else 1)
(if 3 >= 7 then err else 1)
(if 7 >= 3 then 1 else err)
(if 3 >= 3 then 1 else err)
(if 3 >= 7 then err else 1)
(if 7 >= 3 then 1 else err)
(if 3 >= 3 then 1 else err)
(if 2 > 1 == 1 < 2 then 1 else err)
(if 1 + 2 * 3 >= 7 then 1 else err)
(if 1 + 2 * 3 < 7 then err else 1)
(if 2 > 1 == 1 < 2 then 1 else err)
(if 1 + 2 * 3 >= 7 then 1 else err)
(if 1 + 2 * 3 < 7 then err else 1)
# Not integer, but so what.
(if "aa" < "ab" then 1 else err)
(if "aa" < "aa" then err else 1)
(if "foo" < "foobar" then 1 else err)
];
# Not integer, but so what.
(if "aa" < "ab" then 1 else err)
(if "aa" < "aa" then err else 1)
(if "foo" < "foobar" then 1 else err)
];
}

View file

@ -2,10 +2,21 @@ with import ./lib.nix;
let
attrs = {y = "y"; x = "x"; foo = "foo";} // rec {x = "newx"; bar = x;};
attrs =
{
y = "y";
x = "x";
foo = "foo";
}
// rec {
x = "newx";
bar = x;
};
names = builtins.attrNames attrs;
values = map (name: builtins.getAttr name attrs) names;
in assert values == builtins.attrValues attrs; concat values
in
assert values == builtins.attrValues attrs;
concat values

View file

@ -1,5 +1,20 @@
let {
as = { x = 123; y = 456; } // { z = 789; } // { z = 987; };
as =
{
x = 123;
y = 456;
}
// {
z = 789;
}
// {
z = 987;
};
body = if as ? a then as.a else assert as ? z; as.z;
body =
if as ? a then
as.a
else
assert as ? z;
as.z;
}

View file

@ -1,10 +1,23 @@
let {
as = { x = 123; y = 456; } // { z = 789; } // { z = 987; };
as =
{
x = 123;
y = 456;
}
// {
z = 789;
}
// {
z = 987;
};
A = "a";
Z = "z";
body = if builtins.hasAttr A as
then builtins.getAttr A as
else assert builtins.hasAttr Z as; builtins.getAttr Z as;
body =
if builtins.hasAttr A as then
builtins.getAttr A as
else
assert builtins.hasAttr Z as;
builtins.getAttr Z as;
}

View file

@ -1,22 +1,22 @@
let
config =
{
services.sshd.enable = true;
services.sshd.port = 22;
services.httpd.port = 80;
hostName = "itchy";
a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z = "x";
foo = {
a = "a";
b.c = "c";
};
config = {
services.sshd.enable = true;
services.sshd.port = 22;
services.httpd.port = 80;
hostName = "itchy";
a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z = "x";
foo = {
a = "a";
b.c = "c";
};
};
in
if config.services.sshd.enable
then "foo ${toString config.services.sshd.port} ${toString config.services.httpd.port} ${config.hostName}"
+ "${config.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z}"
+ "${config.foo.a}"
+ "${config.foo.b.c}"
else "bar"
if config.services.sshd.enable then
"foo ${toString config.services.sshd.port} ${toString config.services.httpd.port} ${config.hostName}"
+ "${config.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z}"
+ "${config.foo.a}"
+ "${config.foo.b.c}"
else
"bar"

View file

@ -1,7 +1,20 @@
let
as = { x.y.z = 123; a.b.c = 456; };
as = {
x.y.z = 123;
a.b.c = 456;
};
bs = null;
in [ (as ? x) (as ? y) (as ? x.y.z) (as ? x.y.z.a) (as ? x.y.a) (as ? a.b.c) (bs ? x) (bs ? x.y.z) ]
in
[
(as ? x)
(as ? y)
(as ? x.y.z)
(as ? x.y.z.a)
(as ? x.y.a)
(as ? a.b.c)
(bs ? x)
(bs ? x.y.z)
]

View file

@ -1,4 +1,6 @@
rec {
"${"foo"}" = "bar";
__overrides = { bar = "qux"; };
__overrides = {
bar = "qux";
};
}

View file

@ -4,12 +4,17 @@ let
in
{ xyzzy2 ? xyzzy # mutually recursive args
, xyzzy ? "blaat" # will be overridden by --argstr
, fb ? foobar
, lib # will be set by --arg
{
xyzzy2 ? xyzzy, # mutually recursive args
xyzzy ? "blaat", # will be overridden by --argstr
fb ? foobar,
lib, # will be set by --arg
}:
{
result = lib.concat [xyzzy xyzzy2 fb];
result = lib.concat [
xyzzy
xyzzy2
fb
];
}

View file

@ -1,8 +1,8 @@
[
(builtins.add 2 3)
(builtins.add 2 2)
(builtins.typeOf (builtins.add 2 2))
("t" + "t")
(builtins.typeOf (builtins.add 2.0 2))
(builtins.add 2.0 2)
(builtins.add 2 3)
(builtins.add 2 2)
(builtins.typeOf (builtins.add 2 2))
("t" + "t")
(builtins.typeOf (builtins.add 2.0 2))
(builtins.add 2.0 2)
]

View file

@ -8,5 +8,5 @@ let {
y = if builtins ? fnord then builtins.fnord "foo" else "";
body = x + y;
}

View file

@ -1 +1,10 @@
({ __functor = self: x: self.foo && x; foo = false; } // { foo = true; }) true
(
{
__functor = self: x: self.foo && x;
foo = false;
}
// {
foo = true;
}
)
true

View file

@ -1 +1,5 @@
builtins.catAttrs "a" [ { a = 1; } { b = 0; } { a = 2; } ]
builtins.catAttrs "a" [
{ a = 1; }
{ b = 0; }
{ a = 2; }
]

View file

@ -1,13 +1,25 @@
let
closure = builtins.genericClosure {
startSet = [{key = 80;}];
operator = {key, foo ? false}:
if builtins.lessThan key 0
then []
else [{key = builtins.sub key 9;} {key = builtins.sub key 13; foo = true;}];
startSet = [ { key = 80; } ];
operator =
{
key,
foo ? false,
}:
if builtins.lessThan key 0 then
[ ]
else
[
{ key = builtins.sub key 9; }
{
key = builtins.sub key 13;
foo = true;
}
];
};
sort = (import ./lib.nix).sortBy (a: b: builtins.lessThan a.key b.key);
in sort closure
in
sort closure

View file

@ -1 +1,15 @@
[1 2 3] ++ [4 5 6] ++ [7 8 9]
[
1
2
3
]
++ [
4
5
6
]
++ [
7
8
9
]

View file

@ -1,5 +1,9 @@
with import ./lib.nix;
[ (builtins.concatMap (x: if x / 2 * 2 == x then [] else [ x ]) (range 0 10))
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])
[
(builtins.concatMap (x: if x / 2 * 2 == x then [ ] else [ x ]) (range 0 10))
(builtins.concatMap (x: [ x ] ++ [ "z" ]) [
"a"
"b"
])
]

View file

@ -1,8 +1,17 @@
with builtins;
[ (concatStringsSep "" [])
(concatStringsSep "" ["foo" "bar" "xyzzy"])
(concatStringsSep ", " ["foo" "bar" "xyzzy"])
(concatStringsSep ", " ["foo"])
(concatStringsSep ", " [])
[
(concatStringsSep "" [ ])
(concatStringsSep "" [
"foo"
"bar"
"xyzzy"
])
(concatStringsSep ", " [
"foo"
"bar"
"xyzzy"
])
(concatStringsSep ", " [ "foo" ])
(concatStringsSep ", " [ ])
]

View file

@ -3,7 +3,10 @@ let
name = "fail";
builder = "/bin/false";
system = "x86_64-linux";
outputs = [ "out" "foo" ];
outputs = [
"out"
"foo"
];
};
path = "${./eval-okay-context-introspection.nix}";
@ -13,7 +16,10 @@ let
path = true;
};
"${builtins.unsafeDiscardStringContext drv.drvPath}" = {
outputs = [ "foo" "out" ];
outputs = [
"foo"
"out"
];
allOutputs = true;
};
};
@ -21,25 +27,22 @@ let
combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
legit-context = builtins.getContext combo-path;
reconstructed-path = builtins.appendContext
(builtins.unsafeDiscardStringContext combo-path)
desired-context;
reconstructed-path = builtins.appendContext (builtins.unsafeDiscardStringContext combo-path) desired-context;
# Eta rule for strings with context.
etaRule = str:
str == builtins.appendContext
(builtins.unsafeDiscardStringContext str)
(builtins.getContext str);
etaRule =
str:
str == builtins.appendContext (builtins.unsafeDiscardStringContext str) (builtins.getContext str);
# Only holds true if string context contains both a `DrvDeep` and
# `Opaque` element.
almostEtaRule = str:
str == builtins.addDrvOutputDependencies
(builtins.unsafeDiscardOutputDependency str);
almostEtaRule =
str: str == builtins.addDrvOutputDependencies (builtins.unsafeDiscardOutputDependency str);
addDrvOutputDependencies_idempotent = str:
builtins.addDrvOutputDependencies str ==
builtins.addDrvOutputDependencies (builtins.addDrvOutputDependencies str);
addDrvOutputDependencies_idempotent =
str:
builtins.addDrvOutputDependencies str
== builtins.addDrvOutputDependencies (builtins.addDrvOutputDependencies str);
rules = str: [
(etaRule str)
@ -47,12 +50,14 @@ let
(addDrvOutputDependencies_idempotent str)
];
in [
in
[
(legit-context == desired-context)
(reconstructed-path == combo-path)
(etaRule "foo")
(etaRule drv.foo.outPath)
] ++ builtins.concatMap rules [
]
++ builtins.concatMap rules [
drv.drvPath
(builtins.addDrvOutputDependencies drv.drvPath)
(builtins.unsafeDiscardOutputDependency drv.drvPath)

View file

@ -1,6 +1,7 @@
let s = "foo ${builtins.substring 33 100 (baseNameOf "${./eval-okay-context.nix}")} bar";
let
s = "foo ${builtins.substring 33 100 (baseNameOf "${./eval-okay-context.nix}")} bar";
in
if s != "foo eval-okay-context.nix bar"
then abort "context not discarded"
else builtins.unsafeDiscardStringContext s
if s != "foo eval-okay-context.nix bar" then
abort "context not discarded"
else
builtins.unsafeDiscardStringContext s

View file

@ -1,33 +1,131 @@
let
hashAlgos = [ "md5" "md5" "md5" "sha1" "sha1" "sha1" "sha256" "sha256" "sha256" "sha512" "sha512" "sha512" ];
hashAlgos = [
"md5"
"md5"
"md5"
"sha1"
"sha1"
"sha1"
"sha256"
"sha256"
"sha256"
"sha512"
"sha512"
"sha512"
];
hashesBase16 = import ./eval-okay-hashstring.exp;
map2 = f: { fsts, snds }: if fsts == [ ] then [ ] else [ (f (builtins.head fsts) (builtins.head snds)) ] ++ map2 f { fsts = builtins.tail fsts; snds = builtins.tail snds; };
map2' = f: fsts: snds: map2 f { inherit fsts snds; };
map2 =
f:
{ fsts, snds }:
if fsts == [ ] then
[ ]
else
[ (f (builtins.head fsts) (builtins.head snds)) ]
++ map2 f {
fsts = builtins.tail fsts;
snds = builtins.tail snds;
};
map2' =
f: fsts: snds:
map2 f { inherit fsts snds; };
getOutputHashes = hashes: {
hashesBase16 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base16";}) hashAlgos hashes;
hashesNix32 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "nix32";}) hashAlgos hashes;
hashesBase32 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base32";}) hashAlgos hashes;
hashesBase64 = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "base64";}) hashAlgos hashes;
hashesSRI = map2' (hashAlgo: hash: builtins.convertHash { inherit hash hashAlgo; toHashFormat = "sri" ;}) hashAlgos hashes;
hashesBase16 = map2' (
hashAlgo: hash:
builtins.convertHash {
inherit hash hashAlgo;
toHashFormat = "base16";
}
) hashAlgos hashes;
hashesNix32 = map2' (
hashAlgo: hash:
builtins.convertHash {
inherit hash hashAlgo;
toHashFormat = "nix32";
}
) hashAlgos hashes;
hashesBase32 = map2' (
hashAlgo: hash:
builtins.convertHash {
inherit hash hashAlgo;
toHashFormat = "base32";
}
) hashAlgos hashes;
hashesBase64 = map2' (
hashAlgo: hash:
builtins.convertHash {
inherit hash hashAlgo;
toHashFormat = "base64";
}
) hashAlgos hashes;
hashesSRI = map2' (
hashAlgo: hash:
builtins.convertHash {
inherit hash hashAlgo;
toHashFormat = "sri";
}
) hashAlgos hashes;
};
getOutputHashesColon = hashes: {
hashesBase16 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base16";}) hashAlgos hashes;
hashesNix32 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "nix32";}) hashAlgos hashes;
hashesBase32 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base32";}) hashAlgos hashes;
hashesBase64 = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "base64";}) hashAlgos hashes;
hashesSRI = map2' (hashAlgo: hashBody: builtins.convertHash { hash = hashAlgo + ":" + hashBody; toHashFormat = "sri" ;}) hashAlgos hashes;
hashesBase16 = map2' (
hashAlgo: hashBody:
builtins.convertHash {
hash = hashAlgo + ":" + hashBody;
toHashFormat = "base16";
}
) hashAlgos hashes;
hashesNix32 = map2' (
hashAlgo: hashBody:
builtins.convertHash {
hash = hashAlgo + ":" + hashBody;
toHashFormat = "nix32";
}
) hashAlgos hashes;
hashesBase32 = map2' (
hashAlgo: hashBody:
builtins.convertHash {
hash = hashAlgo + ":" + hashBody;
toHashFormat = "base32";
}
) hashAlgos hashes;
hashesBase64 = map2' (
hashAlgo: hashBody:
builtins.convertHash {
hash = hashAlgo + ":" + hashBody;
toHashFormat = "base64";
}
) hashAlgos hashes;
hashesSRI = map2' (
hashAlgo: hashBody:
builtins.convertHash {
hash = hashAlgo + ":" + hashBody;
toHashFormat = "sri";
}
) hashAlgos hashes;
};
outputHashes = getOutputHashes hashesBase16;
in
# map2'`
assert map2' (s1: s2: s1 + s2) [ "a" "b" ] [ "c" "d" ] == [ "ac" "bd" ];
assert
map2' (s1: s2: s1 + s2) [ "a" "b" ] [ "c" "d" ] == [
"ac"
"bd"
];
# hashesBase16
assert outputHashes.hashesBase16 == hashesBase16;
# standard SRI hashes
assert outputHashes.hashesSRI == (map2' (hashAlgo: hashBody: hashAlgo + "-" + hashBody) hashAlgos outputHashes.hashesBase64);
assert
outputHashes.hashesSRI
== (map2' (hashAlgo: hashBody: hashAlgo + "-" + hashBody) hashAlgos outputHashes.hashesBase64);
# without prefix
assert builtins.all (x: getOutputHashes x == outputHashes) (builtins.attrValues outputHashes);
# colon-separated.
# Note that colon prefix must not be applied to the standard SRI. e.g. "sha256:sha256-..." is illegal.
assert builtins.all (x: getOutputHashesColon x == outputHashes) (with outputHashes; [ hashesBase16 hashesBase32 hashesBase64 ]);
assert builtins.all (x: getOutputHashesColon x == outputHashes) (
with outputHashes;
[
hashesBase16
hashesBase32
hashesBase64
]
);
outputHashes

View file

@ -1 +1,9 @@
builtins.deepSeq (let as = { x = 123; y = as; }; in as) 456
builtins.deepSeq (
let
as = {
x = 123;
y = as;
};
in
as
) 456

View file

@ -4,7 +4,10 @@ let
name = "a";
system = builtins.currentSystem;
builder = "/bin/sh";
args = [ "-c" "touch $out" ];
args = [
"-c"
"touch $out"
];
inherit b;
};
@ -16,9 +19,13 @@ let
name = "b-overridden";
system = builtins.currentSystem;
builder = "/bin/sh";
args = [ "-c" "touch $out" ];
args = [
"-c"
"touch $out"
];
};
};
pkgs = pkgs_ // (packageOverrides pkgs_);
in pkgs.a.b.name
in
pkgs.a.b.name

View file

@ -5,7 +5,10 @@ let
name = "a";
system = builtins.currentSystem;
builder = "/bin/sh";
args = [ "-c" "touch $out" ];
args = [
"-c"
"touch $out"
];
inherit b;
};
@ -13,17 +16,22 @@ let
name = "b";
system = builtins.currentSystem;
builder = "/bin/sh";
args = [ "-c" "touch $out" ];
args = [
"-c"
"touch $out"
];
inherit a;
};
c = b;
};
packageOverrides = pkgs: with pkgs; {
b = derivation (b.drvAttrs // { name = "${b.name}-overridden"; });
};
packageOverrides =
pkgs: with pkgs; {
b = derivation (b.drvAttrs // { name = "${b.name}-overridden"; });
};
pkgs = pkgs_ // (packageOverrides pkgs_);
in "${pkgs.a.b.name} ${pkgs.c.name} ${pkgs.b.a.name}"
in
"${pkgs.a.b.name} ${pkgs.c.name} ${pkgs.b.a.name}"

View file

@ -1 +1,5 @@
{ a."${"b"}" = true; a."${"c"}" = false; }.a.b
{
a."${"b"}" = true;
a."${"c"}" = false;
}
.a.b

View file

@ -2,7 +2,8 @@ let
aString = "a";
bString = "b";
in {
in
{
hasAttrs = { a.b = null; } ? ${aString}.b;
selectAttrs = { a.b = true; }.a.${bString};
@ -11,7 +12,17 @@ in {
binds = { ${aString}."${bString}c" = true; }.a.bc;
recBinds = rec { ${bString} = a; a = true; }.b;
recBinds =
rec {
${bString} = a;
a = true;
}
.b;
multiAttrs = { ${aString} = true; ${bString} = false; }.a;
multiAttrs =
{
${aString} = true;
${bString} = false;
}
.a;
}

View file

@ -2,7 +2,8 @@ let
aString = "a";
bString = "b";
in {
in
{
hasAttrs = { a.b = null; } ? "${aString}".b;
selectAttrs = { a.b = true; }.a."${bString}";
@ -11,7 +12,17 @@ in {
binds = { "${aString}"."${bString}c" = true; }.a.bc;
recBinds = rec { "${bString}" = a; a = true; }.b;
recBinds =
rec {
"${bString}" = a;
a = true;
}
.b;
multiAttrs = { "${aString}" = true; "${bString}" = false; }.a;
multiAttrs =
{
"${aString}" = true;
"${bString}" = false;
}
.a;
}

View file

@ -1,6 +1,11 @@
with import ./lib.nix;
let xs = range 10 40; in
[ (builtins.elem 23 xs) (builtins.elem 42 xs) (builtins.elemAt xs 20) ]
let
xs = range 10 40;
in
[
(builtins.elem 23 xs)
(builtins.elem 42 xs)
(builtins.elemAt xs 20)
]

View file

@ -1 +1,4 @@
({}: {x,y,}: "${x}${y}") {} {x = "a"; y = "b";}
({ }: { x, y }: "${x}${y}") { } {
x = "a";
y = "b";
}

View file

@ -1,10 +1,40 @@
let
drvA1 = derivation { name = "a"; builder = "/foo"; system = "i686-linux"; };
drvA2 = derivation { name = "a"; builder = "/foo"; system = "i686-linux"; };
drvA3 = derivation { name = "a"; builder = "/foo"; system = "i686-linux"; } // { dummy = 1; };
drvC1 = derivation { name = "c"; builder = "/foo"; system = "i686-linux"; };
drvC2 = derivation { name = "c"; builder = "/bar"; system = "i686-linux"; };
drvA1 = derivation {
name = "a";
builder = "/foo";
system = "i686-linux";
};
drvA2 = derivation {
name = "a";
builder = "/foo";
system = "i686-linux";
};
drvA3 =
derivation {
name = "a";
builder = "/foo";
system = "i686-linux";
}
// {
dummy = 1;
};
in [ (drvA1 == drvA1) (drvA1 == drvA2) (drvA1 == drvA3) (drvC1 == drvC2) ]
drvC1 = derivation {
name = "c";
builder = "/foo";
system = "i686-linux";
};
drvC2 = derivation {
name = "c";
builder = "/bar";
system = "i686-linux";
};
in
[
(drvA1 == drvA1)
(drvA1 == drvA2)
(drvA1 == drvA3)
(drvC1 == drvC2)
]

View file

@ -1,3 +1,13 @@
["foobar" (rec {x = 1; y = x;})]
==
[("foo" + "bar") ({x = 1; y = 1;})]
[
"foobar"
(rec {
x = 1;
y = x;
})
] == [
("foo" + "bar")
({
x = 1;
y = 1;
})
]

View file

@ -1,5 +1,8 @@
with import ./lib.nix;
builtins.filter
(x: x / 2 * 2 == x)
(builtins.concatLists [ (range 0 10) (range 100 110) ])
builtins.filter (x: x / 2 * 2 == x) (
builtins.concatLists [
(range 0 10)
(range 100 110)
]
)

View file

@ -1,7 +1,7 @@
builtins.flakeRefToString {
type = "github";
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "23.05";
dir = "lib";
repo = "nixpkgs";
ref = "23.05";
dir = "lib";
}

View file

@ -2,7 +2,19 @@ with import ./lib.nix;
let {
l = ["1" "2" ["3" ["4"] ["5" "6"]] "7"];
l = [
"1"
"2"
[
"3"
[ "4" ]
[
"5"
"6"
]
]
"7"
];
body = concat (flatten l);
}

View file

@ -6,4 +6,11 @@ let
n3 = builtins.floor 23;
n4 = builtins.ceil 23;
in
builtins.concatStringsSep ";" (map toString [ n1 n2 n3 n4 ])
builtins.concatStringsSep ";" (
map toString [
n1
n2
n3
n4
]
)

View file

@ -1,9 +1,6 @@
# Tests that the rhs argument of op is not forced unconditionally
let
lst = builtins.foldl'
(acc: x: acc ++ [ x ])
[ ]
[ 42 (throw "this shouldn't be evaluated") ];
lst = builtins.foldl' (acc: x: acc ++ [ x ]) [ ] [ 42 (throw "this shouldn't be evaluated") ];
in
builtins.head lst

View file

@ -1,6 +1,6 @@
# Checks that the nul value for the accumulator is not forced unconditionally.
# Some languages provide a foldl' that is strict in this argument, but Nix does not.
builtins.foldl'
(_: x: x)
(throw "This is never forced")
[ "but the results of applying op are" 42 ]
builtins.foldl' (_: x: x) (throw "This is never forced") [
"but the results of applying op are"
42
]

Some files were not shown because too many files have changed in this diff Show more