12

This answer to the question Non-Root Package Managers suggests Nix as a solution. However, the installation documentation says:

The script will invoke sudo to create /nix if it doesn’t already exist. If you don’t have sudo, you should manually create /nix first as root.

I don't have permissions to do either on a target machine. Does that mean that there is no way for me to install and therefore use Nix unless sysadmin agrees to install it?

Does the same apply to Guix?

4 Answers4

7

You can try it installing nix using PRoot. Or you can build for your custom prefix:

NIX_STORE_DIR=/opt/custom/store \
NIX_STATE_DIR=/opt/custom/var/nix \
NIX_DB_DIR=/opt/custom/var/nix/db \
    nix-build ...
3

Both Nix and Guix, when building from source, allow you to pass the --with-store-dir=${alternative_store_dir} option to their configure scripts. This defaults to /nix/store and /gnu/store respectively. You can set this to somewhere you have write access to.

Be aware though that, for both, changing the store path means changing the hash of a lot of derivatives. This means that you mostly cannot use pre-built binary packages any more and will end up building (almost) everything from source.

Giel
  • 221
  • Giel (& @clacke, who commented above) could you clarify this? I see this link explaining why guix needs root: it needs chroot & setuid. So compiling with a different store, doesn't seem to change the need for root. The only way I can see to use it (almost) without root, is described in the intro here. If you can put files in /guix/store, then you can compile on a machine that has guix & copy over. If I'm missing something, I'd appreciate a full answer. – Diagon Nov 25 '19 at 19:42
  • The only way I can see this working without /guix/store being writable, is if you install guix from source using the --with-store-dir flag on a computer where you do have root. You would have to use a directory /home/uname/guix, where uname is the same as that on the machine where you don't have root. Then install the packages that interest you, and finally copy them over to /home/uname/guix on the computer where you don't have root. As with @clacke's comment, this would mean recompiling the universe from scratch. – Diagon Nov 25 '19 at 22:12
  • I think it should be possible to get rid of the chroot usage by using filesystem namespaces (unshare) which shouldn't require root permissions. I'm not sure if that is the only remaining thing requiring root though... – Giel Nov 26 '19 at 14:50
0

nix-user-chroot worked for me
https://nixos.wiki/wiki/Nix_Installation_Guide#nix-user-chroot
https://github.com/nix-community/nix-user-chroot
ps. nix commands work if shell started as login (nix-user-chroot ~/.nix bash -l); I also needed to run install script one more time from nix user to finally make it work.

amordo
  • 103
-1

You can indeed install Guix without the final make install, thus with no need of root privileges: http://dustycloud.org/blog/guix-package-manager-without-make-install/

Ehvince
  • 261
  • You still need root to create /gnu/store. – clacke Apr 13 '19 at 15:54
  • IIRC, we can set up environment variables to put the store somewhere we don't need to be root. – Ehvince Apr 14 '19 at 17:57
  • You can also recompile guix to use another store path by default, but the point is that you then have to recompile the universe from scratch, and the last time I tried back in 2014 or so it didn't even work, because some parts were making assumptions about the store path. nix run now has support for an alternate store path, but what it does is use filesystem namespaces (unshare) to mount the alternate store path at /nix/store. The equivalent could be done for guix as well, but AFAIK nobody has done it yet. – clacke Apr 15 '19 at 18:21
  • The daemon has to run as root. If you look at that link, you will see a lot of sudo's. – Diagon Nov 26 '19 at 00:33