From 10f6c2592c715c500310a5071b47684c0ab48b29 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Thu, 16 Jul 2009 15:18:26 +0000 Subject: [PATCH] adding NIX_CONTINUE_DOWNLOADS feature, see mkdir comment svn path=/nixpkgs/trunk/; revision=16401 --- pkgs/build-support/fetchurl/builder.sh | 15 +++++++++++++-- pkgs/build-support/fetchurl/default.nix | 14 +++++++++++++- pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 22ba25e90a4..a8cc325c403 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -23,8 +23,19 @@ tryDownload() { echo header "trying $url" success= - if $curl --fail "$url" --output "$out"; then - success=1 + cache_file="/var/nix-downloads/$outputHash" + if { test -n "$NIX_CONTINUE_DOWNLOADS" && touch "$cache_file";}; then + chmod g+w $cache_file # ensure another nixbld user can continue! + # no locking is taking place. I think nix builder locking is enough + if $curl --fail "$url" -C - --output "$cache_file"; then + mv "$cache_file" "$out" + chmod g-w $out # ensure another nixbld user can continue! + success=1 + fi + else + if $curl --fail "$url" --output "$out"; then + success=1 + fi fi stopNest } diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index 00b7f3cc079..9118b290226 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -1,7 +1,7 @@ # Argh, this thing is duplicated (more-or-less) in Nix (in corepkgs). # Need to find a way to combine them. -{stdenv, curl}: # Note that `curl' may be `null', in case of the native stdenv. +{stdenv, curl, getConfig ? (x: y : "")}: # Note that `curl' may be `null', in case of the native stdenv. let @@ -86,6 +86,18 @@ stdenv.mkDerivation { if sha256 != "" then "sha256" else if sha1 != "" then "sha1" else "md5"; outputHash = if outputHash != "" then outputHash else if sha256 != "" then sha256 else if sha1 != "" then sha1 else md5; + + + + # set this to any value to make nix dowload into /var/nix-downloads/$hash + # so that it can continue a half finished download after a shudown, + # susupend to disk, shutdown etc + # for this to work you have to run + # d=/var/nix-downloads; mkdir $d; chgrp nixbld $d; chmod g+x $d; + # once + # defaulting to enabled because continuing takes place only if $d exists + # and has proper permissions + NIX_CONTINUE_DOWNLOADS = getConfig ["NIX_CONTINUE_DOWNLOADS"] "1"; impureEnvVars = [ # We borrow these environment variables from the caller to allow diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6b090462f06..3185d55060a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -282,7 +282,7 @@ let # from being built. fetchurl = useFromStdenv "fetchurl" (import ../build-support/fetchurl { - inherit curl stdenv; + inherit curl stdenv getConfig; }); # fetchurlBoot is used for curl and its dependencies in order to