The original post: /r/debian by /u/hellociaagent on 2025-03-13 13:18:54.

Overview

Apt often does not have the latest packages or the latest versions of packages. One can use the Nix package manager, Flatpak, snaps, or even Homebrew to solve this.

I’m creating this post to boost and introduce nix-setup-systemd, a Debian package that uses systemd mechanisms to setup the nix package manager. I found this method easier to manage than using a Nix install script. Unfortunately, documentation for this method is scarce, so I include my steps below for future reference. This guide builds on this article.

Installation

As root, install the package and add your user to the group nix-users.

sudo apt install nix-setup-systemd sudo adduser $(whoami) nix-users

Here, you should logout and login again, such as by:

sudo su $(whoami)

Then, as user:

nix-channel --add https://nixos.org/channels/nixpkgs-unstable nix-channel --update

Installing packages

Using librewolf as example:

nix-env -iA librewolf

This is same as:

nix-env --install --attr librewolf

Removing packages

nix-env -e librewolf

Path

To find the packages you install via Nix, you should add the path to your shell. It also helps to set XDG_DATA_DIRS.

export PATH=$PATH:$HOME/.nix-profile/bin
export XDG\_DATA\_DIRS="$HOME/.nix-profile/bin:$HOME/.nix-profile/share:$XDG\_DATA\_DIRS"

If this works for you, add it to your .bashrc.

Errors

If you get error: opening lock file ‘/nix/var/nix/profiles/per-user/root/profile.lock’: Permission denied then rm ~/.nix-profile and try again. This is probably because you tried to use nix-env or nix-channel or something while root (source).

Maintenance

To keep your Nix packages up to date:

nix-channel --update nix-env -u nix-collect-garbage -d

GUI Apps

While some articles suggest that GUI apps may not work so well, I have no problem so far.