-
Notifications
You must be signed in to change notification settings - Fork 237
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
How to prevent flake devShell dependencies from being garbage collected? #2249
Comments
In addition to One can also prevent the flake sources from being GC'd: # Add a let binding below `pkgs`
inherit (pkgs) lib;
inputOutPaths = inputs:
lib.lists.unique (lib.lists.flatten (lib.lists.map (input:
if lib.attrsets.hasAttr "inputs" input then
[ input.outPath (inputOutPaths input.inputs) ]
else
input.outPath
) (lib.attrsets.attrValues inputs)
) );
# Add an environment variable to the call to `shellFor`
FLAKE_INPUTS = "${lib.strings.concatStringsSep " " (inputOutPaths inputs)}"; It would be nice if haskell.nix added an option like |
I have the following flake {
nixConfig = {
extra-substituters = "https://cache.iog.io";
extra-trusted-public-keys = "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=";
allow-import-from-derivation = "true";
};
inputs = {
flake-utils.url = "github:numtide/flake-utils";
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
};
outputs = { nixpkgs, haskellNix, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
inherit (pkgs) lib;
overlays = [
haskellNix.overlay
(final: prev: {
# This overlay adds our project to pkgs
mypackage =
final.haskell-nix.stackProject' {
src = ./.;
compiler-nix-name = "ghc948";
# This is used by `nix develop .` to open a shell for use with
# `cabal`, `hlint` and `haskell-language-server`
shell.tools = {
cabal = { };
hlint = { };
haskell-language-server = { };
hie-bios = { };
apply-refact = { };
stan = { };
weeder = { };
};
# Non-Haskell shell tools go here
shell.buildInputs = with pkgs; [
nixpkgs-fmt
ffmpeg
lilypond-with-fonts
];
# For some strange reason this allow stack to find ghc. See https://github.com/input-output-hk/haskell.nix/issues/1759.
shell.additional = ps: with ps; [ Cabal ];
stackYaml = nixpkgs.lib.mkForce "buildbot_stack.yaml";
modules = [{
packages = {
proto-lens-protobuf-types.components.library.build-tools = [ pkgs.protobuf ];
tensorflow-proto.components.library.build-tools = [ pkgs.protobuf final.haskellPackages.proto-lens-protoc ];
};
}];
};
})
];
flake = pkgs.mypackage.flake { };
inputOutPaths = inputs:
lib.lists.unique (lib.lists.flatten (lib.lists.map (input:
if lib.attrsets.hasAttr "inputs" input then
[ input.outPath (inputOutPaths input.inputs) ]
else
input.outPath
) (lib.attrsets.attrValues inputs)
) );
in
flake // {
# Built by `nix build .`
packages.default = flake.packages."mypackage:exe:mypackage";
# Override stuff here.
devShells.default = flake.devShells.default.overrideAttrs (prev: final: {
# buildInputs = [ pkgs.mypackage.roots pkgs.mypackage.stack-nix ] ++ prev.buildInputs;
FLAKE_INPUTS = "${lib.strings.concatStringsSep " " (inputOutPaths inputs)}";
});
}
);
} Adding either |
@cdfa, try swapping devShells.default = flake.devShells.default.overrideAttrs (final: prev: { |
I knew it had to be something silly! Thanks for pointing it out! :) |
After reading this, this and this, I still can't figure out how to prevent flake devShell dependencies from being garbage collected by
nix store gc
. M(N)WE:flake.nix
test.cabal
BTW if the
proj.roots
line is removed, the garbage is even larger:188 store paths deleted, 3325.91 MiB freed
Usually this isn't a huge problem because only the flake inputs are GC'd (mostly nixpkgs), but with haskell.nix the collected garbage is much larger and seems not limited to flake inputs (I might be wrong). Can someone provide a minimal example where nothing is GC'd?
The text was updated successfully, but these errors were encountered: