Possibility of disable substituter of a single package in NixOS

I know the --offline switch of nixos-rebuild can disable all substituters and make all the packages build from sources, but it is extremely time consuming. I am wondering if there is a way to only select one or some packages and make it or them not using binary cache and build from source while running nixos-rebuild. Some may want it for greater sense of security.

You could build the package offline before you run nixos-rebuild.

1 Like

yes lol haven’t thought about that

That won’t account for overrides or overlays in your config, if any.

The actual answer would be to override the package and set preferLocalBuild to true:

1 Like

Thanks for the answer! Haven’t know about this advanced attributes before!
After a quick search in nixpkgs repo, I see preferLocalBuild = true; and allowSubstitutes = false; have always been used together!

Do note that this won’t disable substitution of the src, to do that you’ll first need to run nix build .#package.src --substitute false (you may need to expose the package through your flake. If you’ve already downloaded it, add --rebuild and it will verify it against one actually downloaded with the fetcher.

1 Like

The src is also a derivation, which can also be overridden.