How to install Nix on Fedora Silverblue
This post has been updated now that my contributions to the Determinate Nix installer have been released.
There is a lot to like about Fedora Silverblue. Updates are atomic and if there is something wrong with the newest version, you can always roll back. You always move between immutable images of your operating system, but that also means that installing packages with dnf
doesn't work anymore. For GUI applications, the answers to this are flatpak
and its app store flathub. For everything else you can enter a mutable Fedora container with the help of toolbx. There, the dnf
command is readily available and can be used as usual. This is convenient for development, but not necessarily outside it. Whenever you want to use an installed CLI tool, you now have to enter the toolbx beforehand. Also, there are a couple of system directories that are inaccessible from within the container.
Nix
Nix is a cross-platform package manager with the largest repository at the time of this writing. Like with Silverblue, upgrades in Nix are atomic and can be rolled back. In order to install it, we run the Determinate Nix installer:
|
To get started using Nix, open a new shell or run source nix-daemon.sh
as shown below:
Now you can install tools on your machine with nix-env
. If that's all you want, then you can skip over to the last section.
Home Manager
Home Manager is a tool that allows declarative configuration of user specific packages and dotfiles. This not only helps you to keep track which changes you made to your user environment, but also greatly reduces the amount of work necessary to migrate to a new machine. Convinced? Then let's get started!
First, we add the nixpkgs-unstable
and home-manager
channels.
Then we update our nix-channels.
Now we can install home-manager
with nix-shell
.
You can edit its config file by executing:
This should open your editor with a couple of values already set. In the following snippet you see:
- how to set your git data with useful extra config, and
- how to ensure that a set of nix packages is installed.
{ config, pkgs, ... }:
{
# Leave `home.username`, `home.homeDirectory`, `home.stateVersion`
# and `programs.home-manager.enable` as they are
# Set git config
programs.git = {
enable = true;
userName = "Julian Hofer";
userEmail = "julianhofer@gnome.org";
extraConfig = {
init = {
defaultBranch = "main";
};
pull = {
rebase = true;
};
rebase = {
autostash = true;
};
};
};
# Ensure that the following packages are installed
home.packages = with pkgs; [
bat
fd
gh
glab
ripgrep
];
}
Now we activate our config file by executing
This also means that if you remove a setting or package in the config file, it will be removed on your system as well.
In order to update your environment run:
Distrobox
Distrobox is a tool that creates container that are tightly integrated with the host. This makes it perfect for development tasks.
First install distrobox.
Enter your distrobox with:
Distrobox mounts /nix
inside of your container. This way you can continue using Nix and the apps you've installed with it. To see if everything is working as expected, you can try to view your git config with the cat-replacement bat
:
You can find the discussion at this Mastodon post.