Introduction
From the 26.05 release notes:
The system.nix file has been added as an alternative entry point to configuration.nix (and flake.nix) that allows configuring NixOS without using
nix-channel.
Motivated by this thread, which the source of most of what I wrote here, Iβve switched one of my machines from channels to npins and I wrote down the steps for myself. After a few days of updates without issues, I have applied it to another machine successfully and thought it could be useful to others.
My starting point
- A git repository with one directory per machine, letβs say laptop+desktop. The repo is checked out as root in
/etc/nixosand I have a symlink to/etc/nixos/laptop/configuration.nix. Certainly not the most elegant or sophisticated setup, but it has worked for me for a few years now. - home-manager imported as a nixos module (aka
<home-manager/nixos>)
βββ common
β βββ git.nix
β βββ neovim.nix
βββ configuration.nix -> desktop/configuration.nix
βββ laptop
β βββ configuration.nix
βββ desktop
β βββ configuration.nix
βββ hardware-configuration.nix
Migration steps
- Add
npinsto systemPackages, ensure the system is up-to-date, find out exactly which channels are in use vianix-channel --list. - Initialize npins in the machineβs subdirectory, not globally in the repo since each machine will eventually have its own npins:
npins init --barethennpins add --name nixpkgs channel nixos-26.05. - Create a
/etc/nixos/desktop/system.nixfile as explained in the release notes but using npins:
let
sources = import ./npins;
in
import "${sources.nixpkgs}/nixos" {
configuration = ./configuration.nix;
}
Then add a new symlink to it in /etc/nixos/, run nixos-rebuild switch to confirm that it works so far, it should result in the same system as in step 1.
- Add home-manager:
npins add --name home-manager github nix-community home-manager -b release-26.05
and changeconfiguration.nixto import npins and use it for home-manager:
let
sources = import ./npins;
in
{
imports = [
/etc/nixos/hardware-configuration.nix
"${sources.home-manager}/nixos"
];
(...)
- Add the nixPath setup and a symlink in
configuration.nixas recommended by @rnhmjoj (thank you!)
nix = {
nixPath = [
"nixos-config=/etc/nixos/configuration.nix"
"nixos-system=/etc/nixos/system.nix"
"nixpkgs=/run/current-system/nixpkgs"
];
};
system.systemBuilderCommands = "ln -s ${sources.nixpkgs} $out/nixpkgs";
- Do a
nixos-rebuild switchand re-open your shell to ensure$NIX_PATHis the new one. - Clear the channels
nix-channel --remove home-manager,nix-channel --remove nixos - Disable channels by adding
nix.channel.enable = false;toconfiguration.nixand do another rebuild. - Remove the channel remnants found by
nixos-rebuild, if any. For me that meantrm /nix/var/nix/profiles/per-user/root/channelswhich just contained an emptymanifest.nixafter previous step.
And thatβs it!
The diff on the repository is really small, configuration.nix: 6 new and 1 modifiedlines.
Then thereβs a new 6 lines long system.nix and the npins stuff.
After that
nixos-rebuild switch --upgradebecomescd /etc/nixos/desktop && npins update && nixos-rebuild switchnixos-rebuild switchstill works as before
Result
βββ common
β βββ git.nix
β βββ neovim.nix
βββ configuration.nix -> desktop/configuration.nix
βββ laptop
β βββ configuration.nix
βββ desktop
β βββ configuration.nix
β βββ npins
β β βββ default.nix
β β βββ sources.json
β βββ system.nix
βββ hardware-configuration.nix
βββ system.nix -> desktop/system.nix