fix(depotfmt): only exclude *imported* tvix tests

When we added the Nix language test suite in cl/6126, we excluded the
whole tvix tests folder from Nix formatting. This is unintentional, as
we probably want *our* tests to be formatted correctly.

Change-Id: I2b66d79e30fae17e75d5a1f8c44e279886091c5f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11154
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2024-03-15 16:42:37 +03:00 committed by clbot
parent d5b6704d3d
commit d3534ee051
91 changed files with 412 additions and 272 deletions

View file

@ -23,7 +23,7 @@ let
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
includes = [ "*.nix" ]
excludes = [
"tvix/eval/src/tests/*",
"tvix/eval/src/tests/nix_tests/*",
]
[formatter.rust]

View file

@ -1 +1 @@
builtins.genList (_: {}.foo) 1
builtins.genList (_: { }.foo) 1

View file

@ -1 +1 @@
({x}: x) {x = 1; y = 2;}
({ x }: x) { x = 1; y = 2; }

View file

@ -2,4 +2,4 @@ let
x = throw "I have been forced";
in
x == x
x == x

View file

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

View file

@ -2,7 +2,8 @@ let
# There is no syntax for accessing this identifier in an ordinary
# way.
"foo bar" = 42;
in ({
in
({
# but we *can* inherit it back out
inherit "foo bar";
})."foo bar"

View file

@ -3,5 +3,5 @@ let
in
# The function application here will become a thunk which verifies that
# assert forces the condition expression correctly.
# assert forces the condition expression correctly.
assert condition 21 42; 21

View file

@ -1,2 +1,2 @@
# the 'from' part of an `inherit` can be any expression.
{ inherit ({a = 15;}) a; }.a
{ inherit ({ a = 15; }) a; }.a

View file

@ -1 +1 @@
{} // { a = "ok"; }
{ } // { a = "ok"; }

View file

@ -1 +1 @@
{ a = "ok"; } // {}
{ a = "ok"; } // { }

View file

@ -1 +1 @@
(builtins.tryEval ( builtins.baseNameOf (throw "jill") )).success
(builtins.tryEval (builtins.baseNameOf (throw "jill"))).success

View file

@ -1,5 +1,5 @@
[
(builtins.attrNames {})
(builtins.attrNames { })
(builtins.attrNames { foo = 1; bar = 2; baz = 3; })
(builtins.attrNames { Foo = 1; bar = 2; Baz = 3; })
(builtins.attrNames {

View file

@ -1,4 +1,4 @@
[
(builtins.attrValues {})
(builtins.attrValues { })
(builtins.attrValues { foo = 1; bar = 2; baz = 3; })
]

View file

@ -1 +1 @@
[ builtins ] == [ builtins.builtins ]
[ builtins ] == [ builtins.builtins ]

View file

@ -4,7 +4,7 @@ let
ord1 = builtins.compareVersions a b;
ord2 = builtins.compareVersions b a;
in
assert ord1 == -ord2; ord1;
assert ord1 == -ord2; ord1;
in
[

View file

@ -1 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [] (builtins.throw "a") ]) (builtins.concatLists [ [] [] [ builtins.throw "a" ] ]) ]
map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [ ] (builtins.throw "a") ]) (builtins.concatLists [ [ ] [ ] [ builtins.throw "a" ] ]) ]

View file

@ -1 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: []) (builtins.throw "a")) ]
map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: [ ]) (builtins.throw "a")) ]

View file

