Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| infrastructure:nixos-boxes [2025/12/21 07:46] – diamond | infrastructure:nixos-boxes [2026/01/08 09:12] (current) – move bitwarden-sops out into a page diamond | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| As the name describes, these boxes run NixOS, but they' | As the name describes, these boxes run NixOS, but they' | ||
| + | |||
| + | ## Pages | ||
| + | |||
| + | ```dokuwiki | ||
| + | <catlist infrastructure: | ||
| + | ``` | ||
| + | |||
| + | ## Structure | ||
| + | |||
| + | - `nixos/` | ||
| + | - `machines/` - NixOS machine configurations. | ||
| + | - `modules/` - Reusable NixOS modules. | ||
| + | - `sanity.nix` - Sane defaults for all NixOS machines. For now, these are | ||
| + | server-oriented, | ||
| + | you won't need to import this module. | ||
| + | - `Justfile` - recipe file for common operations (see | ||
| + | [Common Operations](# | ||
| + | |||
| + | ## Onboarding Yourself | ||
| + | |||
| + | Currently, these are the major steps to onboarding yourself to manage these | ||
| + | machines: | ||
| + | |||
| + | 1. Gain access to these machines over the network, ideally over Tailscale. | ||
| + | | ||
| + | | ||
| + | 2. Be added into `./ | ||
| + | | ||
| + | 3. Set up your local environment. See | ||
| + | | ||
| + | |||
| + | ### Setting Up Your Local Environment | ||
| + | |||
| + | You will need at least [Nix][nix] installed on your local machine. Optionally, | ||
| + | install [Direnv][direnv] as well for easier environment variable management. | ||
| + | |||
| + | If you're just using Nix, you can enter a shell with all dependencies by | ||
| + | running: | ||
| + | |||
| + | ```sh | ||
| + | nix develop | ||
| + | ``` | ||
| + | |||
| + | If you're using Direnv, create a `.envrc` file under the `nixos` directory (this | ||
| + | directory) with the following content: | ||
| + | |||
| + | ```sh | ||
| + | use flake | ||
| + | ``` | ||
| + | |||
| + | > **Tip:** | ||
| + | > | ||
| + | > You may have a need to save secret environment variables such as Bitwarden | ||
| + | > session keys in your `.envrc`. For this reason, consider adding it to your | ||
| + | > local gitignore by running: | ||
| + | > | ||
| + | > `echo " | ||
| + | |||
| + | ## Deployment | ||
| + | |||
| + | All NixOS boxes are automatically deployed with GitOps practices. The following diagram briefly explains its architecture: | ||
| + | |||
| + | ```dokuwiki | ||
| + | <div centeralign> | ||
| + | < | ||
| + | flowchart TD | ||
| + | codeberg[dma/ | ||
| + | codeberg --[pull every 15s]--> comin_a | ||
| + | codeberg --[pull every 15s]--> comin_b | ||
| + | subgraph nixos_machine_a[NixOS Machine A] | ||
| + | nixos_rebuild_a[nixos-rebuild] | ||
| + | comin_a[comin.service] --> nixos_rebuild_a | ||
| + | end | ||
| + | subgraph nixos_machine_b[NixOS Machine B] | ||
| + | nixos_rebuild_b[nixos-rebuild] | ||
| + | comin_b[comin.service] --> nixos_rebuild_b | ||
| + | end | ||
| + | </ | ||
| + | </ | ||
| + | ``` | ||
| + | |||
| + | Whenever a new commit is pushed to the `main` branch, all machines race to deploy this new commit. This way, we achieve GitOps without requiring an actual CI/CD pipeline, simplifying the deployment pipeline by a lot. | ||
| + | |||
| + | To see how caught up the deployments are on the NixOS fleet, run `just watch`. This spawns a dashboard of machines and their commits which refreshes every 5 seconds. Use this immediately after pushing to comprehensively view how the machines are going along. | ||
| + | |||
| + | ### Testing Branches | ||
| + | |||
| + | [comin](https:// | ||
| + | |||
| + | To use this, simply push a new commit to a new `testing-{machine}` branch, where `{machine}` is the name of the machine. For example, a commit that updates `home-assistant-one`' | ||
| + | |||
| + | Once everything is tested to be working, you can simply `git checkout main` then `git rebase testing-{machine}` to add your new commits on top. Then, push to main as usual. | ||
| + | |||
| + | |||
| + | ## Common Operations | ||
| + | |||
| + | Most, if not all, common operations can be performed via the `just` command. To | ||
| + | see a list of available recipes, run: | ||
| + | |||
| + | ```sh | ||
| + | just | ||
| + | ``` | ||
| + | |||
| + | ## Playbooks | ||
| + | |||
| + | This section contains useful playbooks for managing these machines. | ||
| + | |||
| + | ### Setting Up a New Machine | ||
| + | |||
| + | This section will not go into the detailed steps of installing NixOS on a new | ||
| + | machine, but rather the recommendations for setting it up: | ||
| + | |||
| + | #### Creating a configuration.nix | ||
| + | |||
| + | Create a `machines/< | ||
| + | (especially common Thinkcentre models), it should be enough to just import | ||
| + | `nixos-hardware` directly. | ||
| + | |||
| + | After creating this file, add it to the local `flake.nix`, | ||
| + | `.nixosConfigurations.< | ||
| + | have a good reason not to. | ||
| + | |||
| + | #### Disk Partitioning | ||
| + | |||
| + | Create a `machines/< | ||
| + | [disko][disko]. | ||
| + | |||
| + | **It is strongly recommended to use full disk encryption via LUKS + Btrfs**, | ||
| + | unless you are absolutely sure the machine will not store any secrets or run | ||
| + | any secure workloads. You may refer to existing NixOS machines for disko | ||
| + | examples. | ||
| + | |||
| + | Don't forget to add the file to the local `flake.nix`, | ||
| + | `.diskoConfigurations.< | ||
| + | for this. | ||
| + | |||
| + | #### Installing NixOS Quickly | ||
| + | |||
| + | Install NixOS directly by flashing it onto the hard drive using a SATA-to-USB or NVME-to-USB adapter. This will save you the trouble of having to transfer this repository over to the machine' | ||
| + | |||
| + | If you're inside the Nix develop environment, | ||
| + | |||
| + | ```sh | ||
| + | sudo disko-install \ | ||
| + | --mode format \ | ||
| + | --disk '< | ||
| + | --flake " | ||
| + | ``` | ||
| + | |||
| + | > **Note:** Use `path:// | ||
| + | |||
| + | > **Note:** This doesn' | ||
| + | |||
| + | If you're doing this from the NixOS live environment, | ||
| + | |||
| + | ```sh | ||
| + | nix run ' | ||
| + | nixos-install --no-channel-copy --flake ' | ||
| + | ``` | ||
| + | |||
| + | #### Re-using Modules | ||
| + | |||
| + | For convenience, | ||
| + | See existing `configuration.nix` files for reference. | ||
| + | |||
| + | #### Secure Boot | ||
| + | |||
| + | After installation, | ||
| + | The `secureboot` module should aid you in this process, but refer to | ||
| + | [Lanzaboote][lanzaboote]' | ||
| + | |||
| + | - [Prepare Your System](https:// | ||
| + | - [Enable Secure Boot](https:// | ||
| + | |||
| + | ### Adding Bitwarden Secrets to a Machine | ||
| + | |||
| + | Moved to [a separate playbook](/ | ||