Package building in flake despite provided substitutes

Hello!

I have a flake setup like the one below:

{
    nixConfig = {
        extra-substituters = "https://cache.nixos.org https://hydra.nixos.org https://nrdxp.cachix.org https://nix-community.cachix.org";
        extra-trusted-public-keys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs= nrdxp.cachix.org-1:Fc5PSqY2Jm1TrWfm88l6cvGWwz3s93c6IOifQWnhNW4= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=";
        extra-experimental-features = "nix-command flakes";
    };

    inputs = rec {
        nixos-unstable.url = "https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz";
        nixos-21-11.url = "https://nixos.org/channels/nixos-21.11/nixexprs.tar.xz";
        j.url = github:shadowrylander/nixpkgs/j;
        nixpkgs.follows = "j";
        ...
    };

    outputs = inputs@{ ... };
}

And an overlay list like the one below:

(let
    channel = "master";
    pkgsets = {
        nixos-unstable = [ "bash" ];
        nixos-21-11 = [ "gcc" ];
    };
in mapAttrsToList (
    pkgchannel: pkglist: map (
        pkg: (final: prev: {
            "${pkg}" = if (pkgchannel == channel) then prev.${pkg} else allpkgs.${pkgchannel}.${pkg};
        })
    ) pkglist
) pkgsets)

I updated the flake lockfile, accepted the nixConfig options, and then tried to install a new system using configuration.nix and flake-compat (so no need for nixUnstable), but while bash is being taken from the binary cache, gcc is still being built locally, regardless of whether I take it from nixos-unstable or nixos-21-11, and the nix-build process is ultimately killed with no error code.

How do I make sure everything in the overlay is taken from the cache, while building everything else?

Thank you kindly for the help!

I don’t know why gcc always builds from source, but by default packages are built in /tmp so you are probably running out of memory. As a work around, nix-daemon can be told to use a different directory by setting the TMPDIR environment variable in nix-daemon’s systemd service file.

1 Like

Got it; I’ve taken to mounting a larger drive as /tmp instead, which seems to be working for the moment!