How to properly build into custom store path?

I’m struggling to find documentation for the right way to build things into custom store path.

Currently I’m trying with

NIX_STORE_DIR=/opt/foobar/store \
NIX_STATE_DIR=/opt/foobar/var/nix \
NIX_DB_DIR=/opt/foobar/var/nix/db \
nix-build --store /opt/foobar

Are all of those environment flags and options required or is something still missing?

Simple things build fine, but for more complex things, I’ve seen build failures with is not in nix store or is not allowed to refer to the following paths. So, possibly something is still missing from my options and the default /nix/store and custom paths get mixed.

A particular issue was that pinning nixpkgs with { pkgs ? import (fetchTarball { ... }) {} failed with is not in nix store unless I replaced builtins.fetchurl with --arg pkgs 'import((import <nixpkgs> {}).pkgs.fetchFromGitHub{...}) {}'. But more of the simlar issues remain when build progresses…

(a long period of trying things out)

It seems that I got a working built into custom paths with the command above after replacing all custom use of builtins.fetchurl with pkgs.fetchurl, adapted my code to their differences and added netrcPhase, bacause only builtins.fetchurl works with nix netrc-file-option.

I wonder, what is missing in the command above that builtins.fetchurl does not work as expected with a custom store?

1 Like