- Nix 68.7%
- Lua 19.3%
- Go 7%
- Shell 5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| home/greg | ||
| hosts/nixos | ||
| lib | ||
| modules/nixos | ||
| pkgs | ||
| scripts | ||
| secrets | ||
| .gitignore | ||
| .sops.yaml | ||
| CLAUDE.md | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
nix-system
NixOS + home-manager configuration for multiple hosts, built from one flake.
Layout
flake.nix inputs + list of hosts (nixosConfigurations)
lib/default.nix mkHost: wires a host dir, users, and home-manager together
hosts/<hostname>/
default.nix host entry: imports profiles/services + hardware-only settings
hardware-configuration.nix output of nixos-generate-config (don't hand-edit)
home.nix optional per-host home-manager overrides (e.g. monitors)
modules/nixos/
core/ baseline for every host (nix, locale, boot loader, network, sudo, ...)
desktop/ Hyprland + noctalia workstation (audio, fonts, greetd, printing, input, ...)
laptop/ power/lid/thermal/fingerprint
services/ opt-in, one file per service (docker, syncthing, beszel, ...)
users/<user>.nix system account for each user
secrets/<hostname>.yaml sops-encrypted secrets for one host
secrets/common.yaml sops-encrypted secrets shared by all hosts (optional)
.sops.yaml who can decrypt which secrets file
home/<user>/ home-manager config for each user (entry: default.nix)
hyprland/ apps/ dev/
scripts/ rebuild/update helpers and Hyprland debugging scripts
Usage
sudo nixos-rebuild switch --flake ~/nix-system # host picked by hostname
sudo nixos-rebuild build --flake ~/nix-system#nixos # build a specific host
nix flake update # or scripts/update.sh
Adding a host
-
On the new machine:
nixos-generate-config --show-hardware-config > hosts/<name>/hardware-configuration.nix -
Create
hosts/<name>/default.nix:{ ... }: { imports = [ ./hardware-configuration.nix ../../modules/nixos/core ../../modules/nixos/desktop # omit for servers ../../modules/nixos/services/docker.nix # pick what you need ]; networking.hostName = "<name>"; system.stateVersion = "26.05"; # release of first install } -
Give the host a secrets key (see Adding a host's key).
-
Optionally add
hosts/<name>/home.nix(e.g. its ownmonitors.lua). -
Register it in
flake.nix:<name> = mkHost { hostname = "<name>"; };(systemandusersare optional arguments.) -
git addthe new files (flakes only see tracked files), then rebuild.
Secrets (sops-nix)
Secrets are stored encrypted in secrets/*.yaml with sops
and decrypted at boot/activation by sops-nix into
/run/secrets/ (tmpfs). Plaintext never enters git or /nix/store.
There are two kinds of age keys:
| Key | Location | Used for |
|---|---|---|
| Personal (admin) | ~/.config/sops/age/keys.txt |
Editing secrets with sops |
| Host | /var/lib/sops-nix/key.txt (root only) |
The machine decrypting its secrets |
.sops.yaml lists every public key and which files each may decrypt. A host
can only read its own secrets/<hostname>.yaml and secrets/<hostname>/, the
shared secrets/common*, and secrets/users/<user>/ for its users.
Back up your personal key (password manager or similar). Without it, and without a host key, the secrets can't be recovered.
Editing secrets
sops secrets/nixos.yaml # opens $EDITOR on the decrypted file; re-encrypts on save
Files are plain YAML. Nested keys become /-separated secret names:
beszel:
token: 62ba... # -> sops.secrets."beszel/token"
Using a secret in a module
{ config, ... }:
{
# Reads from secrets/<hostname>.yaml by default.
sops.secrets."myservice/password" = {
owner = "myservice"; # default root:root 0400
restartUnits = [ "myservice.service" ];
};
# Shared secret from common.yaml instead:
# sops.secrets."wifi/home".sopsFile = ../../../secrets/common.yaml;
services.myservice.passwordFile = config.sops.secrets."myservice/password".path;
}
Only pass the secret's path to a service, never its value. If the service wants an env file or a config file with the secret inside, render it with a template:
sops.templates."myservice.env".content = ''
PASSWORD=${config.sops.placeholder."myservice/password"}
'';
services.myservice.environmentFile = config.sops.templates."myservice.env".path;
See modules/nixos/services/beszel.nix for a working example.
Remember to git add new secrets files, or the flake won't see them.
Encrypted files
Whole files (keys, certificates) are stored in sops' binary format, one secret per file:
| Location | Readable by |
|---|---|
secrets/<hostname>/ |
that host |
secrets/common/ |
all hosts |
secrets/users/<user>/ |
every host that user logs in to (see .sops.yaml) |
Create one in $EDITOR (unknown extensions like .key are stored as binary):
sops secrets/users/greg/id_ed25519
Or encrypt an existing file without copying the plaintext into the repo.
--filename-override picks the .sops.yaml rule; the binary flags matter for
.yaml/.json/.env/.ini files, which sops otherwise encrypts value by value:
sops encrypt --filename-override secrets/users/greg/id_ed25519 \
--input-type binary --output-type binary \
~/.ssh/id_ed25519 > secrets/users/greg/id_ed25519
Declare it with format = "binary" and an explicit sopsFile. For example, a
user's SSH key in modules/nixos/users/<user>.nix:
{ config, ... }:
{
sops.secrets."greg/ssh/id_ed25519" = {
sopsFile = ../../../secrets/users/greg/id_ed25519;
format = "binary";
owner = "greg"; # mode defaults to 0400
path = "/home/greg/.ssh/id_ed25519"; # symlink to /run/secrets/...
};
}
Public keys aren't secret; keep them as plain files or in Nix.
path makes a symlink, so first move any existing file at that location out
of the way (after checking the encrypted copy decrypts: sops decrypt <file>).
Adding a host's key
On the new machine:
sudo install -d -m 700 /var/lib/sops-nix
sudo age-keygen -o /var/lib/sops-nix/key.txt # prints the public key
Then on a machine with your personal key:
- Add the public key to
.sops.yamlunderkeysas&host_<name>and add acreation_rulesentry forsecrets/<name>(\.yaml|/.+)$. Also add it to thecommonrule if the host needs shared secrets, and to theusers/<user>rule of each user who logs in there. - Create the host's file:
sops secrets/<name>.yaml - Re-encrypt files whose recipients changed, e.g.
sops updatekeys secrets/common.yaml secrets/users/greg/*
If you reinstall a host and lose its key, generate a new one, replace it in
.sops.yaml, and run sops updatekeys on its files.
Rotating a leaked secret
Removing a secret from git doesn't remove it from history. Change the value at
its source (for example a new token in the service's UI), then sops the file
and replace it.