nixthing Get in touch

A fresh install · one command · done

NixOS, set up properly.

Flakes on, your config moved into a repository, a folder per host, home-manager wired in. Every guide agrees on the shape, and every guide takes an evening. nixthing does it in one command.

Act I

The usual way.

You've just installed NixOS and you want to do it right. So you ask, and the answer is very, very thorough.

01 · Flakes

Step one: turn on flakes.

They're how everyone does it, and they're still behind an "experimental" flag. So the first edit is to the file you're about to move.

assistant
I just installed NixOS. How do I set it up properly, with flakes?
Great choice! NixOS with flakes is a powerful combination. Let's walk through it step by step.
Step 1: enable flakes. Add this line to /etc/nixos/configuration.nix:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
Then rebuild so the setting takes effect:
$ sudo nixos-rebuild switch

02 · A repository

Then move everything.

A folder for your config, a folder per host, your two existing files copied in, ownership fixed, and a flake.nix written from scratch.

assistant
Step 2: create a repository. Move your existing configuration and hardware files into a folder per host:
$ mkdir -p ~/nix-config/hosts/laptop
$ sudo cp /etc/nixos/*.nix ~/nix-config/hosts/laptop/
$ sudo chown -R $USER ~/nix-config
Step 3: write a flake.nix at the root of ~/nix-config:
{
description = "My NixOS configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
home-manager.url = "github:nix-community/home-manager/release-26.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, home-manager, ... }: {
nixosConfigurations.laptop = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./hosts/laptop/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.you = import ./home.nix;
}
];
};
};
}

03 · home-manager

And wire in home-manager.

Another input, another module, a home.nix, and a warning about following nixpkgs that you'll only understand later.

assistant
Step 4: create home.nix for your user configuration:
{ pkgs, ... }:
{
home.username = "you";
home.homeDirectory = "/home/you";
home.stateVersion = "26.05";
programs.git.enable = true;
}
Make sure home-manager's nixpkgs input follows yours, or you'll end up with two copies of nixpkgs.
Step 5: rebuild from the flake:
$ sudo nixos-rebuild switch --flake ~/nix-config#laptop

04 · The gotcha

Then it can't find your files.

A flake only sees what git tracks, and nobody said to run git. The fix is one line, the next step, and there's always a next step.

assistant
error: getting status of '/nix/store/…-source/hosts/laptop/configuration.nix': No such file or directory
Ah, that's a common one! Flakes only see files that are tracked by git. Initialise a repository and add your files:
$ cd ~/nix-config && git init && git add .
It built. How do I add my desktop?
For each additional machine, create a new folder under hosts/, copy that machine's hardware-configuration.nix over, add another nixosConfigurations entry, and consider factoring shared settings into a common module…

That was one machine.

steps to follow
6
files written by hand
3
errors on the way
1
machines left to do
all of them

Here's the same setup, with nixthing.

Act II

The nixthing way.

The shape everyone ends up with, written for you. It's shell scripts run straight out of the repository, so there's nothing to install first.

01 · New host

One command on a fresh install.

Flakes on, a repository with git in it, this machine's two files moved into its own folder, home-manager wired in, and switched to.

~
$ nixthing new host laptop
→ flakes on
→ ~/nix-config: flake.nix, git initialised
→ hosts/laptop/configuration.nix ········· moved in
→ hosts/laptop/hardware-configuration.nix moved in
→ home-manager wired for you
→ switch.sh
✓ switched · laptop is declared

02 · What you get

The layout, already there.

A folder per host, a home for your user, and a flake that treats every machine the same way. Nothing you have to remember the shape of.

~/nix-config
$ tree
.
├── flake.nix
├── flake.lock
├── switch.sh
├── home/
│ └── you.nix
└── hosts/
└── laptop/
├── configuration.nix
└── hardware-configuration.nix

03 · The next machine

The next machine is the same line.

Run it on the desktop and it becomes a second host in the same repository, sharing your home and everything you've already declared.

~
$ nixthing new host desktop
→ hosts/desktop/hardware-configuration.nix moved in
→ added to flake.nix · shares home/you.nix
✓ switched · 2 hosts declared

04 · Every day after

And one word to switch.

switch.sh stands in for the rebuild incantation. It knows which host it's on, so it's the same command on every machine.

~/nix-config
$ ./switch.sh
→ nixos-rebuild switch --flake .#laptop
✓ generation 3
$

Act III

It's the flake you'd write.

There's no nixthing format and nothing to learn instead of Nix. It writes the ordinary flake the guides describe, so you can read it, change it, or walk away from it.

Plain Nix, in your repository.

Every host is the same function applied to its own folder, so a new machine is one line in nixosConfigurations. home-manager follows your nixpkgs, which is the warning from the chat, already handled.

flake.nix lines 1–30
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
home-manager = {
url = "github:nix-community/home-manager/release-26.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, home-manager, ... }:
let
# every host is the same shape: its own folder, the shared home
host = name: nixpkgs.lib.nixosSystem {
modules = [
./hosts/${name}/configuration.nix
home-manager.nixosModules.home-manager
{
networking.hostName = name;
home-manager.useGlobalPkgs = true;
home-manager.users.you = import ./home/you.nix;
}
];
};
in {
nixosConfigurations = {
laptop = host "laptop";
desktop = host "desktop";
};
};
}
The same setup, both ways
Measure Following a chat nixthing
Flakes, repository, hosts seven steps one command
home-manager another input and a warning wired in
The git gotcha found the hard way git is there from the start
The next machine the chat again the same command

Moving a machine to NixOS?

Tell me what you're setting up. nixthing is how every machine here got its config.

Get in touch