@ -1,8 +1,8 @@
map (e: (builtins.tryEval e).success) [
(builtins.foldl' (builtins.throw "a") {} [ {} {} {} ])
(builtins.foldl' (x: y: x // y) {} (builtins.throw "b"))
(builtins.foldl' (_: _: builtins.throw "x") {} [ {} ])
(builtins.foldl' (x: y: x // y) (builtins.throw "x") [ {} ])
(builtins.foldl' (x: y: x // y) {} [ {} { a = builtins.throw "z"; } {} ])
(builtins.foldl' (x: y: x // y) {} [ {} { b = 3; a = builtins.throw "u"; } {} ])
(builtins.foldl' (builtins.throw "a") { } [{ } { } { }])
(builtins.foldl' (x: y: x // y) { } (builtins.throw "b"))
(builtins.foldl' (_: _: builtins.throw "x") { } [{ }])
(builtins.foldl' (x: y: x // y) (builtins.throw "x") [{ }])
(builtins.foldl' (x: y: x // y) { } [{ } { a = builtins.throw "z"; } { }])
(builtins.foldl' (x: y: x // y) { } [{ } { b = 3; a = builtins.throw "u"; } { }])
]

View file

@ -3,13 +3,13 @@ let
in
# key needs to be a list since it uses comparison, not equality checks:
# lists are comparable in Nix if all non-comparable items in them are equal (e.g.
# functions, attribute sets).
# lists are comparable in Nix if all non-comparable items in them are equal (e.g.
# functions, attribute sets).
builtins.genericClosure {
startSet = [
{ key = [ { inherit foo; } ]; val = null; }
{ key = [{ inherit foo; }]; val = null; }
];
operator = { val, ... }: if val != null then [] else [
{ key = [ { inherit foo; } ]; val = throw "no pointer equality? 🥺👉👈"; }
operator = { val, ... }: if val != null then [ ] else [
{ key = [{ inherit foo; }]; val = throw "no pointer equality? 🥺👉👈"; }
];
}

View file

@ -1,4 +1,3 @@
builtins.groupBy
(v: v.x)
[ (rec { y = x; x = "fred"; }) ]

View file

@ -3,7 +3,7 @@
(builtins.hasAttr "bar" { foo = 1; bar = 2; baz = 3; })
(builtins.hasAttr "baz" { foo = 1; bar = 2; baz = 3; })
(builtins.hasAttr "FOO" { foo = 1; bar = 2; baz = 3; })
(builtins.hasAttr "foo" {})
(builtins.hasAttr "foo" { })
(builtins.hasAttr ("f" + "o" + "o") { foo = 1; })
(builtins.hasAttr ("b" + "a" + "r") { foo = 1; })
]

View file

@ -1,5 +1,5 @@
[
(builtins.length [])
(builtins.length [ ])
(builtins.length [ 1 ])
(builtins.length [ "one" "two" "three" ])
]

View file

@ -1,7 +1,7 @@
map (e: (builtins.tryEval e).success) [
(builtins.listToAttrs [ { name = builtins.throw "a"; value = "b"; } ])
(builtins.listToAttrs [ { name = "a"; value = builtins.throw "b"; } ])
(builtins.listToAttrs [ { name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; } ])
(builtins.listToAttrs [ { name = "a"; value = "b"; } (builtins.throw "e") ])
(builtins.listToAttrs [{ name = builtins.throw "a"; value = "b"; }])
(builtins.listToAttrs [{ name = "a"; value = builtins.throw "b"; }])
(builtins.listToAttrs [{ name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; }])
(builtins.listToAttrs [{ name = "a"; value = "b"; } (builtins.throw "e")])
(builtins.listToAttrs (builtins.throw "f"))
]

View file

@ -1,7 +1,7 @@
[
(builtins.partition (_: true) [ 1 2 3 4 5])
(builtins.partition (_: false) [ 1 2 3 4 5])
(builtins.partition (x: x == 2) [ 1 2 3 4 5])
(builtins.partition (_: true) [ 1 2 3 4 5 ])
(builtins.partition (_: false) [ 1 2 3 4 5 ])
(builtins.partition (x: x == 2) [ 1 2 3 4 5 ])
(builtins.partition (x: (builtins.length x) > 1) [
[ 1 ]

View file

@ -1,6 +1,6 @@
map (e: (builtins.tryEval e).success) [
(builtins.removeAttrs (builtins.throw "a") [ "a" ])
(builtins.removeAttrs { a = {}; } (builtins.throw "b"))
(builtins.removeAttrs { a = { }; } (builtins.throw "b"))
(builtins.removeAttrs { a = builtins.throw "b"; } [ "a" ])
(builtins.removeAttrs { "${builtins.throw "c"}" = "b"; } [ "c" ])
]

View file

@ -1,6 +1,6 @@
[
(builtins.replaceStrings ["oo" "a"] ["a" "i"] "foobar")
(builtins.replaceStrings ["o"] ["a"] "a")
(builtins.replaceStrings ["" ""] ["1" "2"] "a")
(builtins.replaceStrings ["a" "b" "c"] ["A" "B" "C"] "abc")
(builtins.replaceStrings [ "oo" "a" ] [ "a" "i" ] "foobar")
(builtins.replaceStrings [ "o" ] [ "a" ] "a")
(builtins.replaceStrings [ "" "" ] [ "1" "2" ] "a")
(builtins.replaceStrings [ "a" "b" "c" ] [ "A" "B" "C" ] "abc")
]

View file

@ -24,7 +24,7 @@
];
operator = { key, initial, ... }:
if initial
then [ { key = key - 1; initial = false; value = throw "lol"; } ]
then [{ key = key - 1; initial = false; value = throw "lol"; }]
else [ ];
}))
(builtins.length (builtins.concatMap (m: [ m (builtins.throw m) ]) [ "Marusja" ]))

View file

@ -3,20 +3,20 @@ let
in
fix (self:
[
(builtins.typeOf null)
(builtins.typeOf true)
(builtins.typeOf (true && false))
(builtins.typeOf 12)
(builtins.typeOf (builtins.add 21 21))
(builtins.typeOf 1.2)
(builtins.typeOf "foo")
(builtins.typeOf "${"foo" + "bar"}baz")
(builtins.typeOf {})
# (builtins.typeOf { foo.bar = 32; }.foo) # TODO: re-enable when nested keys are done
(builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; }))
(builtins.typeOf self)
(builtins.typeOf fix)
(builtins.typeOf /nix/store)
]
[
(builtins.typeOf null)
(builtins.typeOf true)
(builtins.typeOf (true && false))
(builtins.typeOf 12)
(builtins.typeOf (builtins.add 21 21))
(builtins.typeOf 1.2)
(builtins.typeOf "foo")
(builtins.typeOf "${"foo" + "bar"}baz")
(builtins.typeOf { })
# (builtins.typeOf { foo.bar = 32; }.foo) # TODO: re-enable when nested keys are done
(builtins.typeOf ({ name = "foo"; value = 13; } // { name = "bar"; }))
(builtins.typeOf self)
(builtins.typeOf fix)
(builtins.typeOf /nix/store)
]
)

View file

@ -14,13 +14,13 @@ in
(builtins.isFloat 1)
(builtins.isFunction thunk)
(builtins.isFunction (thunk thunk))
(builtins.isFunction {})
(builtins.isFunction { })
(builtins.isInt 1)
(builtins.isInt (thunk 42))
(builtins.isInt 1.0)
(builtins.isList [ (throw "oh no") (abort "it's over") ])
(builtins.isList (thunk [ 21 21 ]))
(builtins.isList (thunk {}))
(builtins.isList (thunk { }))
(builtins.isNull null)
(builtins.isNull (thunk null))
(builtins.isNull 42)

View file

@ -1 +1 @@
(builtins.tryEval (builtins.intersectAttrs (throw "fred") {})).success
(builtins.tryEval (builtins.intersectAttrs (throw "fred") { })).success

View file

@ -5,10 +5,10 @@ let
in
[
(
{ q = g "ia"; } == { q = g ("i"+"a"); }
{ q = g "ia"; } == { q = g ("i" + "a"); }
)
(
[ (g "ia") ] == [ (g ("i"+"a")) ]
[ (g "ia") ] == [ (g ("i" + "a")) ]
)
]

View file

@ -1,4 +1,5 @@
let
# self-recursive function should be able to close over itself
f = n: if n <= 0 then "done" else f (n - 1);
in f 10
in
f 10

View file

@ -8,7 +8,7 @@ let
in
# introduce some closure depth to force both kinds of upvalue
# resolution, and introduce a dynamically known `a` within the
# closures
# resolution, and introduce a dynamically known `a` within the
# closures
let f = b: with { a = 2; }; c: a + b + c;
in f 0 0

View file

@ -2,6 +2,6 @@
({ __toString = _: "lord"; } + "nikon")
("zero" + { __toString = _: "cool"; })
(/tmp/31337 + "h4x0r")
("foo" + { outPath="blah"; })
({ outPath="blah"; } + "foo")
("foo" + { outPath = "blah"; })
({ outPath = "blah"; } + "foo")
]

View file

@ -1,17 +1,17 @@
[
([1 2] < [1])
([1 2] < [2 3])
([1 2] < [2])
([1 2] < [1 2 3])
([3 4] < [1])
([1 2] > [1])
([1 2] > [2 3])
([1 2] > [2])
([1 2] > [1 2 3])
([3 4] > [1])
([1 2] <= [1])
([1 2] >= [2 3])
([1 2] >= [2])
([1 2] <= [1 2 3])
([3 4] >= [1])
([ 1 2 ] < [ 1 ])
([ 1 2 ] < [ 2 3 ])
([ 1 2 ] < [ 2 ])
([ 1 2 ] < [ 1 2 3 ])
([ 3 4 ] < [ 1 ])
([ 1 2 ] > [ 1 ])
([ 1 2 ] > [ 2 3 ])
([ 1 2 ] > [ 2 ])
([ 1 2 ] > [ 1 2 3 ])
([ 3 4 ] > [ 1 ])
([ 1 2 ] <= [ 1 ])
([ 1 2 ] >= [ 2 3 ])
([ 1 2 ] >= [ 2 ])
([ 1 2 ] <= [ 1 2 3 ])
([ 3 4 ] >= [ 1 ])
]

View file

@ -1 +1 @@
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])
(builtins.concatMap (x: [ x ] ++ [ "z" ]) [ "a" "b" ])

View file

@ -1,8 +1,9 @@
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

@ -15,4 +15,7 @@ with { c = 3; d = 3; };
_:
with { d = 4; };
[ a b c d ]) null null null null
[ a b c d ]) null
null
null
null

View file

@ -5,4 +5,5 @@ let
set = {
value = 42;
};
in result
in
result

View file

@ -1 +1 @@
[["f" ""]] == [["f" ""]]
[ [ "f" "" ] ] == [ [ "f" "" ] ]

View file

@ -1 +1 @@
(builtins.tryEval (builtins.elem { type = rec { x = throw "fred"; }.x; } [ { type = 3; } ])).success
(builtins.tryEval (builtins.elem { type = rec { x = throw "fred"; }.x; } [{ type = 3; }])).success

View file

@ -1,7 +1,9 @@
let
fib' = i: n: m: if i == 0
fib' = i: n: m:
if i == 0
then n
else fib' (i - 1) m (n + m);
fib = n: fib' n 1 1;
in fib 10
in
fib 10

View file

@ -1,6 +1,7 @@
let
fix = f: let x = f x; in x;
in fix(self: {
in
fix (self: {
a = 1;
b = self.a + 20;
c = self.b * 2;

View file

@ -1,5 +1,5 @@
[
(builtins.foldl' builtins.add 0 [1 2 3])
(builtins.foldl' (l1: l2: l1 ++ l2) [0] [[1] [2 3]])
(builtins.foldl' (x: y: if x == 0 then y else x * y) 0 [1 2])
(builtins.foldl' builtins.add 0 [ 1 2 3 ])
(builtins.foldl' (l1: l2: l1 ++ l2) [ 0 ] [ [ 1 ] [ 2 3 ] ])
(builtins.foldl' (x: y: if x == 0 then y else x * y) 0 [ 1 2 ])
]

View file

@ -14,7 +14,7 @@ let
in
# Note that the crash did not occur if the offending expression was the rhs
# argument to `builtins.seq`, hence we need to put the assert in between.
# argument to `builtins.seq`, hence we need to put the assert in between.
assert builtins.seq bomb true;
f { finalise = bomb; }

View file

@ -1,24 +1,24 @@
[
# RFC 7159, section 13.
# RFC 7159, section 13.
(builtins.fromJSON
''
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated" : false,
"IDs": [116, 943, 234, 38793, true ,false,null, -100],
"Latitude": 37.7668,
"Longitude": -122.396
{
"Image": {
"Width": 800,
"Height": 600,
"Title": "View from 15th Floor",
"Thumbnail": {
"Url": "http://www.example.com/image/481989943",
"Height": 125,
"Width": 100
},
"Animated" : false,
"IDs": [116, 943, 234, 38793, true ,false,null, -100],
"Latitude": 37.7668,
"Longitude": -122.396
}
}
}
'')
'')
(builtins.fromJSON ''{"name": "a", "value": "b"}'')
(builtins.fromJSON "[ 1, 2, 3, 4 ]")
]

View file

@ -1,21 +1,22 @@
let
stdenvFun = { }: { name = "stdenv"; };
stdenv2Fun = { }: { name = "stdenv2"; };
stdenvFun = {}: { name = "stdenv"; };
stdenv2Fun = {}: { name = "stdenv2"; };
fetchurlFun = { stdenv }: assert stdenv.name == "stdenv"; { name = "fetchurl"; };
atermFun = { stdenv, fetchurl }: { name = "aterm-${stdenv.name}"; };
aterm2Fun = { stdenv, fetchurl }: { name = "aterm2-${stdenv.name}"; };
nixFun = { stdenv, fetchurl, aterm }: { name = "nix-${stdenv.name}-${aterm.name}"; };
mplayerFun =
{ stdenv, fetchurl, enableX11 ? false, xorg ? null, enableFoo ? true, foo ? null }:
assert stdenv.name == "stdenv2";
assert enableX11 -> xorg.libXv.name == "libXv";
assert enableFoo -> foo != null;
{ name = "mplayer-${stdenv.name}.${xorg.libXv.name}-${xorg.libX11.name}"; };
{ stdenv, fetchurl, enableX11 ? false, xorg ? null, enableFoo ? true, foo ? null }:
assert stdenv.name == "stdenv2";
assert enableX11 -> xorg.libXv.name == "libXv";
assert enableFoo -> foo != null;
{ name = "mplayer-${stdenv.name}.${xorg.libXv.name}-${xorg.libX11.name}"; };
makeOverridable = f: origArgs: f origArgs //
{ override = newArgs:
{
override = newArgs:
makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs));
};
@ -37,7 +38,8 @@ let
mplayer = callPackage mplayerFun { stdenv = pkgs.stdenv2; enableFoo = false; };
nix = callPackage nixFun { };
};
in pkgs;
in
pkgs;
libX11Fun = { stdenv, fetchurl }: { name = "libX11"; };
libX11_2Fun = { stdenv, fetchurl }: { name = "libX11_2"; };
@ -67,14 +69,15 @@ let
in
[ pkgs.stdenv.name
pkgs.fetchurl.name
pkgs.aterm.name
pkgs2.aterm.name
pkgs.xorg.libX11.name
pkgs.xorg.libXv.name
pkgs.mplayer.name
pkgs2.mplayer.name
pkgs.nix.name
pkgs2.nix.name
]
[
pkgs.stdenv.name
pkgs.fetchurl.name
pkgs.aterm.name
pkgs2.aterm.name
pkgs.xorg.libX11.name
pkgs.xorg.libXv.name
pkgs.mplayer.name
pkgs2.mplayer.name
pkgs.nix.name
pkgs2.nix.name
]

View file

@ -4,4 +4,5 @@ let
set = {
inherit ({ value = 42; }) "value";
};
in set.value
in
set.value

View file

@ -1,3 +1,3 @@
builtins.intersectAttrs
{ a = 1; b = 2; c = 3; }
{ a = 100; b = 200; d = 5; }
{ a = 1; b = 2; c = 3; }
{ a = 100; b = 200; d = 5; }

View file

@ -1,4 +1,5 @@
let
f = n: n + a;
a = 2;
in f 40
in
f 40

View file

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

View file

@ -6,7 +6,8 @@ let
list3 = [ (2 + 2) ];
list4 = [ (2 + 2) ];
list5 = [ (2 + 2) ];
in [
in
[
(attrs1 == attrs2)
(list1 == list2)
(list3 == list2)

View file

@ -1,9 +1,9 @@
let {
a = 21;
b = body.one;
a = 21;
b = body.one;
body = {
one = a * 2;
two = b;
};
body = {
one = a * 2;
two = b;
};
}

View file

@ -1 +1 @@
with {}; let { body = 42; }
with { }; let { body = 42; }

View file

@ -1,4 +1,4 @@
let {
a = 21;
body = a * 2;
a = 21;
body = a * 2;
}

View file

@ -2,4 +2,5 @@ let
a = 1;
"b" = 2;
${"c"} = 3;
in [ a b c ]
in
[ a b c ]

View file

@ -3,10 +3,11 @@ let
a = 1;
};
in
let
set2 = {
b = 1;
};
inherit (set) a;
inherit (set2) b;
in a + b
let
set2 = {
b = 1;
};
inherit (set) a;
inherit (set2) b;
in
a + b

View file

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

View file

@ -1 +1 @@
[ 1 2 ] > [ ((rec{x=1;}).x) 2]
[ 1 2 ] > [ ((rec{ x = 1; }).x) 2 ]

View file

@ -1,15 +1,16 @@
with builtins;
let
fold = op: nul: list:
if list == []
if list == [ ]
then nul
else op (head list) (fold op nul (tail list));
concat =
fold (x: y: x + y) "";
asi = name: value : { inherit name value; };
list = [ ( asi "a" "A" ) ( asi "b" "B" ) ];
asi = name: value: { inherit name value; };
list = [ (asi "a" "A") (asi "b" "B") ];
a = builtins.listToAttrs list;
b = builtins.listToAttrs ( list ++ list );
r = builtins.listToAttrs [ (asi "result" [ a b ]) ( asi "throw" (throw "this should not be thrown")) ];
b = builtins.listToAttrs (list ++ list);
r = builtins.listToAttrs [ (asi "result" [ a b ]) (asi "throw" (throw "this should not be thrown")) ];
x = builtins.listToAttrs [ (asi "foo" "bar") (asi "foo" "bla") ];
in concat (map (x: x.a) r.result) + x.foo
in
concat (map (x: x.a) r.result) + x.foo

View file

@ -1 +1 @@
(builtins.tryEval ( (throw "fred") && (throw "jill") )).success
(builtins.tryEval ((throw "fred") && (throw "jill"))).success

View file

@ -1 +1 @@
(builtins.tryEval ( (throw "fred") || (throw "jill") )).success
(builtins.tryEval ((throw "fred") || (throw "jill"))).success

View file

@ -6,4 +6,5 @@ let
a = 21;
b = a * 2;
};
in set.b
in
set.b

View file

@ -1,6 +1,10 @@
let
doubler = n: outer n;
outer = let inner = n: a * n;
a = 2;
in inner;
in doubler 10
outer =
let
inner = n: a * n;
a = 2;
in
inner;
in
doubler 10

View file

@ -1,4 +1,5 @@
let
inner = 21;
set.a.b = inner * 2;
in set
in
set

View file

@ -6,12 +6,17 @@
let
a = 1;
b = 2;
outer = let
c = 3;
d = 4;
inner = let
e = 5;
f = 6;
in g: [ a b c d e f g ];
in inner;
in outer 7
outer =
let
c = 3;
d = 4;
inner =
let
e = 5;
f = 6;
in
g: [ a b c d e f g ];
in
inner;
in
outer 7

View file

@ -1,7 +1,10 @@
let
a = let
b = 1;
c = 2;
in b + c;
a =
let
b = 1;
c = 2;
in
b + c;
b = 4;
in a + b
in
a + b

View file

@ -1,4 +1,5 @@
let
null = 1;
f = n: n + null;
in f 41
in
f 41

View file

@ -4,4 +4,5 @@ let
a = b;
b = c;
c = 42;
in a
in
a

View file

@ -1,4 +1,5 @@
let
set1 = { a = 1; };
set2 = { a = 2; };
in with set1; with set2; a
in
with set1; with set2; a

View file

@ -1,12 +1,11 @@
# the first dash followed by a non-alphabetic character separates
# the "name" from the "version"
assert builtins.parseDrvName "ripgrep-1.2" == { name = "ripgrep"; version = "1.2"; };
assert builtins.parseDrvName "rip-grep-1.2" == { name = "rip-grep"; version = "1.2"; };
assert builtins.parseDrvName "ripgrep-1.2" == { name = "ripgrep"; version = "1.2"; };
assert builtins.parseDrvName "rip-grep-1.2" == { name = "rip-grep"; version = "1.2"; };
assert builtins.parseDrvName "7zip_archiver-0.2" == { name = "7zip_archiver"; version = "0.2"; };
assert builtins.parseDrvName "gcc-1-2" == { name = "gcc"; version = "1-2"; };
assert builtins.parseDrvName "bash--1-2" == { name = "bash"; version = "-1-2"; };
assert builtins.parseDrvName "xvidtune-?1-2" == { name = "xvidtune"; version = "?1-2"; };
assert builtins.parseDrvName "gcc-1-2" == { name = "gcc"; version = "1-2"; };
assert builtins.parseDrvName "bash--1-2" == { name = "bash"; version = "-1-2"; };
assert builtins.parseDrvName "xvidtune-?1-2" == { name = "xvidtune"; version = "?1-2"; };
true

View file

@ -1,2 +1,2 @@
builtins.pathExists ./lib.nix
&& !builtins.pathExists ./bla.nix
&& !builtins.pathExists ./bla.nix

View file

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

View file

@ -3,11 +3,12 @@
let
inherit (builtins) foldl' listToAttrs;
input = [ { name = "result"; value = 1; } { name = "result"; value = 2; } ];
input = [{ name = "result"; value = 1; } { name = "result"; value = 2; }];
# foldl-based version of listToAttrs with the _opposite_ behaviour.
listToAttrs' = list: foldl' ( acc: elem: acc // { ${elem.name} = elem.value; }) {} list;
in [
listToAttrs' = list: foldl' (acc: elem: acc // { ${elem.name} = elem.value; }) { } list;
in
[
(listToAttrs input).result
(listToAttrs' input).result
]

View file

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

View file

@ -2,4 +2,5 @@ let
set = {
a = 1;
};
in with set; a
in
with set; a

View file

@ -1 +1 @@
(builtins.tryEval ( builtins.substring 0 4 (throw "jill") )).success
(builtins.tryEval (builtins.substring 0 4 (throw "jill"))).success

View file

@ -1,7 +1,8 @@
let
__functor = f;
f = self: x: self.out * x;
in {
in
{
inherit __functor;
out = 21;
} 2

View file

@ -1,6 +1,8 @@
let
a = {};
in let
a = { };
in
let
c = if builtins.isFunction a then a b else a;
b = {};
in c
b = { };
in
c

View file

@ -4,4 +4,5 @@ let
set = {
a = with { b = 42; }; b;
};
in set.a
in
set.a

View file

@ -5,6 +5,7 @@ let
a = 1;
b = 2;
c = 3;
in {
in
{
inherit a b c;
}

View file

@ -1,7 +1,10 @@
let
poisoned = let
true = 1;
false = 2;
null = 3;
in [ true false null ];
in [ true false null ] ++ poisoned
poisoned =
let
true = 1;
false = 2;
null = 3;
in
[ true false null ];
in
[ true false null ] ++ poisoned

View file

@ -3,13 +3,14 @@
# provide the value.
# Provide a dynamic `x` identifier in the scope.
with ({ x = 1;});
with ({ x = 1; });
# inherit this `x` as a static identifier
let inherit x;
# Provide another dynamic `x` identifier
in with ({ x = 3; });
# Provide another dynamic `x` identifier
in
with ({ x = 3; });
# Inherited static identifier should have precedence
x

View file

@ -3,4 +3,4 @@ let
f = owo: "thia";
in
[ f 42 ] > [ f 21 ]
[ f 42 ] > [ f 21 ]

View file

@ -43,4 +43,4 @@ in
# pointer inequality
(peq1 f (x: x))
(peq2 (x: x) f)
]
]

View file

@ -9,4 +9,5 @@ let
${with set1; key} = 20;
${with { key = "c"; }; key} = 2;
};
in set2.a + set2.b + set2.c
in
set2.a + set2.b + set2.c

View file

@ -6,7 +6,8 @@ let
set = {
value = 2;
};
in [
in
[
1
(with set; value)
3

View file

@ -3,7 +3,7 @@ with builtins;
rec {
fold = op: nul: list:
if list == []
if list == [ ]
then nul
else op (head list) (fold op nul (tail list));
@ -14,23 +14,25 @@ rec {
flatten = x:
if isList x
then fold (x: y: (flatten x) ++ y) [] x
else [x];
then fold (x: y: (flatten x) ++ y) [ ] x
else [ x ];
sum = foldl' (x: y: add x y) 0;
hasSuffix = ext: fileName:
let lenFileName = stringLength fileName;
lenExt = stringLength ext;
in !(lessThan lenFileName lenExt) &&
substring (sub lenFileName lenExt) lenFileName fileName == ext;
let
lenFileName = stringLength fileName;
lenExt = stringLength ext;
in
!(lessThan lenFileName lenExt) &&
substring (sub lenFileName lenExt) lenFileName fileName == ext;
# Split a list at the given position.
splitAt = pos: list:
if pos == 0 then {first = []; second = list;} else
if list == [] then {first = []; second = [];} else
if pos == 0 then { first = [ ]; second = list; } else
if list == [ ] then { first = [ ]; second = [ ]; } else
let res = splitAt (sub pos 1) (tail list);
in {first = [(head list)] ++ res.first; second = res.second;};
in { first = [ (head list) ] ++ res.first; second = res.second; };
# Stable merge sort.
sortBy = comp: list:
@ -40,14 +42,15 @@ rec {
split = splitAt (div (length list) 2) list;
first = sortBy comp split.first;
second = sortBy comp split.second;
in mergeLists comp first second
in
mergeLists comp first second
else list;
mergeLists = comp: list1: list2:
if list1 == [] then list2 else
if list2 == [] then list1 else
if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
[(head list1)] ++ mergeLists comp (tail list1) list2;
if list1 == [ ] then list2 else
if list2 == [ ] then list1 else
if comp (head list2) (head list1) then [ (head list2) ] ++ mergeLists comp list1 (tail list2) else
[ (head list1) ] ++ mergeLists comp (tail list1) list2;
id = x: x;
@ -55,7 +58,7 @@ rec {
range = first: last:
if first > last
then []
else genList (n: first + n) (last - first + 1);
then [ ]
else genList (n: first + n) (last - first + 1);
}

View file

@ -3,10 +3,10 @@ let
in
builtins.genericClosure {
startSet = [ { key = id; first = true; } ];
startSet = [{ key = id; first = true; }];
operator =
{ first, ... }:
if first then [
{ key = id; first = false; }
] else [];
] else [ ];
}

View file

@ -17,9 +17,9 @@ let
};
multiTail = {
val = 42;
tail1 = multiTail;
tail2 = multiTail;
val = 42;
tail1 = multiTail;
tail2 = multiTail;
};
in

View file

@ -10,23 +10,110 @@
let
# C++ Nix 2.3 builtins except valueSize which is removed in later versions
minimalBuiltins = [
"abort" "add" "addErrorContext" "all" "any" "appendContext" "attrNames"
"attrValues" "baseNameOf" "bitAnd" "bitOr" "bitXor" "builtins" "catAttrs"
"compareVersions" "concatLists" "concatMap" "concatStringsSep"
"currentSystem" "currentTime" "deepSeq" "derivation" "derivationStrict"
"dirOf" "div" "elem" "elemAt" "false" "fetchGit" "fetchMercurial"
"fetchTarball" "fetchurl" "filter" "filterSource" "findFile" "foldl'"
"fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure" "getAttr"
"getContext" "getEnv" "hasAttr" "hasContext" "hashFile" "hashString" "head"
"import" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt"
"isList" "isNull" "isPath" "isString" "langVersion" "length" "lessThan"
"listToAttrs" "map" "mapAttrs" "match" "mul" "nixPath" "nixVersion" "null"
"parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir"
"readFile" "removeAttrs" "replaceStrings" "scopedImport" "seq" "sort"
"split" "splitVersion" "storeDir" "storePath" "stringLength" "sub"
"substring" "tail" "throw" "toFile" "toJSON" "toPath" "toString" "toXML"
"trace" "true" "tryEval" "typeOf" "unsafeDiscardOutputDependency"
"unsafeDiscardStringContext" "unsafeGetAttrPos"
"abort"
"add"
"addErrorContext"
"all"
"any"
"appendContext"
"attrNames"
"attrValues"
"baseNameOf"
"bitAnd"
"bitOr"
"bitXor"
"builtins"
"catAttrs"
"compareVersions"
"concatLists"
"concatMap"
"concatStringsSep"
"currentSystem"
"currentTime"
"deepSeq"
"derivation"
"derivationStrict"
"dirOf"
"div"
"elem"
"elemAt"
"false"
"fetchGit"
"fetchMercurial"
"fetchTarball"
"fetchurl"
"filter"
"filterSource"
"findFile"
"foldl'"
"fromJSON"
"fromTOML"
"functionArgs"
"genList"
"genericClosure"
"getAttr"
"getContext"
"getEnv"
"hasAttr"
"hasContext"
"hashFile"
"hashString"
"head"
"import"
"intersectAttrs"
"isAttrs"
"isBool"
"isFloat"
"isFunction"
"isInt"
"isList"
"isNull"
"isPath"
"isString"
"langVersion"
"length"
"lessThan"
"listToAttrs"
"map"
"mapAttrs"
"match"
"mul"
"nixPath"
"nixVersion"
"null"
"parseDrvName"
"partition"
"path"
"pathExists"
"placeholder"
"readDir"
"readFile"
"removeAttrs"
"replaceStrings"
"scopedImport"
"seq"
"sort"
"split"
"splitVersion"
"storeDir"
"storePath"
"stringLength"
"sub"
"substring"
"tail"
"throw"
"toFile"
"toJSON"
"toPath"
"toString"
"toXML"
"trace"
"true"
"tryEval"
"typeOf"
"unsafeDiscardOutputDependency"
"unsafeDiscardStringContext"
"unsafeGetAttrPos"
];
intersectLists = as: bs: builtins.filter (a: builtins.elem a bs) as;