8000 docs: sync README, AGENTS and sops guide with the untangle refactor by redyf · Pull Request #105 · redyf/nixdots · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# AGENTS.md

> Updated: 2026-08-01

## What This Repo Is
- NixOS flake for personal hosts `desktop` and `selene`, plus a safe public `example` host.
- `flake.nix` discovers `hosts/*` as `nixosConfigurations` and builds one `homeConfigurations."<username>@<hostname>"` per host whose `meta.nix` user has a `users/<username>.nix` (`nh home switch` picks `$USER@$HOSTNAME` automatically).
Expand All @@ -10,14 +8,15 @@

## Source Of Truth
- Trust `flake.nix`, `lib/*.nix`, workflow files, and lockfiles over README prose.
- `lib/mkHost.nix` imports `modules/` (every `.nix` file in it is a module; `lib/modules-in.nix`) and `profiles/nixos/<role>.nix` for every role listed in `meta.nix`. Host `configuration.nix` files only import their generated hardware file. The `example` host intentionally avoids generated hardware config.
- `lib/mkHost.nix` imports `modules/` (every `.nix` file in it is a module; `lib/modules-in.nix`) and `profiles/nixos/<role>.nix` for every role listed in `meta.nix`. It also adds `hosts/<name>/disko.nix` (and the disko module) when the host has one. Host `configuration.nix` files only import their generated hardware file. The `example` host intentionally avoids generated hardware config.
- `lib/mkHome.nix` imports `home/` for every user (every directory with a `default.nix` is a module). `users/<name>.nix` holds per-user differences and imports `profiles/home/common.nix` (personal users) or `profiles/home/minimal.nix` (example). `hosts/<hostname>/home.nix` (optional) holds per-machine user settings such as monitor layouts. NixOS and HM modules receive `hostname`, `username`, `homeDirectory`, `keyboard` and `theme` (`theme.nix`) as module arguments.
- `profiles/nixos/` holds roles: `common` (every personal host), `workstation` (graphical), `gaming`, `dev`, `laptop`, `nvidia` (desktop only), and `minimal` (public example). Host files should only override or add host-specific choices (monitors, disks, hardware).
- `myConfig.*` is the NixOS module namespace; `myHomeConfig.*` is the Home Manager namespace. Each module declares its own `enable` option at the path matching its file (`modules/services/tlp.nix` → `myConfig.services.tlp.enable`); there are no category-level `enable` switches, so profiles list the leaves they want.
- `theme.nix` is the single source for scheme, polarity, cursor, terminal font size and the monospace font. Both Stylix modules read it (`modules/themes/stylix.nix`, `home/desktop/stylix-theme/default.nix`); apps should take colours and fonts from Stylix instead of hardcoding them.
- `pkgs/<name>/package.nix` holds custom packages. `lib/default.nix` turns them into an overlay (`overlays.default`, applied by `mkHost` and `mkHome`), so modules use `pkgs.<name>`, and into the `packages` flake output.

## Commands
- `nh os switch` is the preferred rebuild command on the desktop host.
- `nh os switch` is the preferred rebuild command on both personal hosts; `nh home switch` rebuilds Home Manager.
- `sudo nixos-rebuild switch --flake '.#desktop'` is the direct rebuild fallback.
- `nix flake check` is the main validation command. It runs treefmt (nixfmt + statix) as a check, evaluates every nixosConfiguration and every `<user>@<host>` homeConfiguration.
- `nix fmt` formats the tree with treefmt (`treefmt.nix`: nixfmt + statix, hardware-configuration.nix excluded).
Expand All @@ -37,7 +36,10 @@
- `hosts/desktop/disko.nix` and `hosts/selene/disko.nix` are parameterized with a required `device`; keep destructive disk choices explicit.
- `modules/cli/nh.nix` defaults the flake path to `${homeDirectory}/opensource/nixdots`, but `myConfig.cli.nh.flakePath` can override it.
- `home/cli/tools/git/default.nix` keeps SOPS-rendered identities and work SSH hosts opt-in; enable them from personal user files, not reusable profiles.
- `font-flake` is a local-path flake input (`ci/font-flake-fallback/`) providing proprietary fonts (Monolisa, etc.); the real private font flake is not in this repo.
- `font-flake` is a local-path flake input (`ci/font-flake-fallback/`) that exposes `tx02`, `monolisa`, `berkeley-mono` and `sf-mono` as JetBrains Mono Nerd Font. The real private fonts are not in this repo; use them with `--override-input font-flake github:redyf/font-flake`.
- Home Manager runs standalone and cannot see the NixOS configuration; nothing checks that the two layers agree (see "Dependencies between the NixOS and Home Manager layers" in `README.md`).
- Flakes only see files tracked by git: `git add` new files before building.
- Feature-specific input modules (hyprland, serpantinum, nvibrant) are imported by the `workstation` and `nvidia` roles, not by `mkHost`.

