1
0
Fork 0
nix-configuration/README.md

144 lines
5.8 KiB
Markdown
Raw Normal View History

2024-02-29 14:53:34 +00:00
# NixOS Configuration
2024-12-06 18:04:47 +00:00
A full set of configuration files managed via NixOS. This project uses the [Snowfall library](https://snowfall.org/guides/lib/quickstart).
2024-02-29 14:53:34 +00:00
2024-04-28 16:03:40 +00:00
> [!WARNING]
> DO NOT DOWNLOAD AND RUN `nixos-rebuild` ON THIS REPOSITORY! These are my personal configuration files. I invite you to look through them, modify them, and take inspiration from them, but if you run `nixos-rebuild`, it _will completely overwrite your current system_!
2024-03-22 22:18:38 +00:00
2024-05-10 16:53:17 +00:00
## Using this repo
2024-02-29 14:53:34 +00:00
### Note on secrets management
2024-12-06 18:04:47 +00:00
Secrets are managed using [transcrypt](https://github.com/elasticdog/transcrypt). To unlock the repo, use `transcrypt -c [cipher] -p '[password]'`. Transcrypt will transparently encrypt/decrypt files stored in `modules/nixos/secrets` going forward. You can get the cipher and password from a host with transcrypt already configured by running `transcrypt --display`.
2024-02-29 14:53:34 +00:00
> [!NOTE]
> This is a poor man's secret management solution. If you use this, your secrets will be world-readable in the `/nix/store/`.
2024-02-29 14:53:34 +00:00
2024-05-10 16:53:17 +00:00
### First-time installation
2024-02-29 14:53:34 +00:00
When installing on a brand new system, partition the main drive into two partitions: a `/boot` partition, and a LUKS partition. Then, run `bin/format-drives.sh --root [root partition] --luks [luks partition]` (the script will request sudo privileges):
```sh
2024-12-06 18:04:47 +00:00
./bin/format-drives.sh --boot /dev/nvme0n1p1 --luks /dev/nvme0n1p2
```
2024-12-06 18:04:47 +00:00
Next, set up the host's config in the `systems/[architecture]` folder by copying `default.nix.template` and `hardware-configuration.nix.template` into a new folder named after the hostname. Running `format-drives.sh` also generates a `hardware-configuration.nix` file you can use.
2024-12-06 18:04:47 +00:00
If necessary, import modules by adding the host to `flake.nix` under the `outputs.systems.hosts` section.
Finally, run the NixOS installer, replacing `host` with your actual hostname:
2024-02-29 14:53:34 +00:00
```sh
sudo nixos-install --verbose --root /mnt --flake .#host --no-root-password
2024-12-06 18:04:47 +00:00
```
> [!TIP]
> This config installs a nixos-rebuild wrapper called `nos` (NixOS Operations Script) that handles pulling and pushing changes to your configuration repository via git. For more info, run `nixos-operations-script --help`.
2024-02-29 14:53:34 +00:00
2024-05-10 16:53:17 +00:00
### Running updates
To update a system, run `nixos-operations-script` (or just `nos`). To commit updates back to the repo, use `nos --update`. Do not run this script as root - it will automatically request sudo permissions as needed.
2024-06-05 17:42:14 +00:00
2024-10-10 16:16:37 +00:00
#### Automatic updates
2024-12-06 18:04:47 +00:00
To enable automatic updates for a host, set `config.${namespace}.services.autoUpgrade = true;`. You can configure the autoUpgrade module with additional settings, e.g.:
2024-10-10 16:16:37 +00:00
```nix
2024-12-06 18:04:47 +00:00
services.autoUpgrade = {
2024-10-10 16:16:37 +00:00
enable = true;
configDir = config.secrets.nixConfigFolder;
onCalendar = "daily";
user = config.users.users.aires.name;
};
```
2024-12-06 18:04:47 +00:00
Automatic updates work by running `nos`. There's an additional `pushUpdates` option that, when enabled, updates the `flake.lock` file and pushes it back up to the Git repository. Only one host needs to do this (in this case, it's [Hevana](./systems/x86_64-linux/Hevana)), but you can safely enable it on multiple hosts as long as they use the same repository and update at different times.
2024-06-05 17:42:14 +00:00
#### Manually updating
Run `nos` to update the system. Use the `--update` flag to update `flake.lock` as part of the process. For the first build, you'll need to specify the path to your `flake.nix` file and the hostname using `nos --hostname my_hostname --flake /path/to/flake.nix`.
2024-10-10 16:16:37 +00:00
After the first build, you can omit the hostname and path:
2024-04-28 16:03:40 +00:00
```sh
nos
2024-04-28 16:03:40 +00:00
```
2024-02-29 14:53:34 +00:00
2024-05-10 16:53:17 +00:00
This is the equivalent of running:
2024-12-06 18:04:47 +00:00
```sh
2024-10-10 16:16:37 +00:00
cd [flake dir]
git pull
nix flake update --commit-lock-file
git push
sudo nixos-rebuild switch --flake .
2024-02-29 14:53:34 +00:00
```
2024-05-10 16:53:17 +00:00
There are a few different actions for handling the update:
2024-05-10 16:53:17 +00:00
- `switch` replaces the running system immediately.
- `boot` switches to the new generation during the next reboot.
- `build` creates and caches the update without applying it.
- `test` creates the generation and switches to it, but doesn't add it to the bootloader.
2024-05-10 16:53:17 +00:00
#### Using Remote builds
Nix can create builds for or on remote systems, and transfer them via SSH.
##### Generating a build on a remote system
You can run a build on a remote server by using `--build-host`:
```sh
nixos-rebuild build --flake . --build-host [remote hostname]
```
##### Pushing a build to a remote system
Conversely, you can run a build on the local host, then push it to a remote system.
```sh
NIX_SSHOPTS="-o RequestTTY=force" nixos-rebuild --target-host user@example.com --use-remote-sudo switch
```
2024-05-10 16:53:17 +00:00
### Testing without modifying the system
2024-04-28 16:03:40 +00:00
2024-05-10 16:53:17 +00:00
If you want to test without doing a whole build, or without modifying the current system, there are a couple additional tools to try.
2024-02-29 14:53:34 +00:00
2024-05-10 16:53:17 +00:00
#### Dry builds
To quickly validate your configuration, create a dry build. This analyzes your configuration to determine whether it'll actually build:
2024-02-29 14:53:34 +00:00
```zsh
nixos-rebuild dry-build --flake .
```
2024-05-10 16:53:17 +00:00
#### Virtual machines
You can also build a virtual machine image to preview changes. The first command builds the VM, and the second runs it:
2024-02-29 14:53:34 +00:00
```zsh
nixos-rebuild build-vm --flake .
2024-05-10 16:53:17 +00:00
./result/bin/run-nixos-vm
2024-02-29 14:53:34 +00:00
```
2024-05-10 16:53:17 +00:00
> [!NOTE]
> Running the VM also creates a `.qcow2` file for data persistence. Remove this file after a while, otherwise data might persist between builds and muck things up.
## About this repository
2024-12-06 18:04:47 +00:00
This config uses the [Snowfall lib](https://snowfall.org/), along with some default options and settings for common software. It features:
2024-02-29 14:53:34 +00:00
- Flakes
- Home Manager
2024-06-05 17:42:14 +00:00
- Automatic daily updates
2024-05-24 03:50:42 +00:00
- AMD, Intel, and Raspberry Pi (ARM64) hardware configurations
- Support for various GUIs and desktop environments including Gnome, KDE, XFCE, and Hyprland
2024-02-29 14:53:34 +00:00
- Boot splash screens via Plymouth
- Secure Boot support via Lanzaboote
- Disk encryption via LUKS with TPM auto-unlocking
2024-05-24 03:50:42 +00:00
- Custom packages and systemd services
2024-02-29 14:53:34 +00:00
- Flatpaks
- Default ZSH shell using Oh My ZSH
2024-03-22 22:18:38 +00:00
- Secrets (in a janky hacky kinda way)