31 Commits

Author SHA1 Message Date
Shelvacu
0b960b8595 srcOnly: override output{Dev,Bin,...}. fixes #308050
This wouldn't matter, except pkgs/build-support/setup-hooks/multiple-outputs.sh uses these and errors if they're set to a non-existent output.

Ex: if `outputDev=dev`, then multiple-outputs tries to set `outputInclude=$dev`, but `dev` isn't set.
2025-12-24 13:50:59 -08:00
Wolfgang Walther
91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
sternenseemann
2e6f99eddd srcOnly: add warning for usage with non-stdenv derivations 2025-08-06 16:53:17 +02:00
sternenseemann
fe592efe24 tests.srcOnly: __impureHostDeps issue is fixed using .overrideAttrs 2025-07-18 00:24:37 +02:00
sternenseemann
f89a54c9eb srcOnly: differentiate between computed and user passed drvAttrs
Currently srcOnly assumes that it can pass drv.drvAttrs to
drv.stdenv.mkDerivation and obtain basically the same resulting
derivation, i.e. that drvAttrs and the arguments passed to
stdenv.mkDerivation are equivalent.

It is obvious, that stdenv.mkDerivation may at any point violate this
assumption. Currently, there are two (known) problems stemming from this
assumption affecting srcOnly:

- If __structuredAttrs = true, drvAttrs will contain the env attribute
  set as passed to stdenv.mkDerivation as well as its members at the
  top level like they need to be passed to builtins.derivation.

  If such an attribute set is passed to stdenv.mkDerivation again,
  it triggers its consistency check implemented in #332750.

  This affects e.g. pkgs.git since 318b8c61bd.

- The use of stdenv adapters that modify the env attribute set
  (like withCFlags) causes another issue. In such cases, the
  effect of the adapter, e.g. setting env.NIX_CFLAGS_COMPILE
  can be observed as drvAttrs.NIX_CFLAGS_COMPILE. Without
  __structuredAttrs, drvAttrs.env.NIX_CFLAGS_COMPILE would
  not be set.

  However, because srcOnly dutifully uses the same stdenv as the
  original derivation, the stdenv adapter will be applied to the
  derivation constructed by srcOnly as well. Because it can't tell that
  NIX_CFLAGS_COMPILE was set by the adapter, it'll pass it to
  stdenv.mkDerivation. Unaware of this, the stdenv adapter is applied
  again and sets env.NIX_CFLAGS_COMPILE, triggering the same consistency
  check as above.

tests.srcOnly now also checks that both these issues have been fixed in
srcOnly.

The solution to this is to change the derivation instead of
reconstructing it. Since srcOnly assumes that the input derivation is
based on stdenv.mkDerivation anyways, we are entitled to take advantage
of overrideAttrs. This enables us to see the (effective) arguments
passed to stdenv.mkDerivation via prevAttrs -- before any duplication
between env and the top level happens. We are also guaranteed that the
stdenv adapters are applied only once.

Resolves #269539.

Note that this commit passes the tests.srcOnly test suite both before
and after the change to getEquivAttrs, i.e. that test suite change may
be rebased out or applied after this commit.
2025-07-18 00:24:36 +02:00
sternenseemann
8dfbfd4d8c srcOnly: move dontUnpack warning into dontUnpack binding
This is a refactor to benefit later changes that shouldn't cause any
rebuilds. Unfortunately, the new code doesn't look great with nixfmt.
2025-07-18 00:07:15 +02:00
sternenseemann
436339fa2e srcOnly: float mkDerivation args that need to be overridden into let
This is a refactor (to benefit later changes) that shouldn't cause any
rebuilds under any circumstances.
2025-07-18 00:07:15 +02:00
sternenseemann
e94e63f060 tests.srcOnly: use equivalent input attrs instead of drvAttrs
The ability to use srcOnly on derivations and as a builder can be
formulated like this: Given a derivation `drv` with the expression:

    stdenv.mkDerivation {
      name = "drv";
      …
    }

We can transform it to

    srcOnly {
      stdenv = stdenv;
      name = "drv";
      …
    }

and expect to get the same result as `srcOnly drv`.

This commit changes tests.srcOnly to test this assumption. The
arguments effectively passed to mkDerivation are computed using
getEquivAttrs which then also records the used stdenv for the benefit
of srcOnly.

This is better than using drvAttrs like before because there is actually
no guarantee that drvAttrs is the same as what was passed to
stdenv.mkDerivation. mkDerivation may transform arguments before passing
them on to builtins.derivation. For example, it performs extra
checks on `env` as well as consistency checks with the top level
argument. This can even lead to issues with srcOnly:
https://github.com/NixOS/nixpkgs/issues/269539

Furthermore, the drvAttrs check really only checks something that is
practically statically guaranteed by srcOnly internals before this
commit (assuming that drvAttrs doesn't contain an attribute also named
drvAttrs):

    args = attrs.drvAttrs or attrs;
