nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 97 lines 3.3 kB view raw
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 argsToOverride = args: { 41 name = "${args.name or "${args.pname}-${args.version}"}-source"; 42 43 outputs = [ "out" ]; 44 45 phases = [ 46 "unpackPhase" 47 "patchPhase" 48 "installPhase" 49 ]; 50 separateDebugInfo = false; 51 52 dontUnpack = lib.warnIf (args.dontUnpack or false 53 ) "srcOnly: derivation has dontUnpack set, overriding" false; 54 55 dontInstall = false; 56 installPhase = "cp -pr --reflink=auto -- . $out"; 57 58 # the original derivation might've set something like outputDev = "lib", but "lib" isn't an output anymore 59 # some things get confused and error if one of these is set to an output that doesn't exist 60 # ex: pkgs/build-support/setup-hooks/multiple-outputs.sh 61 outputDev = "out"; 62 outputBin = "out"; 63 outputInclude = "out"; 64 outputLib = "out"; 65 outputDoc = "out"; 66 outputDevdoc = "out"; 67 outputMan = "out"; 68 outputDevman = "out"; 69 outputInfo = "out"; 70 }; 71in 72 73# If we are passed a derivation (based on stdenv*), we can use overrideAttrs to 74# update the arguments to mkDerivation. This gives us the proper awareness of 75# what arguments were effectively passed *to* mkDerivation as opposed to 76# builtins.derivation (by mkDerivation). For example, stdenv.mkDerivation 77# accepts an `env` attribute set which is postprocessed before being passed to 78# builtins.derivation. This can lead to evaluation failures, if we assume 79# that drvAttrs is equivalent to the arguments passed to mkDerivation. 80# See https://github.com/NixOS/nixpkgs/issues/269539. 81if lib.isDerivation attrs && attrs ? overrideAttrs then 82 attrs.overrideAttrs (_finalAttrs: prevAttrs: argsToOverride prevAttrs) 83else 84 let 85 # If we don't have overrideAttrs, it is extremely unlikely that we are seeing 86 # a derivation constructed by stdenv.mkDerivation. Since srcOnly assumes 87 # that we are using stdenv's setup.sh, it therefore doesn't make sense to 88 # have derivation specific logic in this branch. 89 # TODO(@sternenseemann): remove drvAttrs special casing in NixOS 26.05 90 args = 91 lib.warnIf (lib.isDerivation attrs) 92 "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." 93 attrs.drvAttrs or attrs; 94 stdenv = args.stdenv or (lib.warn "srcOnly: stdenv not provided, using stdenvNoCC" stdenvNoCC); 95 drv = stdenv.mkDerivation (args // argsToOverride args); 96 in 97 drv