···
15
+
# Extract (effective) arguments passed to stdenv.mkDerivation and compute the
16
+
# arguments we would need to pass to srcOnly manually in order to get the same
17
+
# as `srcOnly drv`, i.e. the arguments passed to stdenv.mkDerivation plus the
18
+
# used stdenv itself.
22
+
drv' = drv.overrideAttrs (
23
+
_finalAttrs: prevAttrs: {
24
+
passthru = prevAttrs.passthru or { } // {
25
+
passedAttrs = prevAttrs;
30
+
drv'.passedAttrs // { inherit (drv') stdenv; };
32
+
canEvalDrv = drv: (builtins.tryEval drv.drvPath).success;
emptySrc = srcOnly emptyDirectory;
# It can be invoked in a number of ways. Let's make sure they're equivalent.
17
-
zlibSrcDrvAttrs = srcOnly zlib.drvAttrs;
38
+
zlibSrcEquiv = srcOnly (getEquivAttrs zlib);
# zlibSrcFreeform = # ???;
helloSrc = srcOnly hello;
20
-
helloSrcDrvAttrs = srcOnly hello.drvAttrs;
41
+
helloSrcEquiv = srcOnly (getEquivAttrs hello);
43
+
gitSrc = srcOnly git;
44
+
gitSrcEquiv = srcOnly (getEquivAttrs git);
# The srcOnly <drv> invocation leaks a lot of attrs into the srcOnly derivation,
# so for comparing with the freeform invocation, we need to make a selection.
···
helloDrvSimpleSrc = srcOnly helloDrvSimple;
36
-
helloDrvSimpleSrcFreeform = srcOnly (
38
-
inherit (helloDrvSimple)
47
-
# __impureHostDeps get duplicated in helloDrvSimpleSrc (on darwin)
48
-
# This is harmless, but fails the test for what is arguably an
49
-
# unrelated non-problem, so we just work around it here.
50
-
# The inclusion of __impureHostDeps really shouldn't be required,
51
-
# and should be removed from this test.
52
-
// lib.optionalAttrs (helloDrvSimple ? __impureHostDeps) {
53
-
inherit (helloDrvSimple) __impureHostDeps;
60
+
helloDrvSimpleSrcFreeform = srcOnly ({
61
+
inherit (helloDrvSimple)
71
+
# Test the issue reported in https://github.com/NixOS/nixpkgs/issues/269539
74
+
drv = (withCFlags [ "-Werror" "-Wall" ] stdenv).mkDerivation {
75
+
name = "drv-using-stdenv-adapter";
78
+
# Confirm the issue we are trying to avoid exists
79
+
assert !(canEvalDrv (srcOnly drv.drvAttrs));
81
+
stdenvAdapterDrvSrc = srcOnly stdenvAdapterDrv;
82
+
stdenvAdapterDrvSrcEquiv = srcOnly (
83
+
getEquivAttrs stdenvAdapterDrv
85
+
# The upside of using overrideAttrs is that any stdenv adapter related
86
+
# modifications are only applied once. Using the adapter here again would
87
+
# mean applying it twice in total (since withCFlags functions more or less
88
+
# like an automatic overrideAttrs).
93
+
# Issue similar to https://github.com/NixOS/nixpkgs/issues/269539
94
+
structuredAttrsDrv =
96
+
drv = stdenv.mkDerivation {
97
+
name = "drv-using-structured-attrs";
98
+
src = emptyDirectory;
100
+
env.NIX_DEBUG = true;
101
+
__structuredAttrs = true;
104
+
# Confirm the issue we are trying to avoid exists
105
+
assert !(canEvalDrv (srcOnly drv.drvAttrs));
107
+
structuredAttrsDrvSrc = srcOnly structuredAttrsDrv;
108
+
structuredAttrsDrvSrcEquiv = srcOnly (getEquivAttrs structuredAttrsDrv);
runCommand "srcOnly-tests"
62
-
(testers.testEqualDerivation "zlibSrcDrvAttrs == zlibSrc" zlibSrcDrvAttrs zlibSrc)
115
+
(testers.testEqualDerivation "zlibSrcEquiv == zlibSrc" zlibSrcEquiv zlibSrc)
# (testers.testEqualDerivation
# "zlibSrcFreeform == zlibSrc"
67
-
(testers.testEqualDerivation "helloSrcDrvAttrs == helloSrc" helloSrcDrvAttrs helloSrc)
120
+
(testers.testEqualDerivation "helloSrcEquiv == helloSrc" helloSrcEquiv helloSrc)
121
+
(testers.testEqualDerivation "helloSrcEquiv == helloSrc" helloSrcEquiv helloSrc)
122
+
(testers.testEqualDerivation "gitSrcEquiv == gitSrc" gitSrcEquiv gitSrc)
(testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc"
helloDrvSimpleSrcFreeform
127
+
(testers.testEqualDerivation "stdenvAdapterDrvSrcEquiv == stdenvAdapterDrvSrc"
128
+
stdenvAdapterDrvSrcEquiv
129
+
stdenvAdapterDrvSrc
131
+
(testers.testEqualDerivation "structuredAttrsDrvSrcEquiv == structuredAttrsDrvSrc"
132
+
structuredAttrsDrvSrcEquiv
133
+
structuredAttrsDrvSrc