## Public Reuse / Onboarding
- Prefer `hosts/example` and `users/example.nix` over telling users to install `.#desktop` or `.#selene`.
Expand Down
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://github.com/redyf/nixdots">
<img src="https://img.shields.io/github/repo-size/redyf/nixdots?color=ea999c&labelColor=303446&style=for-the-badge">
</a>
<a href="https://github.com/redyf/nixdots/LICENSE">
<a href="https://github.com/redyf/nixdots/blob/main/LICENSE">
<img src="https://img.shields.io/static/v1.svg?style=for-the-badge&label=License&message=MIT&logoColor=ca9ee6&colorA=313244&colorB=cba6f7"/>
</a>
<br>
Expand All @@ -37,11 +37,11 @@
╭─ Model -> DELL XPS 8940
├─ CPU -> Intel i5-10400f @ 4.3GHz
├─ GPU -> NVIDIA GeForce GTX 1650 SUPER
╰─ Resolution -> 1920x1080@165hz
╰─ Resolution -> 1920x1080@180hz
╭─ WM -> Hyprland
├─ Terminal -> Ghostty
├─ Theme -> Catppuccin Macchiato
├─ Icons -> Papirus-Dark
├─ Icons -> WhiteSur
├─ Font -> MonoLisa
╰─ Hotel -> Trivago
       
Expand Down Expand Up @@ -89,6 +89,18 @@ OR
sudo nixos-rebuild switch --flake '.#desktop'
```

- Rebuild and switch the Home Manager configuration (picks `$USER@$HOSTNAME`):

```
nh home switch
```

- Format the tree (treefmt: nixfmt + statix):

```bash
nix fmt
```

- Connect to internet (Change what's inside the brackets with your info).

```
Expand All @@ -97,18 +109,20 @@ nmcli device wifi connect [SSID] password [passphrase]

## Secrets

This repo uses `sops-nix` for encrypted secrets, including the desktop user password. See [`docs/sops-setup.md`](docs/sops-setup.md) for the step-by-step guide.
This repo uses `sops-nix` for encrypted secrets, including the user password on both personal hosts (`desktop` and `selene`). See [`docs/sops-setup.md`](docs/sops-setup.md) for the step-by-step guide.

## Structure

- `flake.nix` discovers NixOS hosts from `hosts/*` and builds one Home Manager configuration per host, named `<username>@<hostname>` (e.g. `selene@selene`). `nh home switch` picks it automatically.
- `hosts/<name>/meta.nix` holds the host metadata: `username`, `system`, `roles` and optionally `keyboard`.
- `hosts/<name>/configuration.nix` contains host-specific system settings.
- `profiles/` contains shared defaults imported by hosts.
- `profiles/nixos/` holds roles (`common`, `workstation`, `gaming`, `dev`, `laptop`, `nvidia`, `minimal`) that hosts list in `meta.nix`. `profiles/home/minimal.nix` provides safer public Home Manager defaults.
- `profiles/nixos/` holds roles (`common`, `workstation`, `gaming`, `dev`, `laptop`, `nvidia`, `minimal`). `lib/mkHost.nix` imports the ones a host lists in `meta.nix`.
- `profiles/home/common.nix` is the Home Manager baseline for the personal users; `profiles/home/minimal.nix` provides safer public defaults. User files import one of them.
- `modules/` contains reusable NixOS modules exposed under `myConfig`. Every `.nix` file there is imported automatically and declares its own `myConfig.<dir>.<name>.enable`.
- `home/` contains reusable Home Manager modules exposed under `myHomeConfig`. Every directory with a `default.nix` is imported automatically and declares its own `myHomeConfig.<path>.enable`.
- `users/<name>.nix` holds per-user Home Manager settings; `hosts/<name>/home.nix` (optional) holds per-machine ones such as monitor layouts.
- `hosts/example` and `users/example.nix` are the recommended starting points for users testing this repo.
- `theme.nix` holds the appearance (scheme, cursor, monospace font) shared by Stylix on both layers.
- `ci/font-flake-fallback` provides a public font fallback for unauthenticated builds.
- `pkgs/<name>/package.nix` holds custom packages, exposed as `pkgs.<name>` in every configuration and as the flake's `packages` / `overlays.default`.
- `lib/` contains helper functions used to create hosts and home configurations.
Expand Down Expand Up @@ -187,6 +201,9 @@ nh home switch -- --override-input font-flake github:redyf/font-flake
> on your hardware unless you have reviewed every host-specific setting,
> generated your own hardware config, and understand the disk layout.
> Deploying someone else's NixOS host can make a machine unbootable or destroy data.
>
> Both hosts also take the user password from `hosts/<name>/secrets.yaml`, which
> only my age keys can decrypt. Without your own secrets file the user has no password.

