# NixOS flake: Hyprland + Noctalia gaming desktop Declarative NixOS for one AMD desktop (`desktop`, user `faumaray`), installable from a USB stick with a single command. The canonical remote is Gitea: (`origin`). GitHub (, remote `github`) is a secondary remote. ## Features - **Flake** in the dendritic layout (flake-parts + import-tree) with home-manager, agenix, disko, lanzaboote, nixos-hardware and Stylix. - **Hyprland** (from its own flake, current git) under UWSM with the **Noctalia v5** shell, WezTerm, Neovim, zsh + starship and Dolphin. **SDDM** is a Catppuccin Wayland greeter with the Stylix wallpaper: there is no autologin, you type the password at every boot and it also unlocks the keyring. Neovim is configured by your own `nvim` repository, taken as a pinned flake input (see Neovim). - **Stylix theming**: Catppuccin Mocha, Monaspace Radon and Noto fonts, Bibata cursor, Papirus icons and one wallpaper for GTK, Qt, the TTY, Hyprland, Noctalia, the login screen, WezTerm, Obsidian, the command-line tools and every other program Stylix supports (`autoEnable`), all from one file. - **Gaming**: Steam with Proton-GE, gamescope, gamemode, MangoHud; Hyprland rules start Proton games fullscreen and float their launchers. - **Notes**: Obsidian with a declarative vault (`~/Documents/Notes`), pinned community plugins and git backup to Gitea, readable by Claude Code (see Obsidian). - **Full AMD**: AMD CPU, Radeon GPU (Mesa, LACT, optional ROCm). - **Network**: proxy-suite (zapret, Telegram WebSocket proxy, and an **AmneziaWG split tunnel** (global TProxy) that sends the Claude/Anthropic and ChatGPT/OpenAI domains, plus a few other sites listed in `aiDomains`, through the tunnel and everything else directly, except the networks zapret2 cannot unblock, which go through it as well; a manual full-tunnel profile `vpn` uses the same config and hands back to the split tunnel when it stops), AmneziaVPN, NetworkManager with the OpenVPN plugin. - **Dev**: composable **dev shells** for Rust (fenix), C/C++ (Clang or GCC) and Vulkan, entered with `dev` or activated per directory by direnv; Docker (rootless and rootful), a Gitea Actions runner, **nix-ld** and AppImage support for binaries built for other distros, and **Claude Code** with the codebase-memory-mcp, Serena, REA, NixOS and Context7 MCP servers, the nil and rust-analyzer language servers, codebase-memory-mcp's skill and graph agents, the Context7 skill, hooks (rtk, nixfmt, notifications, codebase-memory-mcp and Serena), a status line, deny rules for secrets and caveman. - **Disks via disko, btrfs, no encryption**: - NVMe: ESP (`/boot`, 2G) + btrfs `nixos` with `@root @home @nix @log @swap` (16G swapfile). - SATA SSD: btrfs `data`, one subvolume per folder, mounted into the home: `~/Games ~/Downloads ~/Documents ~/Music ~/Pictures ~/Videos ~/Storage`. - **Secure Boot** with lanzaboote (keys in `/var/lib/sbctl`). - **Secrets** with agenix, decrypted by the machine's SSH host key (`/etc/ssh/ssh_host_ed25519_key`). Every secret is optional. - **Installer**: `install-system` (also `nix run .#install`) and a bootable ISO with this repository baked in (`nix build .#iso`). ## Layout ``` flake.nix inputs and nixConfig; outputs = flake-parts over import-tree of modules/ flake.lock pinned inputs (committed) modules/ every .nix file below is a flake-parts module (import-tree) flake/ glue: systems, meta (shared data), hosts -> nixosConfigurations, overlays, packages, apps, dev shell, dev shells (shells.nix), formatter, checks users/ meta.owner: the user's identity (faumaray.nix) core/ the `core` aspect every host imports: nix, boot, locale, networking, users, home-manager, facts for install-system boot/ secure-boot (lanzaboote) or systemd-boot hardware/ amd (CPU, GPU, LACT), rocm (optional, not imported by desktop) security/ secrets (agenix), ssh (server and client) network/ vpn (AmneziaVPN), proxy-suite (zapret, Telegram proxy, AmneziaWG split tunnel and full-tunnel profile) dev/ docker, gitea-runner, nix-ld (foreign binaries, AppImage), dev-shells (the `dev` helper), shells/ (rust, cpp, vulkan, rust-cpp) desktop/ hyprland (+ its Lua files), sddm (login screen), noctalia, audio, fonts, wezterm, xdg, apps, obsidian theme/ stylix: scheme, fonts, cursor, icons, wallpaper, targets switched off cli/ shell, git, neovim (the nvim input) gaming/ steam ai/ claude-code (+ claude-statusline.sh, its status line, and codebase-memory/, codebase-memory-mcp's skill and agents) installer/ the installer ISO hosts/desktop/ host.nix (aspects + host-only values), hardware.nix, disks.nix hosts/desktop/ written by install-system: hardware-configuration.nix, disk-ids.json (not modules) pkgs/ install-system, create-keys, set-password, secret-from-file, switch-system, dev-shell (the `dev` command) patches/proxy-suite/ patches applied to the locked proxy-suite input (network/proxy-suite.nix) secrets/ secrets.nix (recipients) and the encrypted *.age files keys/ PRIVATE keys, gitignored, lives only on your USB stick .claude/, CLAUDE.md project settings and instructions for Claude Code sessions ``` ### How it is organised (dendritic) - **Every `.nix` file under `modules/` is a flake-parts module.** `flake.nix` only declares inputs; its `outputs` is `flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules)`. import-tree imports every file below `modules/` (paths containing `/_` are skipped), so there are no import lists: `git add` a new file and it is part of the flake. - **An aspect is one feature**, published as `flake.modules.nixos.` (a NixOS module) and/or `flake.modules.homeManager.` (a home-manager module). One file can define both halves, e.g. `modules/security/ssh.nix` (server and client). Importing an aspect turns the feature on: there are no `enable` options. Alternatives are separate aspects (`secure-boot` or `systemd-boot`). `core` is the always-on basics, merged from `modules/core/*.nix` and the agenix import in `modules/security/secrets.nix`. - **A host picks aspects.** `modules/hosts/desktop/host.nix` sets `configurations.nixos.desktop.module`: the list of NixOS aspects, the owner's home-manager aspects and the values that belong to this machine only (time zone, locale, keyboard layouts, firewall, `stateVersion`s). `hardware.nix` and `disks.nix` add to the same module. `modules/flake/nixos.nix` turns every `configurations.nixos.` into `nixosConfigurations.` and `checks..nixos-`. - **A combined aspect attaches its home-manager half to the owner** from its NixOS half (`home-manager.users..imports`), so the host imports it once. Home-manager-only aspects (`shell`, `git`, `neovim`, `wezterm`, `xdg`, `apps`, `obsidian`, `claude-code`, `dev-shells`) are listed in the host's `home-manager.users.` block. `sddm` is NixOS-only and sits in the host's NixOS list next to `hyprland`, `noctalia` and `theme` (it reads the Stylix palette, wallpaper, font and cursor, and asserts a Catppuccin scheme). - **Shared data** is two typed top-level flake-parts options (schema in `modules/flake/meta.nix`, not a flake output): `meta.owner` (name, full name, e-mail, uid, SSH keys; the values are in `modules/users/faumaray.nix`) and `meta.secretsDir` (default `./secrets`). A file reads them from the flake-parts `config`, bound in a `let` *before* any NixOS or home-manager module (inside `{ config, ... }:` of those, `config` is the NixOS or home-manager configuration), so both halves get the values by closure. - **Host values are plain NixOS options** (`time.timeZone`, `services.xserver.xkb`, ...), set in `host.nix`. A home-manager half reads them, and everything else on the system side (`osConfig.age.secrets`, ...), through `osConfig`, home-manager's handle on the NixOS configuration. - The only custom option left is the read-only `config.my` in `modules/core/install-facts.nix`, a compatibility view of the real configuration that `install-system` evaluates; aspects never read it. Rules of thumb: - A third-party module is imported by exactly one aspect (agenix and home-manager: `core`; lanzaboote: `secure-boot`; Stylix: `theme`; disko: the host's `disks.nix`). Importing it twice declares its options twice. - A dynamic attribute such as `users.users.${owner.name}` may appear only once per attribute set: put everything for the owner into one block. - A secret is declared (`age.secrets.`) only when `meta.secretsDir + "/.age"` exists, with a `warnings` entry otherwise. Never put a secret value into a `.nix` file. #### Add an aspect 1. Create `modules//.nix` with a header comment (what it does; for a combined aspect, what each half does). 2. Define `flake.modules.nixos.` and/or `flake.modules.homeManager.`. A combined aspect adds its home-manager half from the NixOS half: ```nix { config, ... }: let # flake-parts' config: read shared values here, before the `config` argument # of a NixOS or home-manager module shadows the name. inherit (config.meta) owner; hmFoo = config.flake.modules.homeManager.foo; in { flake.modules.nixos.foo = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; home-manager.users.${owner.name}.imports = [ hmFoo ]; }; flake.modules.homeManager.foo = { osConfig, ... }: { programs.git.settings.user.email = owner.email; home.sessionVariables.KB_LAYOUT = osConfig.services.xserver.xkb.layout; }; } ``` 3. Stylix themes every program it supports on its own (`stylix.autoEnable = true`), so nothing is needed for most. To keep one out, add `stylix.targets..enable = false;` to `modules/theme/stylix.nix` (its home-manager half for user programs). A few targets need settings of their own (`obsidian.vaultNames`): set them there too. 4. Add the name to the NixOS list (or the home-manager list) in `modules/hosts//host.nix`. 5. `git add` the new file (flakes only see tracked files), run `nix fmt`, the host evaluation (`nix eval .#nixosConfigurations.desktop.config.system.build.toplevel.drvPath`) and then `nix flake check --no-build`. #### Add a host 1. Create `hosts//` with `disk-ids.json` (`{"system": "/dev/disk/by-id/nvme-CHANGE-ME", "data": "/dev/disk/by-id/ata-CHANGE-ME"}`) and a placeholder `hardware-configuration.nix` (`hosts/desktop/`'s is a template). `install-system` rewrites both and needs the directory to exist. 2. Copy `modules/hosts/desktop/` to `modules/hosts//`. In each file replace `configurations.nixos.desktop` with `configurations.nixos.` and the `hosts/desktop/` paths; adjust the aspect lists, time zone and keyboard layouts, firewall, disks and the `stateVersion`s. 3. `git add` everything, then `nix run .#install -- --host ` on the target. If a second host needs the same disk layout, lift `disks.nix` into a shared aspect at that point. ### Flake outputs | Output | Contents | |---|---| | `nixosConfigurations` | `desktop`, `installer` | | `packages.x86_64-linux` | `create-keys`, `dev-shell`, `install-system`, `iso`, `secret-from-file`, `set-password`, `switch-system` | | `apps.x86_64-linux` | `create-keys`, `install`, `secret-from-file`, `set-password`, `switch` | | `checks.x86_64-linux` | `create-keys`, `dev-shell`, `formatting`, `install-system`, `nixos-desktop`, `secret-from-file`, `set-password`, `switch-system` | | `devShells.x86_64-linux` | `default` (`nix develop`: agenix, disko, age, ssh-to-age, sbctl, git, nixfmt, nixd, shellcheck), `rust`, `rust-nightly`, `cpp`, `cpp-gcc`, `vulkan`, `vulkan-gcc`, `rust-cpp` (see Development shells) | | `legacyPackages.x86_64-linux` | `composeShells` (the function behind `dev a b -p pkg`) | | `formatter.x86_64-linux` | `nix fmt` (nixfmt; skips the generated `hosts/*/hardware-configuration.nix`) | | `overlays` | `hyprland`, `noctalia`, `additions`, `modifications`, and `default`, which composes the four | | `modules` | `nixos.`, `homeManager.` | `checks.x86_64-linux.nixos-desktop` is the host's toplevel: with `--no-build`, `nix flake check` evaluates the whole host down to its derivation, without it the host is built. `formatting` is the nixfmt check; the six tools are checks too (their shellcheck runs when they are built). ## First-time setup (on your current machine) Everything here is **optional**. Without it the system still installs; the login password then is `changeme` (with a warning), there is no SSH key, the Gitea runner is not configured, the Telegram proxy is off and so are the AmneziaWG tunnels, split and `vpn` (a warning each for the runner, the proxy and AmneziaWG). ```sh git clone https://git.faumaray.com/faumaray/NixOsConfig nixos-config && cd nixos-config # 1. Host SSH key (the agenix identity) and Secure Boot keys -> keys/desktop/ nix run .#create-keys # 2. Open secrets/secrets.nix and replace the two placeholder keys: # host = the public key create-keys printed # faumaray = your own public key (cat ~/.ssh/id_ed25519.pub) # 3. Login password (asks twice, stores secrets/faumaray-password.age) nix run .#set-password -- -i ~/.ssh/id_ed25519 # 4. Your SSH key, installed as ~/.ssh/id_ed25519 on the new system nix run .#secret-from-file -- ssh-id_ed25519.age ~/.ssh/id_ed25519 -i ~/.ssh/id_ed25519 cp ~/.ssh/id_ed25519.pub secrets/ssh-id_ed25519.pub # 5. Commit. Flakes only see tracked files; keys/ is gitignored on purpose. git add -A && git commit -m "Add secrets" ``` `-i` is only a check: it proves your private key can decrypt what was just written. Edit secrets later with `cd secrets && agenix -e .age -i `. Copy the whole directory, **including `keys/`**, to the USB stick (and back `keys/` up: it holds the host key and the Secure Boot keys). `keys//` contains `ssh_host_ed25519_key(.pub)` and `sbctl/{keys,GUID}`. The installer copies them to `/etc/ssh` and `/var/lib/sbctl`; if they are missing it generates new ones and saves them back to the stick. ### Secrets | File in `secrets/` | Content | Consumer | |---|---|---| | `faumaray-password.age` | hashed login password (`mkpasswd -m yescrypt`; `set-password`) | the user account (`modules/core/users.nix`) | | `ssh-id_ed25519.age`, `ssh-id_ed25519_work.age` | private SSH keys (+ optional plain `.pub` files) | linked to `~/.ssh/` (`modules/security/ssh.nix`) | | `gitea-runner-token.age` | one line `TOKEN=` | Gitea runner `performance`, `tokenFile` (`modules/dev/gitea-runner.nix`) | | `tg-ws-proxy-secret.age` | the hex secret (32 hex digits, generated below) | Telegram proxy, `secretFile` (`modules/network/proxy-suite.nix`) | | `amneziawg-ai.age` | the whole AmneziaWG client .conf (AWG 1.x to 3.x) | AmneziaWG split tunnel (`amneziaWg.profiles.ai.configFile`) and full-tunnel profile `vpn` (`profiles.vpn.configFile`), both in `modules/network/proxy-suite.nix`; without it no tunnel, no TProxy and no per-app routing, the proxy stays off | `gitea-runner-token.age` and `tg-ws-proxy-secret.age` are new: the runner token and the Telegram secret used to be plaintext in the Nix files. Create them the same way as the others (the recipients are already listed in `secrets/secrets.nix`; `secret-from-file` runs `git add` for you): ```sh # Gitea runner: a fresh registration token from the Gitea runners page. # The editor opens; type one line: TOKEN= (cd secrets && agenix -e gitea-runner-token.age -i ~/.ssh/id_ed25519) # or without an editor (the token lands in your shell history): printf 'TOKEN=%s\n' '' \ | nix run .#secret-from-file -- gitea-runner-token.age - -i ~/.ssh/id_ed25519 # Telegram proxy: a new secret; note it, the Telegram clients need it in the proxy link s=$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n') && [ "${#s}" -eq 32 ] && echo "$s" \ && printf '%s\n' "$s" | nix run .#secret-from-file -- tg-ws-proxy-secret.age - -i ~/.ssh/id_ed25519 unset s git add secrets/gitea-runner-token.age secrets/tg-ws-proxy-secret.age # agenix -e does not ``` (`-` reads the plaintext from stdin, so no plaintext file is left behind; add `--force` to replace an existing file. Show a stored secret again with `age -d -i ~/.ssh/id_ed25519 secrets/tg-ws-proxy-secret.age`.) The AmneziaWG split tunnel (the Claude/Anthropic and ChatGPT/OpenAI domains, and the few other sites in `aiDomains`, go through the tunnel, everything else stays direct but for the networks zapret cannot unblock, below) takes the client `.conf` that AmneziaVPN exports. It is a file that holds a private key, so keep it outside the repository, encrypt it and delete the plaintext. `secret-from-file` runs `git add` for you. Do not keep the AmneziaVPN desktop client connected with the same peer at the same time: ```sh nix run .#secret-from-file -- amneziawg-ai.age /path/to/client.conf -i ~/.ssh/id_ed25519 rm /path/to/client.conf ``` A plaintext copy must not stay in the repository: `/WG.conf` in the root is gitignored, so `git add` and the `.#` flake references skip it, but it is still a private key on disk, and a `path:` flake reference would copy it into the world-readable Nix store. `amneziawg-ai.age` is the only copy needed. The split mode is the proxy-suite **global TProxy** (`proxy.autostart = "tproxy"`): nftables hands this host's own TCP and UDP connections to public addresses, DNS lookups included, to sing-box (loopback, private and LAN ranges, replies and proxy-suite's own traffic stay out). It sends the AI domains (and Anthropic's published inbound range `160.79.104.0/23`) through the `ai` tunnel and everything else directly, where zapret works. It is TProxy and not TUN because proxy-suite hands zapret2's fallback lists only to the config that serves TProxy (`proxy-suite-socks`): `zapret-cutoff` (networks that cut TLS off at about 16 KB: Cloudflare, AWS, Hetzner...) and `zapret-unfixable` (addresses no strategy fixed: CDN77, G-Core, OVH, Fastly, Akamai...) go to outbound `proxy`, which here is the `ai` tunnel too. Under TUN they went direct and timed out. What TProxy costs: - Only this host's own connections are taken (dockerd's and rootless Docker's user-mode networking among them), not forwarded ones. Rootful containers (the Gitea runner's jobs) and VMs behind a bridge go out directly, through zapret but with neither the split nor the fallback lists. - Blocked CDNs and cut-off networks now leave through the AmneziaWG server, which carries their traffic. - They have no direct fallback: while `ai` is down they do not load at all (cache.nixos.org, behind Fastly, among them). **Two local fixes to proxy-suite.** The module is built from the locked `proxy-suite` input with the patches in `patches/proxy-suite/`, applied with `applyPatches`; the module factory is then called with the same inputs upstream's `flake.nix` passes for `nixosModules.default`. Evaluation builds that patched tree first (import from derivation): a small local build whose tools may need cache.nixos.org, reachable only through `ai`. `system.extraDependencies` keeps the tree in the system closure, so the weekly garbage collection leaves it and evaluation needs neither a build of it nor cache.nixos.org once a switch has put it there; a fresh clone or a `nix flake update` still builds it. `nix flake check --no-build` is read-only: it fails with `...-proxy-suite-flake-patched.drv is not valid` whenever the store lacks the tree's `.drv` (a fresh clone or machine, a `nix flake update` that moves nixpkgs or proxy-suite, an edited patch, a garbage collection). That error means: run the host evaluation first (`nix eval .#nixosConfigurations.desktop.config.system.build.toplevel.drvPath` builds the tree), then the check. - `0001-tproxy-let-zapret-desync-packets-past.patch`: TProxy's output chain took zapret's own desync packets (fakes and split segments) back into the proxy, which dropped them, so every connection zapret desyncs stalled (YouTube, Discord...). nfqws2 marks those packets with its desync mark OR'd with the mark of the packet they derive from (0x40000002 for a proxy-marked one), so the patch tests the mark bits and lets every packet with a zapret desync bit past. The kill switch matches its zapret marks by exact value and would miss 0x40000002 (probably an upstream bug of its own; it is off here). The patch header describes it for an upstream report. - The `ai` watchdog checks the tunnel with `curl --interface awg-ai`, which TProxy marked for the proxy and its `misrouted` guard dropped: three misses, and the watchdog reset the peer every five minutes. The NixOS table `proxy-suite-ai-probe` (`networking.nftables.tables`, in `proxy-suite.nix`) gives packets leaving through `awg-ai` the proxy's own mark, just ahead of TProxy's output chain, which lets that mark past. Drop the table once upstream marks the watchdog's probe. When upstream has the first fix, drop the patch: delete the file, and in `modules/network/proxy-suite.nix` import `inputs.proxy-suite.nixosModules.default` again in place of `proxySuiteModule` (and remove `proxySuiteSource` with the `patches` directory). A patch that no longer applies after `nix flake update proxy-suite` fails evaluation, which is the reminder. The same file also backs a **full-tunnel profile `vpn`**: a normal VPN for all traffic, never started at boot. ```sh proxy-ctl awg on vpn # connect (or: systemctl start proxy-suite-awg-vpn) proxy-ctl awg off # disconnect, back to the split mode ``` Starting it stops TProxy, zapret and the `ai` tunnel (one global mode at a time, and both profiles hold the same peer, which accepts one endpoint). Stopping it starts TProxy (which pulls `ai` in) and zapret again, within seconds; a `restart` keeps the full tunnel, and so does a shutdown. The hook starts both whatever you had switched off by hand before (`proxy-ctl zapret off`, `proxy-ctl proxy tproxy off`). zapret is started by the hook and not wanted by TProxy, so `proxy-ctl zapret off` holds until the next full tunnel stop, boot or switch (a switch starts zapret and TProxy again). A full tunnel that fails to start (no handshake) falls back to the split mode the same way, with a rough edge: the hook's start of TProxy, which conflicts with `proxy-suite-awg-vpn`, cancels the unit's running start job, so `proxy-ctl awg on vpn` prints `Job ... canceled` instead of the real error (read it with `journalctl -u proxy-suite-awg-vpn`). The unit ends up failed, and the system reports `degraded` until `systemctl reset-failed proxy-suite-awg-vpn`. A switch (`nix run .#switch`) starts the active targets again, which starts every unit wanted at boot that is not running, TProxy, zapret and `ai` among them. Each of them stops the full tunnel, so a switch made with the full tunnel up ends in the split mode: run `proxy-ctl awg on vpn` again afterwards, from a terminal outside the tools that depend on the tunnel. For the same reason a switch does not restart the `vpn` unit when it changed (`restartIfChanged = false`): that would bounce between the two modes. A second peer (`vpn` with a client config of its own: another secret and `profiles.vpn.configFile`) would only keep `ai` up beside the full tunnel, and only once the unconditional conflicts and after of `proxy-suite-awg-vpn` on `awg-ai` in `proxy-suite.nix` are dropped; TProxy and zapret stop either way. **Rotate the old values.** They are in the git history, so treat them as leaked: create a new runner registration token in Gitea and a new MTProto secret, and update the Telegram clients with the new proxy link. Until the two files exist a switch removes the runner instance and turns the Telegram proxy off, each with an evaluation warning. ## Install from USB Needs a UEFI PC and network. **The NixOS installer image is not Secure Boot signed: disable Secure Boot in the firmware while installing** (you enable it again afterwards, see below). `install-system` erases the two chosen disks. ### Path A: official NixOS ISO + this repository on a stick 1. Boot the official NixOS ISO (minimal or graphical, e.g. with Ventoy), connect to the network (`nmtui`). 2. Mount the stick that holds the repository and `keys/`. **Not below `/mnt`**, that is where the new system is mounted: ```sh sudo -i mkdir -p /media/usb && mount /dev/disk/by-label/