Fedora

Install Nix Package Manager on Fedora 45 / 44 with SELinux

Fedora’s own nix package installs with one dnf command, and then the daemon socket refuses to start. On Fedora 45 and Fedora 44 with SELinux enforcing, systemctl enable --now nix-daemon.socket fails with Permission denied. Nothing in Fedora’s policy labels /nix, and systemd is not allowed to create a socket in an unlabeled directory. The package’s README says to enable the daemon and never mentions SELinux.

Original content from computingforgeeks.com - post 199218

This guide follows one install from the RPM to a working multi-user setup, starting with the two SELinux file contexts the package does not ship. After that come nix profile, flakes (already switched on), a standalone Home Manager, and an uninstall that really removes everything. Every command below ran on Fedora 45 and Fedora 44 cloud VMs with SELinux enforcing in November 2026, using the distro’s Nix 2.35.6 build.

Fedora ships Nix as split RPMs

The nix package in the Fedora updates repo is an empty metapackage that pulls in the real pieces. You don’t need the upstream curl installer or the Determinate Systems installer, and dnf upgrades Nix like any other package, so there is no second update channel to watch. Fedora 43 and EPEL 10 carry the same split at the older 2.31.6, so the packaging is not new to Fedora 44. Each subpackage owns one layer, in the order you’ll touch them:

  1. nix-core: the nix CLI, /etc/nix/nix.conf and the single-user profile script
  2. nix-filesystem: /nix and its tmpfiles rules
  3. nix-system: the nixbld group and ten build users
  4. nix-daemon: the socket and service units and /etc/profile.d/nix-daemon.sh
  5. nix-legacy: nix-env, nix-shell and the other old commands

The daemon and legacy packages are weak dependencies of nix, so a plain install brings them in. If you want the multi-user setup this guide builds, there’s nothing extra to name on the command line.

sudo dnf install -y nix

On Fedora 45 that resolved to 23 packages and 22 MiB on disk. The daemon, the legacy tools and busybox came in as weak dependencies, and the sysusers scriptlet created the build users during the transaction. Now look at the labels on the directories the package just created.

ls -ldZ /nix /nix/store /nix/var/nix/daemon-socket

All three carry default_t, the type SELinux gives a path no policy rule describes:

drwxr-xr-x. 1 root root   system_u:object_r:default_t:s0 16 Nov 29 16:19 /nix
drwxrwxr-t. 1 root nixbld system_u:object_r:default_t:s0  0 Nov 10 00:00 /nix/store
drwxr-xr-x. 1 root root   system_u:object_r:default_t:s0  0 Nov 29 16:19 /nix/var/nix/daemon-socket

One word explains both SELinux failures in this guide. Confined domains like init_t, which is systemd itself, are allowed almost nothing on default_t, because the policy treats an unknown path as something no service should touch. Fedora’s targeted policy has no file context entries for /nix at all, so every file the package and the daemon create starts out unknown. Interactive commands do not notice, since your shell runs unconfined, and that is why the problem only appears once systemd gets involved.

The daemon socket fails under SELinux

In multi-user mode, every nix command you run talks to nix-daemon over a Unix socket. The daemon then does the builds and store writes as root, so your user never needs write access to /nix/store. The README enables nix-daemon, the service. This guide uses socket activation instead: systemd creates the socket, not the daemon, and starts the daemon only when a client connects. Enable the socket unit.

sudo systemctl enable --now nix-daemon.socket

The symlink gets created, then the job fails. The unit status says it failed with Result: resources, and the journal lines under it name the real problem:

nix-daemon.socket failing with Permission denied and Result resources on Fedora 45 with SELinux enforcing

How does root get Permission denied writing into a directory root owns? Unix permissions are not the check that failed. SELinux is, and the same failure happened on Fedora 44 with its own policy build. Running setenforce 0 made the socket start, which proves the cause, but you shouldn’t keep a box in permissive mode for a package manager. In order, this is what happens when the socket starts:

  1. systemd reads nix-daemon.socket
  2. PID 1, running as init_t, creates the socket file
  3. SELinux checks init_t against the default_t directory
  4. the create is denied and the unit fails

nix-daemon.socket: Failed to create listening socket (/nix/var/nix/daemon-socket/socket): Permission denied