2025-07-18 00:07:14 +02:00
Robert Hensing
966fc630dd tests.srcOnly: Work around duplication of attr on darwin 2025-07-15 11:42:15 -07:00
Robert Hensing
d93bb6f46a tests.srcOnly: Use zlib instead of glibc
This makes the test more portable, as glibc does not evaluate on
all platforms.
Unfortunately the test fails on darwin for an unrelated reason.
__impureHostDeps values were duplicated.
2025-07-15 11:42:15 -07:00
Robert Hensing
af9b49edab tests.srcOnly: Add test cases for equivalences in the interface 2025-07-15 11:42:15 -07:00
Philip Taron
8d9fcbc47a tests/srcOnly: init (#347548) 2024-11-01 09:13:09 -07:00
Gavin John
1a1a4ebd7d tests/srcOnly: init 2024-10-11 17:55:49 -07:00
Gavin John
cbabc6874d srcOnly: Fix bug introduced by rewrite 2024-10-08 10:15:42 -07:00
Gavin John
28ee6e7979 (WIP) srcOnly: Add noogle-compatible documentation 2024-09-29 12:51:40 -07:00
Gavin John
1463fe69c6 srcOnly: use derivation's stdenv and default to stdenvNoCC 2024-09-29 12:51:39 -07:00
Gavin John
13f0f6e596 srcOnly: Add warning if dontUnpack is set 2024-09-29 12:51:38 -07:00
Gavin John
0b77f4ad4f srcOnly: some readability improvements 2024-09-29 12:51:36 -07:00
sternenseemann
affa8f75ec Reapply "srcOnly: reflink if possible and preserve attributes"
This reverts commit 610ee378fc.

Reason for reapply: The change was alright, just went to the wrong
branch.
2024-05-27 13:41:36 +02:00
sternenseemann
610ee378fc Revert "srcOnly: reflink if possible and preserve attributes"
This reverts commit 7173eb87b8.

Reason for revert: This causes too big a rebuild for master (since GHC
uses srcOnly). This went unnoticed due to a stale ofborg rebuild count.
2024-05-27 02:11:54 +02:00
sternenseemann
7173eb87b8 srcOnly: reflink if possible and preserve attributes
This matches how the default unpackPhase would copy from a store path
into the build directory, so it seems wise to match this here. On file
systems that support reflinks, this should improve performance as well.
2024-05-26 22:06:10 +02:00
Michael Hoang
b2ff7ceff2 nixos/tests: Test that Remote SSH can patch Node 2023-06-09 18:21:41 +10:00
sternenseemann
c98cda29f7 srcOnly: prevent phases being skipped
Previously srcOnly would not work for e.g.
`srcOnly haskell.compiler.ghcjs`, as the custom `installPhase` would be
skipped if `dontInstall` is set. Consequently, we need to ensure that
the two skippable phases we need will always be executed.
2023-01-06 19:02:50 +01:00
figsoda
dd73077dc3 srcOnly: remove unused binding 2022-09-26 22:18:55 -04:00
sternenseemann
f76ac449d1 srcOnly: fix with separateDebugInfo and/or multiple outputs
Before this change `srcOnly git` gives:

    duplicate derivation output 'debug', at pkgs/stdenv/generic/make-derivation.nix:270:7

This was because separateDebugInfo = true was passed on to the srcOnly
mkDerivation as well as the outputs list _including_ the debug output.
Luckily we don't need to untangle this mess since srcOnly is only
supposed to have a single output anyways.
2022-07-02 19:32:24 +02:00
mdarocha
fb94bb0b20 src-only: pass all arguments
This allows executing postPatch and other hooks correctly
2022-06-21 12:13:38 +02:00
zimbatm
31ead7d030 srcOnly: rename buildInputs to nativeBuildInputs
The only reason to pass build inputs is to extend the unpackPhase with
custom unpack commands. Eg: add "unrar" to unpack rar sources. And those
should really be passed as native build inputs. Why? Because
nativeBuildInputs is for dependencies that are used at build time but
will not propagate as runtime dependencies. And also, cross-compilation.
2020-04-27 14:31:40 +02:00
zimbatm
bbbc419186 srcOnly: fix invocation and document
Previously, callPackage would try and fill the arguments such as `name`
and `src` which would cause problems if those existed as top-level
attributes. This also makes it clearer what part is the function
signature.

Then document the derivation inline in the code to explain the ellipsis
and various use-cases.
2020-04-22 14:06:28 +02:00
edef
11e13acc46 srcOnly: ignore additional arguments
This reverts commit b32a057425,
which breaks even the most straightforward uses of srcOnly:

    nix-repl> srcOnly guile
    error: anonymous function at /home/src/nixpkgs/pkgs/build-support/src-only/default.nix:1:1 called with unexpected argument 'drvPath', at /home/src/nixpkgs/lib/customisation.nix:69:16

    nix-repl> srcOnly hello
    error: anonymous function at /home/src/nixpkgs/pkgs/build-support/src-only/default.nix:1:1 called with unexpected argument 'drvPath', at /home/src/nixpkgs/lib/customisation.nix:69:16

Link: https://github.com/NixOS/nixpkgs/pull/80903#issuecomment-617172927
2020-04-21 13:20:17 +00:00
zimbatm
b32a057425 srcOnly: remove the ellipsis (#80903)
The function doesn't make use of the extra arguments.
2020-02-24 23:12:37 +00:00
Michael Raskin
ccf99b2ddf A helper to get the source some package is built from.
svn path=/nixpkgs/trunk/; revision=12933
2008-10-01 15:57:22 +00:00