This repository contains my personal NixOS configuration, structured using a dendritic pattern powered by flake-parts and import-tree.
This architecture allows for modular evaluation of standard flake outputs, splitting features, overlays, packages, and host configurations into distinct files that are elegantly discovered through import-tree rather than manually maintained arrays of imports.
Every .nix file under modules/ is a flake-parts module picked up automatically by import-tree, so adding a feature only means creating a file (and git add-ing it, since flakes only see tracked files). Each file defines one flake.nixosModules.<name> or flake.homeModules.<name>; hosts then choose which ones to import.
modules/
├── parts.nix # flake-parts setup (systems, home-manager flake module)
├── common/ # reusable across hosts
│ ├── bundles/ # bundle* modules grouping related features (core-system, desktop, dev)
│ ├── nixos/ # NixOS features (one per file, e.g. fonts, sound, noctalia)
│ ├── home/ # home-manager features (hm*, e.g. hmGit)
│ ├── overlays/ # nixpkgs overlays; default.nix applies all of them
│ └── packages/ # local packages exposed under `packages.<system>`
└── hosts/
└── nixos-pc/
├── default.nix # nixosConfigurations.nixos-pc: the only place listing imported modules
├── configuration.nix # host settings (hostname, locale, nix settings, …)
├── hardware.nix # generated by nixos-generate-config
├── user.nix
├── features/ # nixosPc* modules specific to this machine (firewall, sudo, suspend, packages, …)
└── home/hiepnh/ # home-manager config for hiepnh on this host
| Kind | Location | Module name |
|---|---|---|
| Common NixOS feature | common/nixos/foo-bar.nix |
nixosModules.fooBar |
| Common home-manager feature | common/home/hm-foo.nix |
homeModules.hmFoo |
| Bundle | common/bundles/foo.nix |
nixosModules.bundleFoo / homeModules.bundleFoo |
| Host-specific module | hosts/<host>/features/foo.nix |
nixosModules.<host>Foo (e.g. nixosPcFirewall) |
Common modules should not hardcode a user or machine; set those values from the host (e.g. services.fcitx5-lotus.user in hosts/nixos-pc/configuration.nix).
Some flake inputs (fcitx5-jot, jotty, keywave, unda, wayshadow) are private GitHub repositories fetched over SSH, so the installer needs an SSH key registered on GitHub before it can evaluate the flake. Prebuilt binaries of these packages are served from justanoobcoder.cachix.org, so they are downloaded instead of rebuilt (as long as the cache was pushed after the last rebuild).
The steps below work from the minimal (no desktop) NixOS ISO. GitHub login uses the device flow, so you only need a phone or another device with a browser.
Boot the ISO, connect to the network, then become root (nixos-install runs as root, so the SSH key must belong to root):
sudo -i
nix-shell -p gh gitgh auth loginAnswer the prompts:
- Where do you use GitHub? →
GitHub.com - Preferred protocol for Git operations? →
SSH - Generate a new SSH key? →
Yes(optionally set a passphrase) - Title for your SSH key → something identifiable, e.g.
nixos-installer - How would you like to authenticate? →
Login with a web browser
gh prints a one-time code. Open https://github.com/login/device on your phone, enter the code and approve. gh then uploads the new public key to your GitHub account.
Verify:
ssh -T git@github.comPartition and mount the target disk under /mnt as usual (see the NixOS manual).
mkdir -p /mnt/home/hiepnh
git clone git@github.com:justanoobcoder/nixcfg.git /mnt/home/hiepnh/.nixcfgIf the hardware differs from the previous machine, regenerate it and merge the relevant parts (filesystems, kernel modules, etc.) into modules/hosts/nixos-pc/hardware.nix:
nixos-generate-config --root /mnt --show-hardware-confignixos-install --flake /mnt/home/hiepnh/.nixcfg#nixos-pcSet the root password when prompted, then set the user password:
nixos-enter --root /mnt -c 'passwd hiepnh'The key generated in step 2 lives in the live environment's RAM and is lost on reboot. Either copy it to the new system:
mkdir -p /mnt/home/hiepnh/.ssh
cp ~/.ssh/id_ed25519* /mnt/home/hiepnh/.ssh/
nixos-enter --root /mnt -c 'chown -R hiepnh:users /home/hiepnh/.ssh /home/hiepnh/.nixcfg && chmod 600 /home/hiepnh/.ssh/id_ed25519'Or, after rebooting, run gh auth login again as hiepnh to create a new key, and delete the nixos-installer key from https://github.com/settings/keys.
Run rebuilds as your user (not sudo nixos-rebuild) so private inputs are fetched with your own SSH key:
nixos-rebuild switch --flake ~/.nixcfg#nixos-pc --sudoAfter updating the private inputs (or nixpkgs) and rebuilding, push the new builds so the next reinstall can download them:
nix path-info -r /run/current-system | grep -E 'jot|jotty|keywave|unda|wayshadow' | grep -v -- '-source$'
cachix push justanoobcoder <store paths of the main packages>