- Nix 94.3%
- Shell 5.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| modules | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
NixOS configuration (dendritic pattern, flake-parts)
One repo for the whole laptop: system, Home Manager, Niri, DMS and the programs I use. Organized by feature, not by module type.
How it works
flake.nixdeclares inputs and callsflake-partswithimport-tree ./modules. It never lists features.- Every
.nixfile undermodules/is a flake-parts module. import-tree finds them automatically. Non-.nixfiles (likeconfig.kdl) sit next to them and are ignored. Paths containing/_are skipped. - Files write NixOS and Home Manager modules into a shared registry:
flake.modules.nixos.<target>andflake.modules.homeManager.<target>. Several files can write to the same target and the module system merges them. - Targets are
laptop(the NixOS host) anddimi(the Home Manager user). A feature enables itself just by existing in the tree. - New files must be
git added before Nix can see them.
Layout
flake.nix inputs + mkFlake (inputs can only live here)
modules/
flake-parts.nix plumbing: flakeModules.modules, systems
hosts/laptop/ assembles the machine (configuration.nix, hardware.nix)
users/dimi/ the account and Home Manager baseline, general packages
system/ host-wide plumbing, one flat file per concern
features/ one directory per tool, with native config files beside it
Rule of thumb: a directory when a tool has companion files (config.kdl,
foot.ini), a flat file for plumbing.
Native configs stay native (KDL, INI, JSONC, fish). Home Manager links them
with xdg.configFile."<path>".source = ./file; and they are read-only store
symlinks.
Daily use
nh os switch # rebuild and activate
nh os test # activate without making it the boot default
nh os boot # build for next boot
nh clean all # garbage collect (also runs weekly)
nix flake update # update inputs, then switch
Checks before switching:
git add -A
nixos-rebuild build --flake .#laptop
Adding a feature
- Create
modules/features/<name>/default.nix. - Write into the registry:
{
flake.modules.nixos.laptop = { /* system part */ };
flake.modules.homeManager.dimi = { pkgs, ... }: { /* user part */ };
}
- Put native config files next to it and link them with
xdg.configFile. git add -A, thennh os switch.
Header rules: the outer function header ({ inputs, config, ... }:) is only
needed if the file reads from flake-parts. The inner header ({ pkgs, ... }:)
is only needed if the module uses NixOS or Home Manager arguments.
To disable a feature, move its directory out of modules/ or prefix it with
_.
Reinstalling from scratch
Boot the NixOS installer, then:
-
Partition, format and mount the target at
/mnt(boot partition at/mnt/boot). -
Clone this repo, for example into
/mnt/home/dimi/nixos. -
Regenerate the hardware config. Disk UUIDs change on a fresh install, so the committed
hardware.nixwill not boot.nixos-generate-config --root /mnt --show-hardware-configPaste the output into
modules/hosts/laptop/hardware.nix, inside the wrapper and without the generated file's own header line:{ flake.modules.nixos.laptopHardware = { config, lib, pkgs, modulesPath, ... }: { # body of the generated file goes here }; } -
Install from the flake:
git add -A nixos-install --flake /mnt/home/dimi/nixos#laptopIf flakes are not enabled in the installer, run it with
NIX_CONFIG="experimental-features = nix-command flakes". -
Set the password before rebooting, and fix ownership of the clone:
nixos-enter --root /mnt -c 'passwd dimi' nixos-enter --root /mnt -c 'chown -R dimi:users /home/dimi/nixos' -
Reboot and log in. Restore personal data from backup.
The repo is expected at ~/nixos (programs.nh.flake points there).
First-switch notes
- The old generation stays in the systemd-boot menu. The timeout is 1 second: tap Space or an arrow key at power-on to pick an older generation.
Ctrl+Alt+F2gives a text login if the greeter or Niri fails.home-manager.backupFileExtension = "backup"renames pre-existing files that would block Home Manager. If a.backupalready exists at the same path, delete it by hand.system.stateVersionandhome.stateVersionmust never be changed.