nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenvNoCC }:
2
3/**
4 A utility builder to get the source code of the input derivation, with any patches applied.
5
6 # Examples
7
8 ```nix
9 srcOnly pkgs.hello
10 => «derivation /nix/store/gyfk2jg9079ga5g5gfms5i4h0k9jhf0f-hello-2.12.1-source.drv»
11
12 srcOnly {
13 inherit (pkgs.hello) name version src stdenv;
14 }
15 => «derivation /nix/store/vf9hdhz38z7rfhzhrk0vi70h755fnsw7-hello-2.12.1-source.drv»
16 ```
17
18 # Type
19
20 ```
21 srcOnly :: (Derivation | AttrSet) -> Derivation
22 ```
23
24 # Input
25
26 `attrs`
27
28 : One of the following:
29
30 - A derivation with (at minimum) an unpackPhase and a patchPhase.
31 - A set of attributes that would be passed to a `stdenv.mkDerivation` or `stdenvNoCC.mkDerivation` call.
32
33 # Output
34
35 A derivation that runs a derivation's `unpackPhase` and `patchPhase`, and then copies the result to the output path.
36*/
37
38attrs:
39let
40 args = attrs.drvAttrs or attrs;
41 name = args.name or "${args.pname}-${args.version}";
42 stdenv = args.stdenv or (lib.warn "srcOnly: stdenv not provided, using stdenvNoCC" stdenvNoCC);
43 drv = stdenv.mkDerivation (
44 args
45 // {
46 name = "${name}-source";
47
48 outputs = [ "out" ];
49
50 phases = [
51 "unpackPhase"
52 "patchPhase"
53 "installPhase"
54 ];
55 separateDebugInfo = false;
56
57 dontUnpack = false;
58
59 dontInstall = false;
60 installPhase = "cp -pr --reflink=auto -- . $out";
61 }
62 );
63in
64lib.warnIf (args.dontUnpack or false) "srcOnly: derivation has dontUnpack set, overriding" drv