[Nix-dev] continuing downloads - how to use impureEnvVars ?

Marc Weber marco-oweber at gmx.de
Thu Jul 9 01:12:08 CEST 2009


> I like the idea! On by default but option available to turn off if
> undesired (Can't honestly see why that would be the case.) Testing it
> might be fun. :)

I'd like to try my first very basic implementation, however
NIX_CONTINUE_DOWNLOADS isn't passed to the builder?
Does impureEnvVars work with NIX_BUILD=daemon as well?

  (patch against nixpkgs)

  diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh
  index 22ba25e..d72428d 100644
  --- a/pkgs/build-support/fetchurl/builder.sh
  +++ b/pkgs/build-support/fetchurl/builder.sh
  @@ -19,12 +19,23 @@ curl="curl \
   
   
   tryDownload() {
  +    echo "NIX_CONTINUE_DOWNLOADS $NIX_CONTINUE_DOWNLOADS"
       local url="$1"
       echo
       header "trying $url"
       success=
  -    if $curl --fail "$url" --output "$out"; then
  -        success=1
  +    if test -n "$NIX_CONTINUE_DOWNLOADS"; then
  +      cache_file="/var/nix-downloads/$outputHash"
  +      touch $cache_file; 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"
  +          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 00b7f3c..ed6d21a 100644
  --- a/pkgs/build-support/fetchurl/default.nix
  +++ b/pkgs/build-support/fetchurl/default.nix
  @@ -97,6 +97,14 @@ stdenv.mkDerivation {
       # This variable allows the user to override hashedMirrors from the
       # command-line.
       "NIX_HASHED_MIRRORS"
  +
  +    # 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
  +    # once
  +    "NIX_CONTINUE_DOWNLOADS"
     ] ++ (map (site: "NIX_MIRRORS_${site}") sites);
   
     inherit showURLs mirrorsFile;

Sincerly
Marc Weber



More information about the nix-dev mailing list