push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
{ lib, stdenvNoCC }:
/**
A utility builder to get the source code of the input derivation, with any patches applied.
# Examples
```nix
srcOnly pkgs.hello
=> «derivation /nix/store/gyfk2jg9079ga5g5gfms5i4h0k9jhf0f-hello-2.12.1-source.drv»
srcOnly {
inherit (pkgs.hello) name version src stdenv;
}
=> «derivation /nix/store/vf9hdhz38z7rfhzhrk0vi70h755fnsw7-hello-2.12.1-source.drv»
```
# Type
```
srcOnly :: (Derivation | AttrSet) -> Derivation
```
# Input
`attrs`
: One of the following:
- A derivation with (at minimum) an unpackPhase and a patchPhase.
- A set of attributes that would be passed to a `stdenv.mkDerivation` or `stdenvNoCC.mkDerivation` call.
# Output
A derivation that runs a derivation's `unpackPhase` and `patchPhase`, and then copies the result to the output path.
*/
attrs:
let
argsToOverride = args: {
name = "${args.name or "${args.pname}-${args.version}"}-source";
outputs = [ "out" ];
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];
separateDebugInfo = false;
dontUnpack = lib.warnIf (args.dontUnpack or false
) "srcOnly: derivation has dontUnpack set, overriding" false;
dontInstall = false;
installPhase = "cp -pr --reflink=auto -- . $out";
};
in
# If we are passed a derivation (based on stdenv*), we can use overrideAttrs to
# update the arguments to mkDerivation. This gives us the proper awareness of
# what arguments were effectively passed *to* mkDerivation as opposed to
# builtins.derivation (by mkDerivation). For example, stdenv.mkDerivation
# accepts an `env` attribute set which is postprocessed before being passed to
# builtins.derivation. This can lead to evaluation failures, if we assume
# that drvAttrs is equivalent to the arguments passed to mkDerivation.
# See https://github.com/NixOS/nixpkgs/issues/269539.
if lib.isDerivation attrs && attrs ? overrideAttrs then
attrs.overrideAttrs (_finalAttrs: prevAttrs: argsToOverride prevAttrs)
else
let
# If we don't have overrideAttrs, it is extremely unlikely that we are seeing
# a derivation constructed by stdenv.mkDerivation. Since srcOnly assumes
# that we are using stdenv's setup.sh, it therefore doesn't make sense to
# have derivation specific logic in this branch.
# TODO(@sternenseemann): remove drvAttrs special casing in NixOS 26.05
args =
lib.warnIf (lib.isDerivation attrs)
"srcOnly: derivations not created by a variant of stdenv.mkDerivation are not supported. Code relying on behaviour of srcOnly with non-stdenv derivations may break in the future."
attrs.drvAttrs or attrs;
stdenv = args.stdenv or (lib.warn "srcOnly: stdenv not provided, using stdenvNoCC" stdenvNoCC);
drv = stdenv.mkDerivation (args // argsToOverride args);
in
drv

View File

@@ -0,0 +1,152 @@
{
lib,
runCommand,
srcOnly,
hello,
emptyDirectory,
zlib,
git,
withCFlags,
stdenv,
testers,
}:
let
# 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
# used stdenv itself.
getEquivAttrs =
drv:
let
drv' = drv.overrideAttrs (
_finalAttrs: prevAttrs: {
passthru = prevAttrs.passthru or { } // {
passedAttrs = prevAttrs;
};
}
);
in
drv'.passedAttrs // { inherit (drv') stdenv; };
canEvalDrv = drv: (builtins.tryEval drv.drvPath).success;
emptySrc = srcOnly emptyDirectory;
zlibSrc = srcOnly zlib;
# 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);
gitSrc = srcOnly git;
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.
# Otherwise, we'll be comparing against whatever attribute the fancy hello drv
# has.
helloDrvSimple = stdenv.mkDerivation {
inherit (hello)
name
pname
version
src
patches
;
};
helloDrvSimpleSrc = srcOnly helloDrvSimple;
helloDrvSimpleSrcFreeform = srcOnly {
inherit (helloDrvSimple)
name
pname
version
src
patches
stdenv
;
};
# Test the issue reported in https://github.com/NixOS/nixpkgs/issues/269539
stdenvAdapterDrv =
let
drv = (withCFlags [ "-Werror" "-Wall" ] stdenv).mkDerivation {
name = "drv-using-stdenv-adapter";
};
in
# Confirm the issue we are trying to avoid exists
assert !(canEvalDrv (srcOnly drv.drvAttrs));
drv;
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).
inherit stdenv;
}
);
# Issue similar to https://github.com/NixOS/nixpkgs/issues/269539
structuredAttrsDrv =
let
drv = stdenv.mkDerivation {
name = "drv-using-structured-attrs";
src = emptyDirectory;
env.NIX_DEBUG = true;
__structuredAttrs = true;
};
in
# Confirm the issue we are trying to avoid exists
assert !(canEvalDrv (srcOnly drv.drvAttrs));
drv;
structuredAttrsDrvSrc = srcOnly structuredAttrsDrv;
structuredAttrsDrvSrcEquiv = srcOnly (getEquivAttrs structuredAttrsDrv);
in
runCommand "srcOnly-tests"
{
moreTests = [
(testers.testEqualDerivation "zlibSrcEquiv == zlibSrc" zlibSrcEquiv zlibSrc)
# (testers.testEqualDerivation
# "zlibSrcFreeform == zlibSrc"
# 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
helloDrvSimpleSrc
)
(testers.testEqualDerivation "stdenvAdapterDrvSrcEquiv == stdenvAdapterDrvSrc"
stdenvAdapterDrvSrcEquiv
stdenvAdapterDrvSrc
)
(testers.testEqualDerivation "structuredAttrsDrvSrcEquiv == structuredAttrsDrvSrc"
structuredAttrsDrvSrcEquiv
structuredAttrsDrvSrc
)
];
}
''
# Test that emptySrc is empty
if [ -n "$(ls -A ${emptySrc})" ]; then
echo "emptySrc is not empty"
exit 1
fi
# Test that zlibSrc is not empty
if [ -z "$(ls -A ${zlibSrc})" ]; then
echo "zlibSrc is empty"
exit 1
fi
# Make $out exist to avoid build failure
mkdir -p $out
''