···
+
# Extract (effective) arguments passed to stdenv.mkDerivation and compute the
+
# arguments we would need to pass to srcOnly manually in order to get the same
+
# as `srcOnly drv`, i.e. the arguments passed to stdenv.mkDerivation plus the
+
drv' = drv.overrideAttrs (
+
_finalAttrs: prevAttrs: {
+
passthru = prevAttrs.passthru or { } // {
+
passedAttrs = prevAttrs;
+
drv'.passedAttrs // { inherit (drv') stdenv; };
+
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.
+
zlibSrcEquiv = srcOnly (getEquivAttrs zlib);
# zlibSrcFreeform = # ???;
helloSrc = srcOnly hello;
+
helloSrcEquiv = srcOnly (getEquivAttrs hello);
+
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;
+
helloDrvSimpleSrcFreeform = srcOnly ({
+
inherit (helloDrvSimple)
+
# Test the issue reported in https://github.com/NixOS/nixpkgs/issues/269539
+
drv = (withCFlags [ "-Werror" "-Wall" ] stdenv).mkDerivation {
+
name = "drv-using-stdenv-adapter";
+
# Confirm the issue we are trying to avoid exists
+
assert !(canEvalDrv (srcOnly drv.drvAttrs));
+
stdenvAdapterDrvSrc = srcOnly stdenvAdapterDrv;
+
stdenvAdapterDrvSrcEquiv = srcOnly (
+
getEquivAttrs stdenvAdapterDrv
+
# The upside of using overrideAttrs is that any stdenv adapter related
+
# modifications are only applied once. Using the adapter here again would
+
# mean applying it twice in total (since withCFlags functions more or less
+
# like an automatic overrideAttrs).
+
# Issue similar to https://github.com/NixOS/nixpkgs/issues/269539
+
drv = stdenv.mkDerivation {
+
name = "drv-using-structured-attrs";
+
__structuredAttrs = true;
+
# Confirm the issue we are trying to avoid exists
+
assert !(canEvalDrv (srcOnly drv.drvAttrs));
+
structuredAttrsDrvSrc = srcOnly structuredAttrsDrv;
+
structuredAttrsDrvSrcEquiv = srcOnly (getEquivAttrs structuredAttrsDrv);
runCommand "srcOnly-tests"
+
(testers.testEqualDerivation "zlibSrcEquiv == zlibSrc" zlibSrcEquiv zlibSrc)
# (testers.testEqualDerivation
# "zlibSrcFreeform == zlibSrc"
+
(testers.testEqualDerivation "helloSrcEquiv == helloSrc" helloSrcEquiv helloSrc)
+
(testers.testEqualDerivation "helloSrcEquiv == helloSrc" helloSrcEquiv helloSrc)
+
(testers.testEqualDerivation "gitSrcEquiv == gitSrc" gitSrcEquiv gitSrc)
(testers.testEqualDerivation "helloDrvSimpleSrcFreeform == helloDrvSimpleSrc"
helloDrvSimpleSrcFreeform
+
(testers.testEqualDerivation "stdenvAdapterDrvSrcEquiv == stdenvAdapterDrvSrc"
+
stdenvAdapterDrvSrcEquiv
+
(testers.testEqualDerivation "structuredAttrsDrvSrcEquiv == structuredAttrsDrvSrc"
+
structuredAttrsDrvSrcEquiv