Skip to content

Instantly share code, notes, and snippets.

@dezren39
Forked from matthewpi/README.md
Created May 14, 2022 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dezren39/00d24b1b4d06f6ff221e329d2db8078e to your computer and use it in GitHub Desktop.
Save dezren39/00d24b1b4d06f6ff221e329d2db8078e to your computer and use it in GitHub Desktop.
NixOS on Fedora

NixOS on Fedora

Please note that these instructions are not offically supported or condoned by Nix and are not guaranteed to always work, but from my testing everything seems to work perfectly fine.

These steps may not be required if NixOS/nix#2374 is resolved.

SELinux

These commands are required for both Fedora Workstation and Fedora Silverblue

sudo semanage fcontext -a -t etc_t '/nix/store/[^/]+/etc(/.*)?'
sudo semanage fcontext -a -t lib_t '/nix/store/[^/]+/lib(/.*)?'
sudo semanage fcontext -a -t systemd_unit_file_t '/nix/store/[^/]+/lib/systemd/system(/.*)?'
sudo semanage fcontext -a -t man_t '/nix/store/[^/]+/man(/.*)?'
sudo semanage fcontext -a -t bin_t '/nix/store/[^/]+/s?bin(/.*)?'
sudo semanage fcontext -a -t usr_t '/nix/store/[^/]+/share(/.*)?'
sudo semanage fcontext -a -t var_run_t '/nix/var/nix/daemon-socket(/.*)?'
sudo semanage fcontext -a -t usr_t '/nix/var/nix/profiles(/per-user/[^/]+)?/[^/]+'

If you are on Fedora Workstation, skip past the Fedora Silverblue section down to Install Nix

Fedora Silverblue

If you are running Fedora Silverblue, you will need to follow these extra steps.

Create the nix directory in a persistent location

sudo mkdir /var/nix

/etc/systemd/system/mkdir-rootfs@.service

[Unit]
Description=Enable mount points in / for ostree
DefaultDependencies=no
ConditionPathExists=!%f

[Service]
Type=oneshot
ExecStartPre=chattr -i /
ExecStart=mkdir -p '%f'
ExecStopPost=chattr +i /

/etc/systemd/system/nix.mount

[Unit]
After=mkdir-rootfs@nix.service
Wants=mkdir-rootfs@nix.service

[Mount]
What=/var/nix
Where=/nix
Options=bind
Type=none

[Install]
WantedBy=local-fs.target

/etc/systemd/system/nix-boot.service

[Unit]
Description=Start nix-daemon.socket after nix.mount
Requires=nix.mount

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl daemon-reload
ExecStartPost=/usr/bin/systemctl start nix-daemon.socket

[Install]
WantedBy=multi-user.target

Enable and mount the nix mount and reset the SELinux context.

# Ensure systemd picks up the newly created units
sudo systemctl daemon-reload
# Enable the nix mount on boot.
sudo systemctl enable nix.mount
# Mount the nix mount now.
sudo systemctl start nix.mount
# Enable the nix-boot service so Nix is loaded by systemd on boot properly
sudo systemctl enable nix-boot.service
# R = recurse, F = full context (not just target)
sudo restorecon -RF /nix

Install Nix

After you have configured SELinux (and if you are on Silverblue, configured a /nix mount), it's time to install Nix.

sh <(curl -L https://nixos.org/nix/install) --daemon

You have just installed Nix and should be ready to rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment