4 ms·
My issue with Nix is that you are forced to install packages in a global location. Why is it that every package manager assumes I’m an administrator on my machi
by bshacklett 3y ago
My issue with Nix is that you are forced to install packages in a global location. Why is it that every package manager assumes I’m an administrator on my machine? Even if I am, how does it make sense to take over a global directory as a single user?
- miniBill 3y agoNix does not require you to be an administrator to install a package though!
- raunakchhatwal 3y agoI think he may be referring to installing Nix itself, which does require root even if the intention isn't to install anything system-wide. I did once think about modifying the nix installer to let me set an arbitrary nix store because I wanted nix packages in a docker container I was debugging, but never really got around to it. Let me know if you know of somebody else who tried this.
- iFreilicht 3y agoSo this is possible, but there are a lot of caveats. First, the installer itself explicitly says: ``` # Please don't change this. We don't support it, because the # default shell profile that comes with Nix doesn't support it. readonly NIX_ROOT="/nix" ``` I haven't seen any configurations where the entire /nix is relocated, but nix _does_ support relocating the store with the environment variable `NIX_STORE_DIR`.[1] However, this means that you can no longer use the the binary cache and *everything* you install has to be compiled from scratch, including glibc. The reason is that nix usually patches paths like `/bin/myprogram` to `/nix/store/1238f...-myprogram-1.2.3/bin/myprogram` in everything that depends on `myprogram` during build time to isolate the build outputs from the system. If you change your store, all those paths will now be invalid, including the hash part. So using a nix store that isn't `/nix/store` is possible, but I don't think anyone is actually doing it except in a few select scenarios. You can also compile nix itself with a different root. That will work as expected, but you still have the issue that you need to compile everything you install yourself. [1]: https://nixos.org/manual/nix/stable/command-ref/env-common.html?highlight=NIX_STORE#env-NIX_STORE_DIR https://nixos.org/manual/nix/stable/command-ref/env-common.h... (you can also relocate most other directories. The `prefix` in the paths is `/nix`)
- bshacklett 3y agoNow that's interesting. I use Homebrew in a similar way. It does mean I have to compile a lot of things from scratch, but Homebrew has knowledge of which packages are relocatable and which aren't, so I get to use binary "bottles" for about 25% of the packages I install. I'll have to give this a try.
- watermelon0 3y agoHomebrew is the same, there is no good way to have Homebrew installation shared among multiple users on a single machine, much less to have separate packages for each of them.
- bshacklett 3y ago> ...there is no good way... Agreed, but it's at least possible. My usual install is just cloning Homebrew to ~/homebrew and setting up a symlink. It's far from ideal, due to the number of packages I need to build from source, but it works, and it's allowed me to function normally in tightly controlled environments. As far as I can tell, the initial installation for Nix doesn't allow this, though iFreilicht pointed out some options that I haven't seen before, so I may be wrong.
- pxc 3y agoNix leverages hardcoded paths inside the binaries and other outputs it builds in order to ensure determinacy. Nix packages are not always trivially relocatable. Consequently, reliance on the binary caches means different users have to rely on the same path to the Nix store, since it's part of all those outputs. You can build Nix with a custom store prefix and run it that way if you're willing to build from source. In practice, Linux users don't really have to contend with that tradeoff because you can relocate a Nix store wholesale using a bind mount, or a user namespace (unprivileged chroot), or various fakeroot tricks to run a Nix store in your homedir as if it lives in /nix. Unfortunately macOS just doesn't have any of those mechanisms. If macOS some day gets first-class container support and, consequently, relevant user-facing primitives for user-mode chroot, then unprivileged, cache-friendly Nix installation methods for macOS will doubtless follow. I hope both happen!
- pxc 3y agoI have a bad habit of writing user-mode when I mean 'unprivileged' in the sense of 'not as root' and I don't think the word really works that way. I did it again here! Whoops.
- n8henrie 3y agoOnly true for MacOS though, Linux supports a proper single-user no-root install.
- bshacklett 3y agoInteresting. Would you mind elaborating? I'd love to give this a try, but I'm not having luck finding documentation on how to do it.
- n8henrie 3y agohttps://nixos.org/download.html#nix-install-linux https://nixos.org/download.html#nix-install-linux
- johnklos 3y agoTry pkgsrc. You can run it wherever you like, as an unprivileged user.