Skip to content

Commit 84b53a1

Browse files
haenoeEricson2314
andcommitted
Unit test for derivation "advanced attrs"
Co-Authored-By: John Ericson <John.Ericson@Obsidian.Systems>
1 parent 2f5fdab commit 84b53a1

20 files changed

Lines changed: 493 additions & 14 deletions

maintainers/flake-module.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@
447447
''^tests/unit/libfetchers/public-key\.cc''
448448
''^tests/unit/libstore-support/tests/derived-path\.cc''
449449
''^tests/unit/libstore-support/tests/derived-path\.hh''
450-
''^tests/unit/libstore-support/tests/libstore\.hh''
451450
''^tests/unit/libstore-support/tests/nix_api_store\.hh''
452451
''^tests/unit/libstore-support/tests/outputs-spec\.cc''
453452
''^tests/unit/libstore-support/tests/outputs-spec\.hh''
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("out","/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults","","")],[],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("builder","/bin/bash"),("name","advanced-attributes-defaults"),("out","/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults"),("system","my-system")])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
derivation {
2+
name = "advanced-attributes-defaults";
3+
system = "my-system";
4+
builder = "/bin/bash";
5+
args = [ "-c" "echo hello > $out" ];
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("dev","/nix/store/8bazivnbipbyi569623skw5zm91z6kc2-advanced-attributes-structured-attrs-defaults-dev","",""),("out","/nix/store/f8f8nvnx32bxvyxyx2ff7akbvwhwd9dw-advanced-attributes-structured-attrs-defaults","","")],[],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"builder\":\"/bin/bash\",\"name\":\"advanced-attributes-structured-attrs-defaults\",\"outputs\":[\"out\",\"dev\"],\"system\":\"my-system\"}"),("dev","/nix/store/8bazivnbipbyi569623skw5zm91z6kc2-advanced-attributes-structured-attrs-defaults-dev"),("out","/nix/store/f8f8nvnx32bxvyxyx2ff7akbvwhwd9dw-advanced-attributes-structured-attrs-defaults")])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
derivation {
2+
name = "advanced-attributes-structured-attrs-defaults";
3+
system = "my-system";
4+
builder = "/bin/bash";
5+
args = [ "-c" "echo hello > $out" ];
6+
outputs = [ "out" "dev" ];
7+
__structuredAttrs = true;
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("bin","/nix/store/pbzb48v0ycf80jgligcp4n8z0rblna4n-advanced-attributes-structured-attrs-bin","",""),("dev","/nix/store/7xapi8jv7flcz1qq8jhw55ar8ag8hldh-advanced-attributes-structured-attrs-dev","",""),("out","/nix/store/mpq3l1l1qc2yr50q520g08kprprwv79f-advanced-attributes-structured-attrs","","")],[("/nix/store/4xm4wccqsvagz9gjksn24s7rip2fdy7v-foo.drv",["out"]),("/nix/store/plsq5jbr5nhgqwcgb2qxw7jchc09dnl8-bar.drv",["out"])],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"__darwinAllowLocalNetworking\":true,\"__impureHostDeps\":[\"/usr/bin/ditto\"],\"__noChroot\":true,\"__sandboxProfile\":\"sandcastle\",\"allowSubstitutes\":false,\"builder\":\"/bin/bash\",\"impureEnvVars\":[\"UNICORN\"],\"name\":\"advanced-attributes-structured-attrs\",\"outputChecks\":{\"bin\":{\"disallowedReferences\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"],\"disallowedRequisites\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"]},\"dev\":{\"maxClosureSize\":5909,\"maxSize\":789},\"out\":{\"allowedReferences\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"],\"allowedRequisites\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"]}},\"outputs\":[\"out\",\"bin\",\"dev\"],\"preferLocalBuild\":true,\"requiredSystemFeatures\":[\"rainbow\",\"uid-range\"],\"system\":\"my-system\"}"),("bin","/nix/store/pbzb48v0ycf80jgligcp4n8z0rblna4n-advanced-attributes-structured-attrs-bin"),("dev","/nix/store/7xapi8jv7flcz1qq8jhw55ar8ag8hldh-advanced-attributes-structured-attrs-dev"),("out","/nix/store/mpq3l1l1qc2yr50q520g08kprprwv79f-advanced-attributes-structured-attrs")])
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let
2+
system = "my-system";
3+
foo = derivation {
4+
inherit system;
5+
name = "foo";
6+
builder = "/bin/bash";
7+
args = ["-c" "echo foo > $out"];
8+
};
9+
bar = derivation {
10+
inherit system;
11+
name = "bar";
12+
builder = "/bin/bash";
13+
args = ["-c" "echo bar > $out"];
14+
};
15+
in
16+
derivation {
17+
inherit system;
18+
name = "advanced-attributes-structured-attrs";
19+
builder = "/bin/bash";
20+
args = [ "-c" "echo hello > $out" ];
21+
__sandboxProfile = "sandcastle";
22+
__noChroot = true;
23+
__impureHostDeps = ["/usr/bin/ditto"];
24+
impureEnvVars = ["UNICORN"];
25+
__darwinAllowLocalNetworking = true;
26+
outputs = [ "out" "bin" "dev" ];
27+
__structuredAttrs = true;
28+
outputChecks = {
29+
out = {
30+
allowedReferences = [foo];
31+
allowedRequisites = [foo];
32+
};
33+
bin = {
34+
disallowedReferences = [bar];
35+
disallowedRequisites = [bar];
36+
};
37+
dev = {
38+
maxSize = 789;
39+
maxClosureSize = 5909;
40+
};
41+
};
42+
requiredSystemFeatures = ["rainbow" "uid-range"];
43+
preferLocalBuild = true;
44+
allowSubstitutes = false;
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Derive([("out","/nix/store/33a6fdmn8q9ih9d7npbnrxn2q56a4l8q-advanced-attributes","","")],[("/nix/store/4xm4wccqsvagz9gjksn24s7rip2fdy7v-foo.drv",["out"]),("/nix/store/plsq5jbr5nhgqwcgb2qxw7jchc09dnl8-bar.drv",["out"])],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__darwinAllowLocalNetworking","1"),("__impureHostDeps","/usr/bin/ditto"),("__noChroot","1"),("__sandboxProfile","sandcastle"),("allowSubstitutes",""),("allowedReferences","/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo"),("allowedRequisites","/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo"),("builder","/bin/bash"),("disallowedReferences","/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar"),("disallowedRequisites","/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar"),("impureEnvVars","UNICORN"),("name","advanced-attributes"),("out","/nix/store/33a6fdmn8q9ih9d7npbnrxn2q56a4l8q-advanced-attributes"),("preferLocalBuild","1"),("requiredSystemFeatures","rainbow uid-range"),("system","my-system")])
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let
2+
system = "my-system";
3+
foo = derivation {
4+
inherit system;
5+
name = "foo";
6+
builder = "/bin/bash";
7+
args = ["-c" "echo foo > $out"];
8+
};
9+
bar = derivation {
10+
inherit system;
11+
name = "bar";
12+
builder = "/bin/bash";
13+
args = ["-c" "echo bar > $out"];
14+
};
15+
in
16+
derivation {
17+
inherit system;
18+
name = "advanced-attributes";
19+
builder = "/bin/bash";
20+
args = [ "-c" "echo hello > $out" ];
21+
__sandboxProfile = "sandcastle";
22+
__noChroot = true;
23+
__impureHostDeps = ["/usr/bin/ditto"];
24+
impureEnvVars = ["UNICORN"];
25+
__darwinAllowLocalNetworking = true;
26+
allowedReferences = [foo];
27+
allowedRequisites = [foo];
28+
disallowedReferences = [bar];
29+
disallowedRequisites = [bar];
30+
requiredSystemFeatures = ["rainbow" "uid-range"];
31+
preferLocalBuild = true;
32+
allowSubstitutes = false;
33+
}

tests/unit/libexpr/derivation.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "gtest/gtest.h"
2+
#include <string>
3+
#include "tests/characterization.hh"
4+
#include "tests/libexpr.hh"
5+
#include "derivations.hh"
6+
7+
namespace nix {
8+
9+
class DerivationTest : public CharacterizationTest, public LibExprTest
10+
{
11+
Path unitTestData = getUnitTestData() + "/derivation";
12+
13+
public:
14+
Path goldenMaster(std::string_view testStem) const override
15+
{
16+
return unitTestData + "/" + testStem;
17+
}
18+
};
19+
20+
#define EXPR_DRV_TEST(NAME, STEM) \
21+
TEST_F(DerivationTest, Derivation_##NAME) \
22+
{ \
23+
writeTest( \
24+
STEM ".drv", \
25+
[&]() -> Derivation { \
26+
Value v = eval(readFile(goldenMaster(STEM ".nix"))); \
27+
Symbol s = state.symbols.create("drvPath"); \
28+
auto attr = v.attrs() -> get(s); \
29+
state.forceValueDeep(*attr->value); \
30+
NixStringContext context; \
31+
auto storePath = state.coerceToStorePath(attr->pos, *attr->value, context, ""); \
32+
\
33+
return store->readDerivation(storePath); \
34+
}, \
35+
[&](const auto & file) { \
36+
auto s = readFile(file); \
37+
return parseDerivation(*store, std::move(s), STEM); \
38+
}, \
39+
[&](const auto & file, const auto & got) { \
40+
auto s = got.unparse(*store, false); \
41+
return writeFile(file, std::move(s)); \
42+
}); \
43+
}
44+
45+
EXPR_DRV_TEST(advancedAttributes, "advanced-attributes");
46+
EXPR_DRV_TEST(advancedAttributes_defaults, "advanced-attributes-defaults");
47+
EXPR_DRV_TEST(advancedAttributes_structuredAttrs, "advanced-attributes-structured-attrs");
48+
EXPR_DRV_TEST(advancedAttributes_structuredAttrs_defaults, "advanced-attributes-structured-attrs-defaults");
49+
50+
}

0 commit comments

Comments
 (0)