Search code examples
darwinulimitnix

How do I set the ulimit in a nix build shell?


I am attempting to install the certbot package for nix, and it fails during the tests every time because the tests hit the open file limit on the system. I have modified the certbot install script just enough to print out the ulimit at the beginning of the patchPhase and find that the maximum number of allowed open files is 256. However, in the shell from which I am executing nix-shell or nix-env, my ulimit (both hard and soft) is set to 100000.

How can I propogate that limit down to the certbot build process? I would like to avoid trying to figure out how to modify the python build script that certbot uses.

Running a Bash shell on OSX 10.13.


Solution

  • Manually raise the ulimit in the patchPhase stanza of certbot.nix. Turns out that this change propogates through the rest of the phases in the certbot build script.

      buildInputs = [ dialog ] ++ (with python2Packages; [ nose mock gnureadline ]);
    
      patchPhase = ''
        ulimit -n 8196
        substituteInPlace certbot/notify.py --replace "/usr/sbin/sendmail" "/run/wrappers/bin/sendmail"
        substituteInPlace certbot/util.py --replace "sw_vers" "/usr/bin/sw_vers"
      '';
    
      postInstall = ''
    

    I will submit a patch to nixpkgs.