2020-08-22 17:44:39 +02:00
|
|
|
|
# NixOS configuration
|
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
## Structure
|
|
|
|
|
|
|
|
|
|
* `deploy.nix`: Configuration for deployment with
|
|
|
|
|
[krops](https://cgit.krebsco.de/krops/about/)
|
|
|
|
|
* `machines`: Machine-specific configuration
|
|
|
|
|
+ `README.md`: Short overview of the hardware and usage of the machine
|
|
|
|
|
+ `configuration.nix`: Main configuration
|
|
|
|
|
+ `hardware-configuration.nix`: Hardware-specific configuration. It should
|
|
|
|
|
not depend on any modules or files from this repository, since it is used
|
|
|
|
|
for initial setup.
|
2021-03-01 13:54:18 +01:00
|
|
|
|
+ `services`: Non-trivial machine-specific configuration related to a
|
|
|
|
|
specific service the machine provides.
|
2021-03-01 13:54:41 +01:00
|
|
|
|
+ `secrets`: Nix expressions that include information that is not meant to
|
|
|
|
|
be visible to everyone (e.g. accounts, password hashes, private
|
|
|
|
|
information etc.)
|
2021-01-27 21:55:04 +01:00
|
|
|
|
* `modules`: Custom modules. Many are activated by default, since I want them
|
|
|
|
|
on all systems.
|
|
|
|
|
* `pkgs`: My nixpkgs overlay
|
|
|
|
|
* `users/simon`: [home-manager](https://github.com/nix-community/home-manager)
|
|
|
|
|
configuration
|
|
|
|
|
|
|
|
|
|
Secrets are managed with krops’s integrated support for
|
|
|
|
|
[`pass`](https://www.passwordstore.org/). Permission management for them is
|
|
|
|
|
implemented in `modules/secrets.nix`.
|
|
|
|
|
|
2020-08-22 17:44:39 +02:00
|
|
|
|
## How to install
|
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
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).
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Set up wifi if no wired connection is available:
|
2020-08-24 11:11:23 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
wpa_passphrase "SSID" "PSK" | wpa_supplicant -B -i wlp4s0 -c/dev/stdin
|
2020-08-24 11:11:23 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Create the partition table (enter the indented lines in the repl):
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
parted /dev/sdX
|
2020-08-22 17:44:39 +02:00
|
|
|
|
mktable GPT
|
|
|
|
|
mkpart primary 1MiB 2MiB
|
|
|
|
|
mkpart primary 2MiB 500MiB
|
|
|
|
|
mkpart primary 500MiB 100%
|
|
|
|
|
set 1 bios_grub on
|
|
|
|
|
disk_toggle pmbr_boot
|
|
|
|
|
quit
|
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Format encrypted partition and open it:
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
cryptsetup luksFormat --type luks2 /dev/sdX3
|
|
|
|
|
cryptsetup open --type luks2 /dev/sdX3 HOSTNAME-pv
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Create LVM (replace `8G` with desired swap size):
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
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
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
|
|
|
|
**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
|
2021-01-27 21:55:04 +01:00
|
|
|
|
the following after opening the luks partition: `vgchange -ay`.
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Create filesystems:
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
mkfs.ext2 /dev/sdX2
|
|
|
|
|
mkfs.ext4 -L root /dev/HOSTNAME-vg/root
|
|
|
|
|
mkswap -L swap /dev/HOSTNAME-vg/swap
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Mount the file systems and activate swap:
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
mount /dev/HOSTNAME-vg/root /mnt
|
|
|
|
|
mkdir /mnt/boot
|
|
|
|
|
mount /dev/sdX2 /mnt/boot
|
|
|
|
|
swapon /dev/HOSTNAME-vg/swap
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2020-08-30 10:03:48 +02:00
|
|
|
|
Generate hardware configuration and copy hardware configuration to machine
|
2021-01-27 21:55:04 +01:00
|
|
|
|
configuration (skip this step if you already have a hardware-configuration for
|
|
|
|
|
this machine):
|
|
|
|
|
|
|
|
|
|
nixos-generate-config --root /mnt/
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-03-30 23:49:08 +02:00
|
|
|
|
Modify the hardware configuration as needed. Fill in the fields that have
|
|
|
|
|
comments in `machines/installation/configuration.nix` and copy it to
|
2021-01-27 21:55:04 +01:00
|
|
|
|
`/mnt/etc/nixos/configuration.nix`.
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Install NixOS:
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
nixos-install
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
Add the krops sentinel file:
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
mkdir -p /mnt/var/src
|
|
|
|
|
touch /mnt/var/src/.populate
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
After the successful instalation, reboot use `deploy HOSTNAME` on another
|
|
|
|
|
system to deploy the new system using krops, after adding the
|
|
|
|
|
`configuration.nix` and entry in `machines/default.nix` for the machine.
|
2020-08-22 17:44:39 +02:00
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
2021-01-27 21:55:04 +01:00
|
|
|
|
As nixpkgs, this repository is licensed under the [MIT License](LICENSE). This
|
|
|
|
|
only applies to the nix expressions, not the built system or package closure.
|
|
|
|
|
Patches may also be licensed differently, since they may be derivative works of
|
|
|
|
|
the packages to which they apply.
|