Installing the same / nix directory on multiple machines

I want to install software sequentially using the nix package manager on several openSUSE machines (different versions) of the same architecture. I am not root in any of the systems, but I would like to convince our sysadmin to install nix in multi-user mode on all machines using network mount.

  • Is it possible to install the same /nix directory on all machines and run nix in multi-user mode on all these machines?

  • Will nix-env -i interfere with other machines?

  • Can nix-env -i xxx install xxx in the user profiles of all machines or only on the machine where the command was run? How about those installed by root ?

  • Does garbage collection on one machine collect software installed on other machines?

+5
source share
1 answer
  • You can install Nix storage on multiple computers to share binary files between many hosts with similar architectures. If /nix is available on all of these machines, each of them can use the installed packages in much the same way that they will be used if they are installed locally.

    Now that multiple machines are writing to the same Nix store at the same time, it will only work reliably if your underlying network file system supports network file locking properly. This may sound innocuous, but in my experience most network file systems do not actually support file locking, and I assume that if you try to accomplish this feat, then you will encounter a problem sometimes in the form of dead locks and / or inconsistent storage .

  • nix-env -i - and all other nix-xxx commands are general - synchronize access to all resources in /nix/store and /nix/var , so several operations performed do not interfere with each other (provided that the file system provides reliable synchronization ) If one user runs nix-env -i on two machines at the same time, then he will certainly encounter a race condition, because one of the two teams will cancel the effect of the other. This phenomenon also occurs when you run two nix-env -i commands on the same machine at the same time, but this is not a common storage problem.

  • nix-env -i changes the user environment on all hosts simultaneously. The user profile ~foo/.nix-profile is a symbolic link in the shared repository in /nix/var/nix/profiles/per-user/foo/profile , so changes made to this profile on the same machine will be visible on all other cars. root like any other user in this regard.

  • Yes, nix-collect-garbage will work on any of the computers sharing the storage. Since shared user profiles are also available, a full usage / dependency graph is seen by the tool, and no storage paths will ever be garbage collected that still reference the user profile.

    In other words, these are temporary environments such as those created for nix-shell or nix-build . Nix records the existence of these environments, symbolically binding from /nix/var/nix/gcroots to the corresponding path on the local hard drive, that is, in the place where the temporary environment lives. Such an environment is considered dead if this symbolic link becomes obsolete, i.e. If the "real path" of the Nix environment disappears. Now, if the user enters the nix-shell environment on machine A, then a symbolic link will be created, created in /nix/var/nix/gcroots , which indicates, say, /run/user/1000/nix-shell-environment-1 . However, the garbage collector running on machine B will not find this path and will consider the environment dead, therefore removing the symlink from /nix/var/nix/gcroots and the main storage paths from /nix/store . If this happens, then an active nix-shell environment running on A will suddenly stop working.

+5
source

Source: https://habr.com/ru/post/1239031/


All Articles