A plain ausearch -m AVC -ts recent came back empty on these VMs even though the denial was logged. Reading the log files directly with --input-logs found it.

sudo ausearch --input-logs -m AVC -ts today -c systemd | grep sock_file

PID 1 tried to create a sock_file named socket in a default_t directory and got denied:

type=AVC msg=audit(1795968419.855:776): avc:  denied  { create } for  pid=1 comm="systemd" name="socket" scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=sock_file permissive=0

Give the socket directory var_run_t, the type systemd already uses for runtime sockets, with a persistent file context rule. Use semanage fcontext rather than chcon, because a chcon label is lost on the next relabel and the socket would fail again after an autorelabel boot.

sudo semanage fcontext -a -t var_run_t '/nix/var/nix/daemon-socket(/.*)?'
sudo restorecon -Rv /nix/var/nix/daemon-socket
sudo systemctl enable --now nix-daemon.socket

restorecon reports the relabel from default_t to var_run_t, and the socket goes to active (listening) with SELinux still enforcing:

SELinux AVC for the nix daemon socket, the var_run_t fcontext rule and nix-daemon.socket listening on Fedora 45

The Determinate Systems installer ships a small SELinux module that makes the same choice for this path, which you can read in its nix.fc file. If other denials on your box are confusing you, our SELinux survival guide for Fedora walks through reading AVCs and choosing between a boolean, a label and a module.

Any user can reach the daemon

You might expect a nix-users group to join before Nix lets you in. Fedora’s packaging does not create one: getent group nix-users returns nothing, and the socket is mode srw-rw-rw-. A regular wheel user with no group changes and a fresh login can query the store straight away.

nix store info

Store URL: daemon means your commands go through the socket, and Trusted: 0 means you’re an ordinary client:

Store URL: daemon
Version: 2.35.6
Trusted: 0

Untrusted is the right default for a workstation. You can install anything from the binary cache, but you cannot add substituters or turn off signature checks. A compromised user account therefore cannot poison the store for everyone else. nix config show reports allowed-users = * and trusted-users = root. Only touch trusted-users if you run your own cache and know which accounts should be allowed to point the daemon at it.

The package’s config file already holds the settings most upstream guides ask you to add by hand. Read it once before you change anything.

cat /etc/nix/nix.conf

Six lines, and flakes are already among them:

auto-optimise-store = true
bash-prompt-prefix = (nix:$name)\040
experimental-features = nix-command flakes
extra-nix-path = nixpkgs=flake:nixpkgs
max-jobs = auto
ssl-cert-file = /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

Four of those lines change how Nix behaves for you on day one:

  • flakes and the new nix command are on
  • identical store files get hard-linked as the store fills
  • nixpkgs resolves through the flake registry
  • downloads trust Fedora’s CA bundle

The CA line matters more than it looks. Because Nix reads Fedora’s extracted bundle, a corporate CA you add with update-ca-trust applies to Nix downloads too, so you won’t need a separate NIX_SSL_CERT_FILE behind a TLS-inspecting proxy. Nothing in this guide requires editing the file.

nix profile replaces nix-env

nix profile add is the current way to install a package for your user. nix profile install still works but prints a warning that it’s a deprecated alias, and nix-env -iA belongs to the legacy tooling. Log out and back in first if you installed Nix in this session, because /etc/profile.d/nix-daemon.sh only adds the profile directory to PATH at login. Without a new login, the package lands in your profile but your shell has no path to it. Then install something small.

nix profile add nixpkgs#hello

The first run took 37 seconds, and most of that was not the download. Nix fetched and unpacked the whole nixpkgs-unstable tarball into its Git cache before it could evaluate one package, then pulled five store paths (8.7 MiB, including its own glibc):

First nix profile add nixpkgs#hello on Fedora 45 taking 37 seconds and running hello from the Nix profile

Notice where hello resolved: ~/.nix-profile/bin/hello, a symlink into ~/.local/state/nix/profiles/profile. The scripts in /etc/profile.d put two Nix directories in front of the system ones at login. Your PATH after a fresh login is searched in this order:

  1. ~/.local/bin and ~/bin
  2. ~/.nix-profile/bin
  3. /nix/var/nix/profiles/default/bin
  4. /usr/local/bin, then /usr/bin

