Search code examples
haskell-stacknix

Stack build without storing output in nix store?


I've been running stack build on a project multiple times - and each time it seems to save the result in the /nix/store which requires a lot of storage over time.

Is there a way I can NOT save the result to the store?


Solution

  • No, you can't "not save the result to the store". (You can specify a different store, but that will make your problem worse -- you'll be storing an extra copy of your dependency chain in this store, and moreover, you'll be unable to download prebuilt binaries for parts of your dependency chain that are built by Nix's automated upstream build system, Hydra).

    What you should do is garbage-collect your store, which will remove items that are no longer in use (as measured by reachability from an active "gc root" -- such as the result link created by the build process, programs which are actively running, or the set of software installed in a user's profile with nix-env).

    This can be as simple as:

    nix-store --gc
    

    ...or, if you have a specific item eating up space you want to remove:

    # delete all instances of whatever, if-and-only-if they aren't reachable from a gc root
    nix-store --delete /nix/store/*-whatever