Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large files within source tree causes build to run out of memory #358

Closed
gulrotkake opened this issue Sep 29, 2014 · 18 comments · Fixed by #4030
Closed

Large files within source tree causes build to run out of memory #358

gulrotkake opened this issue Sep 29, 2014 · 18 comments · Fixed by #4030
Assignees

Comments

@gulrotkake
Copy link

If the size of a file or a sufficient number of files in a nix-build exceeds the amount of memory available, Nix runs out of memory and gives up. For example, given this simple build:

{ stdenv, pkgs, ... } :

stdenv.mkDerivation rec {
  name = "huge";
  src = ./.;
  buildInputs = [ ];
  buildPhase =
    ''
        md5sum huge.bin > md5.result
    '';

  installPhase =
   ''
     mkdir $out
     mv md5.result $out
  '';
}

where huge.bin is a very huge file, nix will first warn:

warning: dumping very large path (> 256 MiB); this may run out of memory

before eventually running out of memory.

The above was tested with

nix-build (Nix) 1.8pre3834_9b146a5
@edolstra
Copy link
Member

edolstra commented Oct 6, 2014

As a workaround, you could use fetchurl to get the file, e.g. fetchurl { src = file:///bla/huge; sha256 = ...; }.

@shlevy
Copy link
Member

shlevy commented Dec 14, 2014

Bonus feature: hole detection to avoid spurious reads.

@edolstra
Copy link
Member

I don't think there are many realistic use cases where a Nix source file contains holes...

@domenkozar
Copy link
Member

It would be nice if it printed out the file name

@sjmackenzie
Copy link

Agreed, the file name would be most handy.

@sjmackenzie
Copy link

We have 50 instances of src = ./. each time the ./. points to the root of a rust project which consists of 4 files, one of which is in a folder called src. We have no instances of a large file/binary called with ./., just many (and growing quickly) instances of (./.).

@Ericson2314
Copy link
Member

Why does it even read the files into memory at once? I assume the hash can be computed with constant space.

@sjmackenzie
Copy link

For the record, we found the cause: it was a .target folder generated by the rustc compiler. Deleting that folder straightened nix again.

@domenkozar
Copy link
Member

@Ericson2314 #619

@domenkozar
Copy link
Member

Until this is fixed in Nix see https://nixos.org/wiki/How_to_add_files_to_the_nix-store#Large_files

@ip1981
Copy link

ip1981 commented Feb 3, 2017

As a workaround, you could use fetchurl to get the file, e.g. fetchurl { src = file:///bla/huge; sha256 = ...; }.

There might be permission problem.

@fisx
Copy link

fisx commented Sep 28, 2017

Until this is fixed in Nix see https://nixos.org/wiki/How_to_add_files_to_the_nix-store#Large_files

dead link, and it looks like this page does not exist on https://nixos.wiki/?

@dpc
Copy link

dpc commented Nov 2, 2017

Is there any way to make src = ./. except for ./target;?

@sjmackenzie
Copy link

take a look at cleanSource and filterSource

@dpc
Copy link

dpc commented Nov 2, 2017

src = builtins.filterSource (p: t: lib.cleanSourceFilter p t && baseNameOf p != "target") ./.;

I think this is it, in case anyone lands here from google search.

@langston-barrett
Copy link
Contributor

I am also experiencing this problem while trying to install Mathematica.

Here's the old Wiki page on archive.org in case anyone else is searching for it: https://web.archive.org/web/20160829175307/https://nixos.org/wiki/How_to_add_files_to_the_nix-store

@bgamari
Copy link
Contributor

bgamari commented Dec 21, 2017

This is addressed by #619.

@Pitometsu
Copy link

Looks as a solution for me: https://stackoverflow.com/a/39493330/3195266

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.