So a Nix package with the same name as a Fedora one wins in your shell. That’s what you want for a newer ripgrep, and a nasty surprise if you put Nix’s python3 in your profile and a dnf-installed script starts using it. Keep language runtimes in nix shell or a flake instead, because those only change PATH for the shell you start them in. The day-to-day profile commands are few.

nix profile add nixpkgs#jq nixpkgs#ripgrep
nix profile list
nix profile history
nix profile remove hello
nix profile rollback
nix profile upgrade --all

Each change writes a new profile generation, so rollback after remove hello brought hello straight back without downloading anything. Old generations keep their store paths alive, though, which is why the store never shrinks on its own. Disk only comes back when you drop the history and collect garbage.

nix profile wipe-history
nix store gc

On this small profile the collector deleted 794 paths and freed 2.5 MiB, taking the store from 66M to 62M. Those numbers grow quickly once flakes and Home Manager are involved: /nix had reached 2.2G by the end of this lab, and none of it lived under /var or /home. If your root filesystem is small, put /nix on its own volume before the first install rather than after.

System units need the store labeled bin_t

Interactive use works on default_t store files. The second denial only appears when a confined domain tries to execute something from /nix/store, and three different contexts touch the store on this setup:

  1. your shell, as unconfined_t: runs store binaries fine
  2. nix-daemon, as unconfined_service_t: writes the store fine
  3. a systemd unit, starting as init_t: denied on default_t

A one-shot service that runs hello straight from the store reproduces the third case. Create the unit:

sudo vim /etc/systemd/system/nixhello.service

Put the store path that readlink -f "$(command -v hello)" prints on your machine in ExecStart. This is the unit as tested:

[Unit]
Description=Run hello from the Nix store

[Service]
Type=oneshot
ExecStart=/nix/store/dcg4mi1h810kl0q5skk995b8nb2idg1g-hello-2.12.3/bin/hello

Reload systemd and start the unit while the store is still default_t.

sudo systemctl daemon-reload
sudo systemctl start nixhello.service

It fails with status=203/EXEC, which systemd reports when it can’t execute the binary at all. The AVC shows systemd denied execute on a default_t file:

avc:  denied  { execute } for  pid=12432 comm="(hello)" name="01al4cmwkg7716wiiazpygfkl142vp358p7kh1lr29ay2m9bqip6" dev="sda3" ino=402431 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=file permissive=0

Labeling the whole store bin_t clears it. That’s broader than the Determinate policy, which keeps bin_t for bin and sbin directories and gives libraries, unit files and data their own types. On a workstation the coarse rule is fine, because everything in the store is already world-readable and the only new permission is execute for confined domains. On a server that runs confined services against Nix paths, copy the finer policy instead, so a service can’t execute a data file it was only meant to read.

sudo semanage fcontext -a -t bin_t '/nix/store(/.*)?'
sudo restorecon -R /nix/store
sudo systemctl start nixhello.service

The relabel took 0.118 seconds on a small store, the unit then finished cleanly, and a jq path added afterwards came out bin_t with no second restorecon:

systemd unit failing with status 203/EXEC on a Nix store binary, fixed by labeling /nix/store bin_t on Fedora

New paths inherit the type because the daemon creates them inside an already-labeled directory, and that held on Fedora 44 too with a tree path added after the rule. Both were downloads from the binary cache; if a unit still gets 203/EXEC on a path Nix built locally, run sudo restorecon -R /nix/store again. Do you need this rule at all? Not if Nix only ever runs from your shell. Add it the first time a unit, timer or service fails with 203/EXEC on a /nix/store path, and remove the test unit once you’ve seen it work.

sudo rm /etc/systemd/system/nixhello.service
sudo systemctl daemon-reload

Both rules you added are listed by sudo semanage fcontext -l -C, which shows only local customizations. Keep that command in mind, because you’ll need the same two patterns again at uninstall time.

nix shell runs tools without installing

Most tools you only need once do not belong in a profile. Nix gives you four levels of commitment, and picking the lowest one that works keeps your profile small:

  • nix run: one program, one time
  • nix shell: a shell with packages on PATH
  • nix develop: a project’s shell, defined in a flake
  • nix profile add: stays until you remove it

The first two leave nothing behind except store paths, which the next garbage collection removes. Compare a Nix Python with Fedora’s own:

