2023-07-30 13:04:13 +02:00
# nixos-config [](https://builtwithnix.org)
2020-11-16 21:14:46 +01:00
2022-12-05 20:32:39 +01:00
This repository holds my NixOS configuration.
2023-07-30 12:51:01 +02:00
It is fully reproducible, flakes based, and position-independent, ...
2020-11-16 21:14:46 +01:00
2023-03-18 16:58:18 +01:00
used flakes:
2023-07-30 12:51:01 +02:00
2023-03-18 16:58:18 +01:00
- image generation: [nixos-generators ](https://github.com/nix-community/nixos-generators )
2023-09-02 17:51:12 +02:00
- disk partitioning: [disko ](https://github.com/nix-community/disko )
2023-03-18 16:58:18 +01:00
- secrets: [sops-nix ](https://github.com/Mic92/sops-nix )
2024-01-18 22:37:39 +01:00
- deployment: [nixinate ](https://github.com/MatthewCroughan/nixinate ), see [usage ](#usage )
2024-04-28 15:09:59 +02:00
- formatting: [git-hooks ](https://github.com/cachix/git-hooks.nix )
2024-12-02 22:00:53 +01:00
- install: [nixos-anywhere ](https://github.com/nix-community/nixos-anywhere/ )
2020-11-16 21:14:46 +01:00
2023-09-02 17:51:12 +02:00
## Structure
2020-11-16 21:14:46 +01:00
2023-07-30 12:51:01 +02:00
```text
2022-06-15 21:14:59 +02:00
.
2023-03-10 21:41:41 +01:00
├── images # custom image generations
├── machines # machine definitions
├── modules # own nix-options, to modularize services/hardware/...
├── overlays # overlays
├── pkgs # own packages, which are not available in nixpkgs
└── profiles # summarize module collections into single options
2022-06-15 21:14:59 +02:00
```
2020-11-16 21:14:46 +01:00
2023-09-02 17:51:12 +02:00
## Usage
2020-11-16 21:14:46 +01:00
2023-09-02 17:51:12 +02:00
- updating:
2023-07-30 12:51:01 +02:00
2023-09-02 17:51:12 +02:00
```bash
nix flake update
```
2020-11-16 21:14:46 +01:00
2024-01-18 22:37:39 +01:00
- deployment/update:
2023-07-30 12:51:01 +02:00
2023-09-02 17:51:12 +02:00
```bash
2024-11-08 00:19:17 +01:00
nix run .#< flake >
2023-09-02 17:51:12 +02:00
```
2022-06-15 21:14:59 +02:00
2023-09-02 17:51:12 +02:00
- secrets:
2023-07-30 12:51:01 +02:00
2023-09-02 17:51:12 +02:00
```bash
sops ./machines/< host > /secrets.yaml
```
2022-07-03 13:51:27 +02:00
2023-09-02 17:51:12 +02:00
- images:
2023-07-30 12:51:01 +02:00
2023-09-02 17:51:12 +02:00
```bash
nix build .#install -iso
nix build .#aarch64 -install --system aarch64-linux
```
- vms:
```bash
nixos-rebuild build-vm --flake .#< flake >
```
- (re-)install:
make sure you have ssh-root access to the machine and the ssh-key is used properly.
(It does not matter what system is installed before.)
1. generate config (only needed for new host)
get `nixos-generate-config` to run via nix and execute
```bash
nixos-generate-config --no-filesystems --root $(mktemp -d)
```
reuse the `hardware-configuration.nix` to create a new machine with its flake.
1. setup secrets
1. new host
then prepare the secrets in the following layout:
```bash
# enter disk encryption key
2024-12-02 21:28:49 +01:00
(umask 077; echo "my-super-safe-password" > /tmp/disk.key)
2023-09-02 17:51:12 +02:00
temp=$(mktemp -d)
# ssh-host keys
install -d -m755 "$temp/etc/ssh"
install -d -m755 "$temp/etc/secrets/initrd"
2024-12-02 21:33:48 +01:00
ssh-keygen -o -a 100 -N "" -t rsa -b 4096 -f "$temp/etc/ssh/ssh_host_rsa_key"
ssh-keygen -o -a 100 -N "" -t ed25519 -f "$temp/etc/ssh/ssh_host_ed25519_key"
ssh-keygen -o -a 100 -N "" -t ed25519 -f "$temp/etc/secrets/initrd/ssh_host_ed25519_key"
2023-09-02 17:51:12 +02:00
```
1. existing host
```bash
2024-12-02 21:28:49 +01:00
(umask 077; echo "my-super-safe-password" > /tmp/disk.key)
2023-09-02 17:51:12 +02:00
temp=$(mktemp -d)
2023-09-05 21:51:43 +02:00
find $temp -printf '%M %p\n'
2023-09-02 17:51:12 +02:00
```
should result in something looking like this
```text
drwx------ $temp
drwxr-xr-x $temp/etc
drwxr-xr-x $temp/etc/ssh
-rw------- $temp/etc/ssh/ssh_host_rsa_key
-rw------- $temp/etc/ssh/ssh_host_ed25519_key
-rw-r--r-- $temp/etc/ssh/ssh_host_rsa_key.pub
-rw-r--r-- $temp/etc/ssh/ssh_host_ed25519_key.pub
drwxr-xr-x $temp/etc/secrets
drwxr-xr-x $temp/etc/secrets/initrd
-rw------- $temp/etc/secrets/initrd/ssh_host_ed25519_key
-rw-r--r-- $temp/etc/secrets/initrd/ssh_host_ed25519_key.pub
```
1. execute install
now simply install by executing (this will delete all data!):
```bash
2024-12-02 22:00:53 +01:00
nix run github:nix-community/nixos-anywhere -- \
2023-09-02 17:51:12 +02:00
--disk-encryption-keys /tmp/disk.key /tmp/disk.key \
--extra-files "$temp" \
--flake .#< flake > \
root@< host >
```
## Inspired by
2023-07-30 12:51:01 +02:00
2022-07-30 15:03:48 +02:00
- [Nix config by Mic92 ](https://github.com/Mic92/dotfiles )
- [Nix config by ambroisie ](https://github.com/ambroisie/nix-config )
- [Nix config by pborzenkov ](https://github.com/pborzenkov/nix-config )
- [Nix config by nyanloutre ](https://gitea.nyanlout.re/nyanloutre/nixos-config )
2024-01-18 22:37:39 +01:00
- [Nix config by disassembler ](https://github.com/disassembler/network )
2024-04-28 15:09:59 +02:00
- [git-hook config ](https://github.com/cachix/git-hooks.nix/blob/master/template/flake.nix )