Nix-store --import does not prevent build?

Hi all,

I create a simple setup with two machines.

A fast builder one, and a slower one.
Both machine have the same nix store, in particular: /cvmfs/
Having a custom store path, everything is build from scratch, I am ok with that.

I build bash on the fast machine, it took a while, it builds GCC, etc, but eventually it worked.

Now I would like to install the package bash into the slower machine.

I exported the closure from the fast machine:

$ nix-store -qR  /cvmfs/

$ nix-store --export $(nix-store -qR  /cvmfs/ > bash.closure

I moved the bash.closure in the slow machine using scp.
And finally I imported the closure back.

nix-store --import < bash.closure

Everything worked correctly, and indeed in the slow machine I now see the store populated with the directory I would expect.

$ ll /cvmfs/
total 32
drwxr-xr-x 7 redbeardlab redbeardlab 4096 Nov 30 23:42 ./
drwxr-xr-x 3 redbeardlab redbeardlab 4096 Nov 30 23:42 ../
drwxr-xr-x 2 redbeardlab redbeardlab 4096 Nov 30 23:42 .links/
dr-xr-xr-x 6 redbeardlab redbeardlab 4096 Jan  1  1970 45j96ybrkc8b4dyn73k1h2wnlbfrglir-glibc-2.31/
dr-xr-xr-x 4 redbeardlab redbeardlab 4096 Jan  1  1970 4rsxigbrnrcjlvkrwags4w8vn4l0p957-bash-5.0-p17/
dr-xr-xr-x 3 redbeardlab redbeardlab 4096 Jan  1  1970 ch9axn8z538896ky2dh835lm54zf9whn-libunistring-0.9.10/
dr-xr-xr-x 4 redbeardlab redbeardlab 4096 Jan  1  1970 ifxlq9j8hmj5303252q6cgb8wb5gccz3-libidn2-2.3.0/

However, if in the slow machine I try to install bash nix-env -i bash, it tries to compile everything from scratch.

$ nix-env -i bash                                                      
installing 'bash-5.0-p17'                                                                                                                                                                                   
these derivations will be built:                                                                                                                                                                            

Why this happens?

I was hoping that the slow machine would just create the necessary symlinks without building any software.

How can this be checked?

most likely, the two machines are at two different points on their nix-channel. So nix-env -i bash is resolving to a different .drv . You’ll want to look at FAQ/Pinning Nixpkgs - NixOS Wiki if you’re trying to pin two machines to the same point in time.

1 Like

This is helping! Thanks!

However, both machines are using the 20.09 release.

$ nix-channel --list

Can this still happening? How do I check that the .drv are indeed different?

On the slow machine I can see that nix is trying to build /cvmfs/ which is also present in the store of the fast machine /cvmfs/ and it is also the only bash-5.0 in the whole store.

Or wait, in order to build I had to disable the sandbox, setting sandbox = false in the config.

Can this be the culprit?

Being on the same channel does not mean that they are on the same point in time in that channel.
Try this command and compare the output to see which git commits they are currently booting into:

$ nixos-version
20.09.2063.f900be57309 (Nightingale)

However that is not the version used to install programs. Assuming you have a pretty standard install, try this command:

$ cat /nix/var/nix/profiles/per-user/root/channels/nixos/.version*

Then compare the output.
If you need them to be on the exact same version, use pinning as mention by jonringer above.
If you just want to use one system to build the configuration for both systems, that’s possible as well, either manually or automatic.
Be aware that cross compiling is another challenge and may be more complicated, so if you got two x86_64 systems that’s fine, but if one of them is e.g. a Raspberry Pi or an Apple Mac, that’s a different story.

Unfortunately I am not on NixOs, and nixos-version does not seems installed.

The channels are on the same suffix, they were NOT, I update both and now they are.

$ cat /cvmfs/ 

I recreate the closure but they are identical.

And the outcome is exactly the same, the closures are imported, but when I got to install nix-env -i bash it tries to build everything from scratch.