nix run nixpkgs#cowsay -- "hello from nix"
nix shell nixpkgs#python313 -c python3 --version
/usr/bin/python3 --version

The Nix shell had Python 3.13 while Fedora’s interpreter stayed at 3.15. That’s the use case: an older runtime for one project, without touching /usr/bin.

Python 3.13.18
Python 3.15.2

On a minimal cloud image, Perl-based tools like cowsay first print a block of perl: warning: Setting locale failed lines, ending in Falling back to the standard locale ("C"). Nix’s Perl brings its own glibc and doesn’t find a locale it can load for en_US.UTF-8. The output below the warning is still correct, and the whole run took under 3 seconds, including the 11.6 MiB download.

A flake pins one project’s toolchain

A flake is a directory with a flake.nix and a lock file that records the exact nixpkgs revision. Nix reads a flake in a Git repo through Git, so you need Git first, and the Fedora Cloud image does not include it.

sudo dnf install -y git
mkdir -p ~/hello-flake
cd ~/hello-flake
git init

Create the flake file in that directory:

vim flake.nix

This flake defines one development shell with Go and jq from nixos-unstable.

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs }:
    let
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
    in {
      devShells.x86_64-linux.default = pkgs.mkShell {
        packages = [ pkgs.go pkgs.jq ];
      };
    };
}

What happens when you run nix flake show right away? Nix refuses, because it only sees files Git tracks. Stage the file, run the show again, then enter the shell and run a command inside it.

git add flake.nix
nix flake show
nix develop -c go version

The successful nix flake show fetched nixpkgs and wrote flake.lock, which pinned it to revision 78cc855f from 27 November. With that done, building the shell took 35 seconds:

nix flake show failing on an untracked flake.nix, then nix develop printing the Go version on Fedora 45

Commit both flake.nix and flake.lock. Anyone who clones the repo then gets the same Go and jq builds until somebody runs nix flake update, whatever Fedora release they’re on, because the lock names a nixpkgs commit and a hash instead of a branch. That is the whole reason to use a flake over nix shell: the second machine gets the same answer as the first.

error: Path ‘flake.nix’ in the repository is not tracked by Git

That’s the error from the untracked file above. Nix copies a Git flake into the store from the Git index, so an untracked file doesn’t exist as far as it is concerned. The message suggests git add -N "flake.nix", and a normal git add works too. You don’t need to commit, since Nix only prints warning: Git tree ... is dirty until you do.

Home Manager owns your user config

Home Manager turns your packages and dotfiles into one declared configuration. On Fedora you use it standalone, with no NixOS underneath, and bootstrap it straight from its flake.

nix run home-manager/master -- init --switch

This was the slowest step at 1 minute 50 seconds: 107 paths, a 76.2 MiB download and 258 MiB unpacked. It tracks nixpkgs-unstable and the Home Manager master branch, and writes three files under ~/.config/home-manager/:

  • flake.nix: the inputs and your user’s configuration
  • flake.lock: the pinned revisions
  • home.nix: the file you’ll actually edit

Every switch then printed this warning:

trace: warning: You are using

  Home Manager version 26.11 and
  Nixpkgs version 27.05.

It is a calendar gap, not a broken install. Nixpkgs had already branched its next release, so unstable reports the release after that, while Home Manager master still calls itself the earlier one. Both sides are rolling branches here, so the mismatch fixes itself when Home Manager cuts its branch. Leave the warning, or set home.enableNixpkgsReleaseCheck = false; once you’ve read it. Now declare some packages and a Git identity.

vim ~/.config/home-manager/home.nix

Inside the generated home.packages = [ ... ]; list, add the two packages:

    pkgs.htop
    pkgs.tree

Then add this block under programs.home-manager.enable = true;, before the closing brace:

  programs.git = {
    enable = true;
    settings.user = {
      name = "Kenneth";
      email = "[email protected]";
    };
  };

Apply it. The second switch reused the cached inputs and finished in 11 seconds.

home-manager switch
home-manager generations

Home Manager wrote ~/.config/git/config for you, and both tools resolve from your profile:

home-manager switch activating a new generation with htop, tree and git config on Fedora 45

Look at the activation lines in that capture, where Home Manager swaps its home-manager-path profile entry. It does not add htop and tree as separate profile entries; that single package bundles everything you declared. That detail causes the one error you’ll almost certainly hit. If you already keep dotfiles in Git with something like Chezmoi, pick one tool per file, or the two will overwrite each other on every switch.

