This is a collection of my configuration files.
Warning: Don’t blindly use my settings unless you know what that entails. Use at your own risk!
Here are some details about my setup:
parted /dev/sda -- mklabel gpt # create GPT partition table
parted /dev/sda -- mkpart primary 512MB -8GB # add the root partition, this will fill the disk except for the end part, where the swap will live and space left in front will be used by the boot partition
parted /dev/sda -- mkpart primary linux-swap -8GB 100% # add swap partition
# Setup the boot partition. NixOS by default uses the ESP (EFI system partition) as its /boot partition. It uses the initially reserved 512MiB at the start of the disk.
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 3 esp on
mkfs.ext4 -L nixos /dev/sda1 # for initialising ext4 partition
mkswap -L swap /dev/sda2 # for creating swap partitions
mkfs.fat -F 32 -n boot /dev/sda3 # for creating boot partition
Result:
- /dev/sda1
- label: nixos
- size: remaining size after boot and swap partitions has been set
- /dev/sda2
- label: swap
- size: 8GiB
- /dev/sda3
- label: boot
- size: 512MiB
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
swapon /dev/sda2nixos-generate-config --root /mnt # generate default configuration
nix-env -iA nixos.git # install git
git clone https://github.com/giuxtaposition/.dotfiles /home/giu/.dotfiles
cd /home/giu/.dotfiles
cp /mnt/etc/nixos/hardware-configuration.nix ./nixos # copy generated hardware-configuration
nixos-install --flake .#reinanix flake update # to update the flake.lock file (packages versions)
sudo nixos-rebuild switch --flake .#reina # update and rebuild nixos config
home-manager switch --flake .#giu@reina # update and rebuild home-manager configSecrets are managed with sops-nix using age encryption.
Encrypted secrets live in secrets/secrets.yaml and are decrypted at NixOS activation time to /run/secrets/<name>.
- Generate an age key on the target machine:
sudo mkdir -p /var/lib/sops-nix
sudo age-keygen -o /var/lib/sops-nix/key.txtThe public key is printed to stderr — copy it.
- Add the public key to
secrets/.sops.yaml:
keys:
- &kumiko age1abc123...
creation_rules:
- path_regex: secrets\.yaml$
key_groups:
- age:
- *kumiko- Create or edit the encrypted secrets file (requires
sopsandagein your shell, available vianix develop):
sops secrets/secrets.yamlThis opens your $EDITOR with the decrypted YAML. Add secrets using path-style keys:
vpn:
protonvpn:
env-file: |
OPENVPN_USER=username+pmp
OPENVPN_PASSWORD=passwordSave and close — sops encrypts the file automatically.
Reference secrets in NixOS modules via config.sops.secrets:
# Declare the secret
sops.secrets."vpn/protonvpn/env-file" = {};
# Use the decrypted path
environmentFiles = [
config.sops.secrets."vpn/protonvpn/env-file".path
];Secrets are decrypted to /run/secrets/<name> with 0400 root:root by default.
To grant access to a service user, set the owner field:
sops.secrets."services/paperless/admin-password" = {
owner = "paperless";
};When adding a new server that needs secrets:
- Generate an age key on the host (step 1 above)
- Add the new public key to
secrets/.sops.yamlunderkeysand the relevantcreation_rules - Re-encrypt existing secrets so the new host can decrypt them:
sops updatekeys secrets/secrets.yaml- Enable the secrets module in the host config:
secrets.enable = true;