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 | ## Structure | ||
| Line 48: | Line 54: | ||
| ``` | ``` | ||
| - | > [!TIP] | + | > **Tip:** |
| > | > | ||
| > You may have a need to save secret environment variables such as Bitwarden | > You may have a need to save secret environment variables such as Bitwarden | ||
| Line 54: | Line 60: | ||
| > local gitignore by running: | > local gitignore by running: | ||
| > | > | ||
| - | > ```sh | + | > `echo " |
| - | > 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 | ## Common Operations | ||
| Line 66: | Line 106: | ||
| just | just | ||
| ``` | ``` | ||
| - | |||
| - | A few notable recipes include: | ||
| - | |||
| - | - `just deploy < | ||
| - | have the hostname of `< | ||
| - | - `just ssh < | ||
| - | the above rule. | ||
| - | - `just sync-bitwarden-secrets < | ||
| - | machine. See | ||
| - | [Adding Bitwarden Secrets to a Machine](# | ||
| ## Playbooks | ## Playbooks | ||
| Line 86: | Line 116: | ||
| machine, but rather the recommendations for setting it up: | machine, but rather the recommendations for setting it up: | ||
| - | - Create | + | #### Creating |
| - | (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`, under | + | Create a `machines/< |
| - | `.nixosConfigurations.< | + | (especially common Thinkcentre models), it should be enough |
| - | have a good reason not to. | + | `nixos-hardware` directly. |
| - | - Create a `machines/< | + | After creating this file, add it to the local `flake.nix`, under |
| - | | + | `.nixosConfigurations.< |
| + | have a good reason not to. | ||
| - | **It is strongly recommended to use full disk encryption via LUKS + Btrfs**, | + | #### Disk Partitioning |
| - | 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`, under | + | Create a `machines/< |
| - | `.diskoConfigurations.< | + | [disko][disko]. |
| - | for this. | + | |
| - | - Install NixOS directly by flashing it onto the hard drive using a SATA-to-USB | + | **It is strongly recommended |
| - | or NVME-to-USB adapter. This will save you the trouble of having | + | unless you are absolutely sure the machine will not store any secrets |
| - | this repository over to the machine' | + | any secure workloads. You may refer to existing NixOS machines for disko |
| - | will be very handy: | + | examples. |
| - | | + | Don't forget to add the file to the local `flake.nix`, under |
| - | nix run ' | + | `.diskoConfigurations.< |
| - | | + | for this. |
| - | | + | |
| - | - For convenience, | + | #### Installing NixOS Quickly |
| - | See existing `configuration.nix` files for reference. | + | |
| - | - After installation, | + | 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 |
| - | 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 | + | If you' |
| - | + | ||
| - | If you' | + | |
| - | for Bitwarden users. If not, please reach out to an existing administrator first | + | |
| - | to be added before continuing. | + | |
| - | + | ||
| - | Before continuing, **it is strongly advised that you have [Nix][nix] and | + | |
| - | [Direnv][direnv] installed**. This will allow you to store your Bitwarden | + | |
| - | secrets much easier. | + | |
| - | + | ||
| - | #### Preparing the Bitwarden CLI | + | |
| - | + | ||
| - | First, set the `BITWARDENCLI_APPDATA_DIR` environment variable to prevent the | + | |
| - | CLI from using or overriding your personal Bitwarden configuration. It is | + | |
| - | strongly recommended to set this in `.envrc` so you don't forget: | + | |
| ```sh | ```sh | ||
| - | $ cat .envrc | + | sudo disko-install \ |
| - | export BITWARDENCLI_APPDATA_DIR=" | + | |
| - | ... | + | --disk '< |
| + | | ||
| ``` | ``` | ||
| - | Then, you'll need to obtain your Bitwarden API key. For this, follow the | + | > **Note:** Use `path://$PWD` rather than `.` since `disko` has buggy Flake subdirectory support. |
| - | [Bitwarden official documentation](https://bitwarden.com/ | + | |
| - | You may choose to add these as environment variables as well: | + | |
| - | ```sh | + | > **Note:** This doesn' |
| - | $ cat .envrc | + | |
| - | export BW_CLIENTID=" | + | |
| - | export BW_CLIENTSECRET=" | + | |
| - | ``` | + | |
| - | Now, proceed to run `bw unlock`. This will prompt | + | If you're doing this from the NixOS live environment, |
| - | and return a session key which contains | + | |
| - | add this key as well: | + | |
| ```sh | ```sh | ||
| - | $ cat .envrc | + | nix run ' |
| - | export BW_SESSION=" | + | nixos-install |
| ``` | ``` | ||
| - | Doing this is not recommended however, since it exposes your session key (and | + | #### Re-using Modules |
| - | therefore essentially your entire vault) in plaintext on disk, and the key will | + | |
| - | never expire. Instead, prefer exporting it manually in the current shell | + | |
| - | session. | + | |
| - | #### Adding a Secret | + | For convenience, |
| + | See existing `configuration.nix` files for reference. | ||
| - | Head to the Bitwarden web app or extension, then navigate to the **Server | + | #### Secure Boot |
| - | Credentials/ | + | |
| - | machine. | + | |
| - | To add a secret to a machine, open the corresponding item, then add a new hidden | + | After installation, set up Secure Boot and TPM2 unlocking as soon as you can. |
| - | field with the name being the SOPS path you want to store the secret at relative | + | The `secureboot` module should aid you in this process, but refer to |
| - | to `/ | + | [Lanzaboote][lanzaboote]' |
| - | For example, do add a secret at `/run/secrets/authentik/secret_key`, | + | - [Prepare Your System](https: |
| - | add a new hidden field with the name `authentik/secret_key` and the value being | + | - [Enable Secure Boot](https:// |
| - | the value of the secret. | + | |
| - | #### Onboard the Machine to SOPS | + | ### Adding |
| - | + | ||
| - | This step only needs to be done once per machine. To validate that a machine is | + | |
| - | ready for SOPS, ensure it has the `sops.*` options in its `configuration.nix`. | + | |
| - | + | ||
| - | If not, start by referring to | + | |
| - | [sops-nix' | + | |
| - | Essentially, | + | |
| - | + | ||
| - | 1. Grab the machine' | + | |
| - | 2. Add it to `vars.nix` under `< | + | |
| - | 3. Find the Bitwarden | + | |
| - | - Using `just get-bitwarden-secret-id < | + | |
| - | with the exact name given, but this is not guaranteed to be in the correct | + | |
| - | | + | |
| - | - Using the `& | + | |
| - | | + | |
| - | 4. Add it to `vars.nix` under `< | + | |
| - | + | ||
| - | Then, add the boilerplate snippet to the machine' | + | |
| - | + | ||
| - | ```nix | + | |
| - | { | + | |
| - | sops = { | + | |
| - | defaultSopsFile = ./ | + | |
| - | age.sshKeyPaths = [ "/ | + | |
| - | }; | + | |
| - | } | + | |
| - | ``` | + | |
| - | + | ||
| - | #### Synchronizing Secrets | + | |
| - | + | ||
| - | First, make sure that the local Bitwarden vault is up to date by running | + | |
| - | `bw sync`. | + | |
| - | + | ||
| - | Then, run `just sync-bitwarden-secrets < | + | |
| - | from Bitwarden to the `./ | + | |
| - | SOPS file will automatically be generated with the host SSH key being the only | + | |
| - | decrypting recipient. | + | |
| - | + | ||
| - | Having more than just the host's recipient key is not recommended. Instead, | + | |
| - | prefer regenerating the secret file from source Bitwarden if needed. This way, | + | |
| - | the secrets are always up to date with Bitwarden. | + | |
| - | + | ||
| - | #### Using the Secrets | + | |
| - | + | ||
| - | You may use the secrets in your machine like any other [sops-nix][sops-nix] | + | |
| - | secrets. For example: | + | |
| - | + | ||
| - | ```nix | + | |
| - | sops.secrets." | + | |
| - | owner = " | + | |
| - | }; | + | |
| - | ``` | + | |
| - | + | ||
| - | This will place the secret at `/ | + | |
| - | being the `authentik` user. | + | |
| - | + | ||
| - | Deploy the machine using `just deploy < | + | |
| - | the machine. | + | |
| - | [nix]: https://nixos.org/download.html | + | Moved to [a separate playbook](/infrastructure/playbook/bitwarden-sops-nix). |
| - | [direnv]: https:// | + | |
| - | [sops-nix]: https:// | + | |