error: An existing package already provides the following file

Once Home Manager manages tree, adding it again by hand with nix profile add nixpkgs#tree collides with the bundled package:

nix profile add error: an existing package already provides the file, colliding with home-manager-path

The suggested --priority flags make the error go away, but they hide the real problem: two tools now own the same command, and the next home-manager switch decides which one you get. Pick one owner per package. Once you use Home Manager, add packages to home.nix and keep nix profile add for things you’ll remove within the week.

dnf remove leaves most of Nix behind

Removing the RPMs takes out 22 MiB of binaries and leaves nearly everything they created. After dnf remove on Fedora 45, these were still on disk:

  • /nix with the whole store, 2.2G here
  • an empty /etc/nix
  • ~/.nix-profile, ~/.nix-defexpr and ~/.cache/nix
  • the nixbld group and its ten users
  • both SELinux file context rules

If you use Home Manager, remove it first while Nix still works, so it can unlink the files it generated. It ends with Home Manager is uninstalled but your home.nix is left untouched.

home-manager uninstall

Next, stop the daemon and remove the packages by name. On Fedora 45, removing just nix and nix-daemon took the other subpackages along as unused dependencies. Naming all six still helps, because dnf never autoremoves a package you once installed by name.

sudo systemctl disable --now nix-daemon.socket nix-daemon.service
sudo dnf remove -y nix nix-core nix-daemon nix-system nix-filesystem nix-legacy

Everything else is manual. Delete the store and config, your per-user state, the build accounts and the two SELinux rules.

sudo rm -rf /nix /etc/nix
rm -rf ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.local/state/nix ~/.local/state/home-manager ~/.cache/nix ~/.config/nix ~/.config/home-manager
for i in $(seq 1 10); do sudo userdel nixbld-$i; done; sudo groupdel nixbld
sudo semanage fcontext -d '/nix/store(/.*)?'
sudo semanage fcontext -d '/nix/var/nix/daemon-socket(/.*)?'

Run the home directory line for every user who used Nix. On Fedora 44 the full sequence left no /nix, no profile link, no nixbld entries and no local fcontext rules:

Full Nix uninstall on Fedora 44: dnf remove, deleting /nix, nixbld users and the SELinux fcontext rules

Log out and back in afterwards. The profile scripts are gone, but your current shell still has the Nix directories in PATH until a new login rebuilds it, so a stale command -v can point at files that no longer exist.

Where each Nix piece lives on Fedora

Keep this map. It lists what owns each path, the SELinux type it needs for the setup above, and whether dnf remove cleans it up.

PathCreated bySELinux typeRemoved by dnf
/usr/bin/nixnix-corebin_t (policy default)Yes
/nix/var/nix/daemon-socketnix-daemon (tmpfiles), systemdvar_run_t (your rule)No
/nix/storenix-system (directory), nix-daemon (contents)bin_t (your rule, for units)No
/etc/nix/nix.confnix-corepolicy defaultFile yes, directory no
nixbld group and usersnix-system sysusersn/aNo
~/.nix-profilefirst nix profile adduser_home_tNo
~/.config/home-managerhome-manager inithome directory defaultNo

Read it top to bottom when something breaks. A failed socket means the second row lost its label, a 203/EXEC from a unit means the third row did, and a command that runs the wrong version means ~/.nix-profile/bin sits ahead of /usr/bin in PATH. If Nix is your first step on a new machine, our Fedora 45 post-install checklist covers the rest, and the dnf cheat sheet handles the packages that should stay on the Fedora side. To run Nix as the whole OS, see NixOS on Proxmox VE, or try it first in a VM on KVM on Fedora. The Home Manager manual lists every option home.nix accepts.

Keep reading

How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Fedora How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Things to Do After Installing Fedora 45 Workstation Fedora Things to Do After Installing Fedora 45 Workstation Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Fedora Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Fedora Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Install .NET 10 on Fedora 45: Minimal API, systemd, SELinux Fedora Install .NET 10 on Fedora 45: Minimal API, systemd, SELinux What is New in Fedora 45: Features, Changes and Release Date Fedora What is New in Fedora 45: Features, Changes and Release Date

Leave a Comment

Press ESC to close