Simon Bruder
d854fe3ac8
Flake lock file updates: • Updated input 'home-manager': 'github:nix-community/home-manager/bda2c80b4c1a8d85c84c343a25ac7303fbc7999d' (2022-05-30) → 'github:nix-community/home-manager/ac2287df5a2d6f0a44bbcbd11701dbbf6ec43675' (2022-06-01) • Updated input 'nixpkgs': 'github:nixos/nixpkgs/a634c8f6c1fbf9b9730e01764999666f3436f10a' (2022-05-30) → 'github:nixos/nixpkgs/9ff91ce2e4c5d70551d4c8fd8830931c6c6b26b8' (2022-06-14) • Updated input 'nixpkgs-unstable': 'github:nixos/nixpkgs/f1c167688a6f81f4a51ab542e5f476c8c595e457' (2022-05-30) → 'github:nixos/nixpkgs/6616de389ed55fba6eeba60377fc04732d5a207c' (2022-06-14) • Updated input 'sops-nix': 'github:Mic92/sops-nix/36b5901782e7fbfc191cace910f67f8b8743f678' (2022-05-29) → 'github:Mic92/sops-nix/f075361ecbde21535b38e41dfaa28a28f160855c' (2022-06-05) • Updated input 'sops-nix/nixpkgs-21_11': 'github:NixOS/nixpkgs/baa82d4b626288c7439eeea073a18aabbe435991' (2022-05-29) → 'github:NixOS/nixpkgs/2de556c4cd46a59e8ce2f85ee4dd400983213d45' (2022-06-04) • Updated input 'sops-nix/nixpkgs-22_05': 'github:NixOS/nixpkgs/db78278ff296cf21eca7e8c08ee99707387a54fa' (2022-05-29) → 'github:NixOS/nixpkgs/d6cb04299ce8964290ae7fdcb87aa50da0500b5c' (2022-06-04) |
||
---|---|---|
.git-crypt | ||
keys | ||
machines | ||
modules | ||
pkgs | ||
users/simon | ||
.envrc | ||
.gitattributes | ||
.gitignore | ||
.sops.yaml | ||
flake.lock | ||
flake.nix | ||
LICENSE | ||
README.md | ||
secrets.yaml |
NixOS configuration
Structure
machines
: Machine-specific configurationREADME.md
: Short overview of the hardware and usage of the machineconfiguration.nix
: Main configurationhardware-configuration.nix
: Hardware-specific configuration. It should not depend on any modules or files from this repository, since it is used for initial setup.services
: Non-trivial machine-specific configuration related to a specific service the machine provides.secrets
: Nix expressions that include information that is not meant to be visible to everyone (e.g. accounts, password hashes, private information etc.) or secrets for services that don’t provide any other (easy) way of specifying them and whose secrets leaking does not pose a huge threat
modules
: Custom modules. Many are activated by default, since I want them on all systems.pkgs
: My nixpkgs overlayusers/simon
: home-manager configuration
Secrets are managed with sops-nix.
Machines can be deployed with nix run .#deploy/hostname
, LUKS encrypted
systems can be unlocked over network with nix run .#unlock/hostname
.
How to install
This guide describes how to install this configuration with GPT and BIOS boot. It is not a one-fits-all guide, but the base for what I use for interactive systems. Servers and specialised systems may need a different setup (e. g. swap with random luks passphrase and no LVM).
Set up wifi if no wired connection is available:
systemctl start wpa_supplicant
wpa-cli
add_network
set_network 0 ssid "SSID"
set_network 0 psk "PSK"
set_network 0 key_mgmt WPA-PSK
enable_network 0
Create the partition table (enter the indented lines in the repl):
parted /dev/sdX
mktable GPT
mkpart primary 1MiB 2MiB
mkpart primary 2MiB 500MiB
mkpart primary 500MiB 100%
set 1 bios_grub on
disk_toggle pmbr_boot
quit
On UEFI:
parted /dev/nvmeXnY
mktable GPT
mkpart ESP 1MiB 512MiB
mkpart root 512MiB 100%
set 1 esp on
quit
Format encrypted partition and open it:
cryptsetup luksFormat --type luks2 /dev/sdX3
cryptsetup open --type luks2 /dev/sdX3 HOSTNAME-pv
Create LVM (replace 8G
with desired swap size):
pvcreate /dev/mapper/HOSTNAME-pv
vgcreate HOSTNAME-vg /dev/mapper/HOSTNAME-pv
lvcreate -L 8G -n swap HOSTNAME-vg
lvcreate -l '100%FREE' -n root HOSTNAME-vg
Hint: If you have to reboot to the installation system later because
something went wrong and you need access to the LVM (but don’t know LVM), do
the following after opening the luks partition: vgchange -ay
.
Create filesystems:
mkfs.ext2 /dev/sdX2
mkfs.btrfs -L root /dev/HOSTNAME-vg/root
mkswap -L swap /dev/HOSTNAME-vg/swap
On UEFI:
mkfs.fat -F 32 -n boot /dev/nvmeXnYpZ
mkfs.btrfs -L root /dev/HOSTNAME-vg/root
mkswap -L swap /dev/HOSTNAME-vg/swap
Mount the file systems and activate swap:
mount /dev/HOSTNAME-vg/root /mnt
mkdir /mnt/boot
mount /dev/sdX2 /mnt/boot
swapon /dev/HOSTNAME-vg/swap
Generate hardware configuration and copy hardware configuration to machine configuration (skip this step if you already have a hardware-configuration for this machine):
nixos-generate-config --root /mnt/
Modify the hardware configuration as needed and add it to the machine
configuration in this repository. If necessary, create the machine
configuration first by basing it on an already existing configuration and
adding an entry to machines/default.nix
. Then copy this repository to the
target machine and run (--impure
is needed since /mnt/nix/store
is not in
/nix/store
):
nixos-install --no-channel-copy --impure --flake /path/to/repository#hostname
Add the krops sentinel file:
mkdir -p /mnt/var/src
touch /mnt/var/src/.populate
Reboot.
License
Unless otherwise noted in the specific files or directories, the files in this repository are licensed under the MIT License. This only applies to the nix expressions, not the built system or package closures. Patches may also be licensed differently, since they may be derivative works of the packages to which they apply.