diff options
author | Vladimír Čunát <v@cunat.cz> | 2020-05-11 08:22:59 +0200 |
---|---|---|
committer | Vladimír Čunát <v@cunat.cz> | 2020-05-11 08:22:59 +0200 |
commit | 5eaabaf08914bb6c73173aa135643eb696735f16 (patch) | |
tree | 3d8121ab4a6aee0a97b2e08cd7191c08e1a2b64d /pkgs/build-support | |
parent | f236714d65baa74404e5e25a24b6208134971752 (diff) | |
parent | 303adc76971983c0c2891d62a83065bdd79595b4 (diff) | |
download | nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar.gz nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar.bz2 nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar.lz nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar.xz nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.tar.zst nixlib-5eaabaf08914bb6c73173aa135643eb696735f16.zip |
Merge branch 'staging-next' into PR 82342
Hydra nixpkgs: ?compare=1586582
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/docker/default.nix | 55 | ||||
-rwxr-xr-x | pkgs/build-support/fetchgit/nix-prefetch-git | 1 | ||||
-rw-r--r-- | pkgs/build-support/fetchurl/builder.sh | 15 | ||||
-rw-r--r-- | pkgs/build-support/fetchurl/default.nix | 2 | ||||
-rw-r--r-- | pkgs/build-support/rust/default.nix | 18 |
5 files changed, 65 insertions, 26 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 28c0d2dfcae1..bee6e37cccbb 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -32,7 +32,29 @@ }: # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. +let + + mkDbExtraCommand = contents: let + contentsList = if builtins.isList contents then contents else [ contents ]; + in '' + echo "Generating the nix database..." + echo "Warning: only the database of the deepest Nix layer is loaded." + echo " If you want to use nix commands in the container, it would" + echo " be better to only have one layer that contains a nix store." + + export NIX_REMOTE=local?root=$PWD + # A user is required by nix + # https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478 + export USER=nobody + ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration + + mkdir -p nix/var/nix/gcroots/docker/ + for i in ${lib.concatStringsSep " " contentsList}; do + ln -s $i nix/var/nix/gcroots/docker/$(basename $i) + done; + ''; +in rec { examples = callPackage ./examples.nix { @@ -874,25 +896,16 @@ rec { # contents. The main purpose is to be able to use nix commands in # the container. # Be careful since this doesn't work well with multilayer. - buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: - let contentsList = if builtins.isList contents then contents else [ contents ]; - in buildImage (args // { - extraCommands = '' - echo "Generating the nix database..." - echo "Warning: only the database of the deepest Nix layer is loaded." - echo " If you want to use nix commands in the container, it would" - echo " be better to only have one layer that contains a nix store." - - export NIX_REMOTE=local?root=$PWD - # A user is required by nix - # https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478 - export USER=nobody - ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration - - mkdir -p nix/var/nix/gcroots/docker/ - for i in ${lib.concatStringsSep " " contentsList}; do - ln -s $i nix/var/nix/gcroots/docker/$(basename $i) - done; - '' + extraCommands; - }); + buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: ( + buildImage (args // { + extraCommands = (mkDbExtraCommand contents) + extraCommands; + }) + ); + + buildLayeredImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: ( + buildLayeredImage (args // { + extraCommands = (mkDbExtraCommand contents) + extraCommands; + }) + ); + } diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index abba76bd1ac9..43f7c5acd5ad 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -373,6 +373,7 @@ print_results() { "url": "$(json_escape "$url")", "rev": "$(json_escape "$fullRev")", "date": "$(json_escape "$commitDateStrict8601")", + "path": "$(json_escape "$finalPath")", "$(json_escape "$hashType")": "$(json_escape "$hash")", "fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false), "deepClone": $([[ -n "$deepClone" ]] && echo true || echo false), diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 74fdc320835f..e93c98419a67 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -47,13 +47,18 @@ tryDownload() { finish() { + local skipPostFetch="$1" + set +o noglob if [[ $executable == "1" ]]; then chmod +x $downloadedFile fi - runHook postFetch + if [ -z "$skipPostFetch" ]; then + runHook postFetch + fi + exit 0 } @@ -69,7 +74,13 @@ tryHashedMirrors() { --fail --silent --show-error --head "$url" \ --write-out "%{http_code}" --output /dev/null > code 2> log; then tryDownload "$url" - if test -n "$success"; then finish; fi + + # We skip postFetch here, because hashed-mirrors are + # already content addressed. So if $outputHash is in the + # hashed-mirror, changes from ‘postFetch’ would already be + # made. So, running postFetch will end up applying the + # change /again/, which we don’t want. + if test -n "$success"; then finish skipPostFetch; fi else # Be quiet about 404 errors, which we interpret as the file # not being present on this particular mirror. diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index 7d23a3a7f8f1..a0c48468dfac 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -65,7 +65,7 @@ in , # Shell code to build a netrc file for BASIC auth netrcPhase ? null -, # Impure env vars (http://nixos.org/nix/manual/#sec-advanced-attributes) +, # Impure env vars (https://nixos.org/nix/manual/#sec-advanced-attributes) # needed for netrcPhase netrcImpureEnvVars ? [] diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index b7d19ccd4a0a..aa5edc1f5bf7 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,4 +1,14 @@ -{ stdenv, cacert, git, rust, cargo, rustc, fetchCargoTarball, buildPackages, windows }: +{ stdenv +, buildPackages +, cacert +, cargo +, diffutils +, fetchCargoTarball +, git +, rust +, rustc +, windows +}: { name ? "${args.pname}-${args.version}" , cargoSha256 ? "unset" @@ -58,6 +68,10 @@ let cxxForHost="${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"; releaseDir = "target/${rustTarget}/${buildType}"; + # Specify the stdenv's `diff` by abspath to ensure that the user's build + # inputs do not cause us to find the wrong `diff`. + diff = "${diffutils}/bin/diff"; + in stdenv.mkDerivation (args // { @@ -110,7 +124,7 @@ stdenv.mkDerivation (args // { srcLockfile=$NIX_BUILD_TOP/$sourceRoot/Cargo.lock echo "Validating consistency between $srcLockfile and $cargoDepsLockfile" - if ! diff $srcLockfile $cargoDepsLockfile; then + if ! ${diff} $srcLockfile $cargoDepsLockfile; then # If the diff failed, first double-check that the file exists, so we can # give a friendlier error msg. |