If you want to test this repository, start with the safe example outputs:

Expand Down Expand Up @@ -265,7 +282,7 @@ Disko commands are destructive. Always pass the target disk explicitly and verif
If you run disko against **hosts/\<host\>/disko.nix**, the command looks like this:

```nix
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko ./hosts/desktop/disko.nix --arg device '/dev/nvme0n1'
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko ./hosts/desktop/disko.nix --arg device '"/dev/nvme0n1"'
```

you will partition, format and mount the disk for /dev/nvme0n1 (change as needed).
Expand Down
34 changes: 17 additions & 17 deletions docs/sops-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

This repo uses `sops-nix` to keep secrets encrypted in Git. The encrypted file is committed, but the private age key stays only on the machine that needs to decrypt it.

Current desktop flow:
Current flow:

```text
hosts/<host>/secrets.yaml -> /var/lib/sops-nix/key.txt -> /run/secrets-for-users/users/<username>/password
```

`desktop` decrypts with the age key in `/var/lib/sops-nix/key.txt`. `selene` derives its age key from the SSH host key instead (`myConfig.system.sops.keyFile = null`, see [Adding Another Host](#adding-another-host)). `<username>` is the `username` in `hosts/<host>/meta.nix`.

## Safety Rules

- Commit public age recipients (`age1...`) only.
Expand Down Expand Up @@ -109,19 +111,14 @@ This should print nothing.

## 5. Enable It In NixOS

The desktop host should enable SOPS and use the generated secret path:
Enable SOPS in `hosts/<host>/configuration.nix`:

```nix
myConfig = {
users = {
username = "<username>";
hashedPasswordFile = config.sops.secrets."users/<username>/password".path;
};

system.sops.enable = true;
};
myConfig.system.sops.enable = true;
```

The module (`modules/system/sops.nix`) declares `users/<username>/password` for the `username` in `hosts/<host>/meta.nix` and sets `myConfig.users.hashedPasswordFile` to its path.

Validate the secret path:

```bash
Expand Down Expand Up @@ -159,13 +156,16 @@ api_keys:
github: ghp_example_only_do_not_use
```

Declare the secret in Nix:
Declare the secret in Nix (`username` is a module argument, taken from `meta.nix`):

```nix
sops.secrets."api_keys/github" = {
owner = config.myConfig.users.username;
mode = "0400";
};
{ username, ... }:
{
sops.secrets."api_keys/github" = {
owner = username;
mode = "0400";
};
}
```

Use `config.sops.secrets."api_keys/github".path` when a program needs the secret.
Expand Down Expand Up @@ -248,7 +248,7 @@ creation_rules:
- *selene_user
```

Then create `hosts/selene/secrets.yaml` (only `users/<username>/password` is required; the `git` keys are needed only when `myConfig.system.sops.gitIdentity.enable` is on), enable `myConfig.system.sops.enable = true`, and set `myConfig.users.hashedPasswordFile = config.sops.secrets."users/${config.myConfig.users.username}/password".path`. Evaluation fails with a clear assertion if sops is enabled before the file exists.
Then create `hosts/selene/secrets.yaml` (only `users/<username>/password` is required; the `git` keys are needed only when `myConfig.system.sops.gitIdentity.enable` is on), and enable `myConfig.system.sops.enable = true`; the password file option is set by the module. Evaluation fails with a clear assertion if sops is enabled before the file exists.

If you add the desktop key as a recipient for `selene`, you can edit `selene` secrets from the desktop, but a leaked desktop key would also decrypt those secrets.

Expand Down Expand Up @@ -280,5 +280,5 @@ This is manageable because those values can be regenerated or typed again. It be
| `config file not found, or has no creation rules` | Run from the repo root and check `.sops.yaml` `path_regex`. |
| `no key could decrypt the data` | Check `SOPS_AGE_KEY_FILE` and confirm the matching public key is in `.sops.yaml`. |
| Boot cannot decrypt secrets | Confirm `/var/lib/sops-nix/key.txt` exists and is owned by `root:root` with mode `600`. |
| `users/<username>/password` is missing | Check `myConfig.system.sops.enable`, `myConfig.users.username`, and the YAML path. |
| `users/<username>/password` is missing | Check `myConfig.system.sops.enable`, `username` in `hosts/<host>/meta.nix`, and the YAML path. |
| Login fails after switch | Regenerate the hash with `mkpasswd -m sha-512` and check `journalctl -u sops-install-secrets-for-users`. |
Loading
0