How to use nix package manager? Is it to be used as root or as user?

I’ve noticed that almost all flatpak packages that I have are also available on nix package manager and I was curious about it, so I’ve tried installing it and working with it.
I understand that for nix package manager flakes have recently gotten the popular method of installing packages instead of using channels, so I am choosing that route.

So far I’ve got:

$ guix packages -i nix

Then edit /etc/nix/nix.conf

extra-experimental-features = nix-command flakes

Now when running the first nix command, I get:

$ nix flake init
error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted

This is “solved” by turning all nix files into ownership of the user, which I think is very wrong because only one user can then use nix to install packages.

sudo mkdir $USER /nix/var/nix/{profiles,gcroots}/per-user/$USER
sudo chown $USER --recursive /nix

On top of that, using it as a user gets the nix package manager to install packages on the home folder. I don’t think I would want that.

$ nix flake init
error: '/home/user/.local/share/nix/root/nix/store/f9c35cwj3asd78n5rfyriqdhb6d0ykil-source/trivial' was not found in the Nix store
       If you've set 'defaultTemplate.path' to a string, try using a path instead.

So what is standard practice. Run nix package manager as user or as root?

I don’t know if you figured this out already, but Guix already has a system service available for Nix. It’s in the Miscellaneous services section of the manual. you can also add extra options to your nix.conf with it like this:

(service nix-service-type
  (nix-configuration
    (extra-config (list "experimental-features = nix-command flakes\n"
                        "trusted-users = root @wheel\n"))))

After that you can either add channels or use your flake if you have one. I honestly don’t remember if i also manually created a nix profile directory as explained in the manual, but that might be necessary too. when it comes to sourcing your profile, i do it in my bash_profile, but if you already have something like this in your bash_profile:

eval "$(guix package --search-paths \
-p $HOME/.config/guix/current \
-p $HOME/.guix-home/profile \
-p $HOME/.guix-profile \
-p /run/current-system/profile)"

make sure to source your nix profile AFTER this snippet. the order seems to matter. sourcing nix profile before guix sources its profiles causes nix profile stuff not to be set correctly.

1 Like