Sandro Jäckel
948309fef8
Flake lock file updates: • Updated input 'heliwatch': 'git+https://gitea.c3d2.de/astro/heliwatch.git?ref=refs/heads/master&rev=6dc6e161c200eaf061be632fb2f26df4008e4d36' (2024-11-05) → 'git+https://gitea.c3d2.de/astro/heliwatch.git?ref=refs/heads/master&rev=fb576af2ebbe3f92c24e911b79caa43609b458e8' (2024-12-10) • Updated input 'microvm': 'github:astro/microvm.nix/e08aed6e3a32e47e21e57bd2791326ea3f7647be?narHash=sha256-scaQMTs4NnGkd9SZWROr5m0vOZIIhRkk5N7Q%2BS9zhXQ%3D' (2024-12-10) → 'github:astro/microvm.nix/870cb181719aa12baf478d7cde6068ec7ed144ae?narHash=sha256-CeYsC8J2dNiV2FCQOxK1oZ/jNpOF2io7aCEFHmfi95U%3D' (2024-12-10) • Updated input 'nixos-hardware': 'github:nixos/nixos-hardware/e563803af3526852b6b1d77107a81908c66a9fcf?narHash=sha256-IS3bxa4N1VMSh3/P6vhEAHQZecQ3oAlKCDvzCQSO5Is%3D' (2024-12-06) → 'github:nixos/nixos-hardware/cf737e2eba82b603f54f71b10cb8fd09d22ce3f5?narHash=sha256-%2BjjPup/ByS0LEVIrBbt7FnGugJgLeG9oc%2BivFASYn2U%3D' (2024-12-10) • Updated input 'nixpkgs': 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=backports-24.11&rev=b6b3e9ca09d98093daaf4a635bc327e432767dea&shallow=1' (2024-12-10) → 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=backports-24.11&rev=41b753b6166f9ac32ae7e8044c117d5fa3020b81&shallow=1' (2024-12-10) • Updated input 'openwrt-imagebuilder': 'github:astro/nix-openwrt-imagebuilder/8b27c9cba0971849ada357b0333d07c4e82111a3?narHash=sha256-6U28G8R4XHc%2BaFLV5NeFz%2B5MT2S6FTk2/dCVQ1wM2pE%3D' (2024-12-10) → 'github:astro/nix-openwrt-imagebuilder/d792b6a831136767f1cb3c165119631ede13a51d?narHash=sha256-/iWvDj0EgNNX15WZTcORLxYsLCrRHsPwLuIBtMjnjLw%3D' (2024-12-11) • Updated input 'skyflake': 'github:astro/skyflake/40fb7a4fb248691014ba5b2c841f77a34d160a80?narHash=sha256-8IQFwDudLZmBLNlA3xnmN7kAAi3RuPelf4iY7Zmt7PI%3D' (2023-10-13) → 'github:astro/skyflake/ca6b44725aa2b2ead2965177fff24d6565145500?narHash=sha256-fQ1RN/wSQkOQA2w9A9L7UyLM1YFBgOO/65y%2BlRu%2BXAk%3D' (2024-12-10) • Updated input 'sshlogd': 'git+https://gitea.c3d2.de/astro/sshlogd.git?ref=refs/heads/main&rev=e5bd786db76612b62e8a152e8ffeca5ad062c34f' (2024-11-05) → 'git+https://gitea.c3d2.de/astro/sshlogd.git?ref=refs/heads/main&rev=8b997f20da27fd7a0329053e9c10b288ab389fbe' (2024-12-10) • Updated input 'ticker': 'git+https://gitea.c3d2.de/astro/ticker.git?ref=refs/heads/master&rev=fbcf0b650de2fcf6eae9803cf0dedccb8155ab1d' (2024-11-05) → 'git+https://gitea.c3d2.de/astro/ticker.git?ref=refs/heads/master&rev=735dd54f36e51eae3aafd73fbe7e09b52aa8b295' (2024-12-10) • Updated input 'yammat': 'git+https://gitea.c3d2.de/c3d2/yammat.git?ref=refs/heads/master&rev=05eff1ebc9f59603b48ce7c02c02993763d986d8' (2024-11-12) → 'git+https://gitea.c3d2.de/c3d2/yammat.git?ref=refs/heads/master&rev=508b2f104c9283821ac987750e48ddbe6a129fc7' (2024-12-10) |
||
---|---|---|
backgrounds | ||
config | ||
doc | ||
hosts | ||
keys | ||
lib | ||
modules | ||
overlays | ||
.git-blame-ignore-revs | ||
.gitattributes | ||
.gitignore | ||
.sops.yaml | ||
book.toml | ||
flake.lock | ||
flake.nix | ||
packages.nix | ||
README.md | ||
renovate.json | ||
ssh-public-keys.nix |
C3D2 infrastructure based on NixOS
Further documentation
Helpful tools
- NixOS option search
- Code search (including Nix repos we use)
Setup
Enable nix flakes user wide
Add the setting to the user nix.conf. Only do this once!
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
Enable nix flakes system wide (preferred for NixOS)
add this to your NixOS configuration:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
nixpkgs/nixos
The nixpkgs/nixos input used lives at https://github.com/supersandro2000/nixpkgs/tree/nixos-24.05. We are using a fork managed by sandro to make backports, cherry-picks and custom fixes dead easy. If you want to have an additional backport, cherry-pick or other change, please contact sandro.
nixos-modules repo
The nixos-modules repo lives at https://github.com/NuschtOS/nixos-modules and is mirrored to https://gitea.c3d2.de/c3d2/nixos-modules. Auto generated documentation about all options is available at https://nuschtos.github.io/nixos-modules/. It contains options sandro shares between his private nixos configs and the C3D2 one and which others also started to use. It sets many options by default and when searching for a particular setting you should always grep this repo, too. In question ask sandro and consider improving the documentation about this with comments and readme explanations. Something should be changed/added/removed/etc? Please create a PR or start a conversations with your ideas.
SSH access
If people should get root access to all machines, their keys should be added to ssh-public-keys.nix
.
Deployment
Deploy to a remote NixOS system
For every host that has a nixosConfiguration
in our Flake, there are two scripts that can be run for deployment via ssh.
-
nix run .#HOSTNAME-nixos-rebuild switch
Copies the current state to build on the target system. This may fail due to resource limits on eg. Raspberry Pis.
-
nix run .#HOSTNAME-nixos-rebuild-local switch
Builds everything locally, then uses
nix copy
to transfer the new NixOS system to the target.To use the cache from hydra set the following nix options similar to enabling flakes:
trusted-public-keys = hydra.hq.c3d2.de:KZRGGnwOYzys6pxgM8jlur36RmkJQ/y8y62e52fj1ps= extra-substituters = https://hydra.hq.c3d2.de
This can also be set with the
c3d2.addBinaryCache
option from the c3d2-user-module.
Checking for updates
nix run .#list-upgradable
Checks all hosts with a nixosConfiguration
in flake.nix
.
Update from Hydra build
The fastest way to update a system, a manual alternative to setting
c3d2.autoUpdate = true;
Just run:
update-from-hydra
Deploy a MicroVM
Build a microvm remotely and deploy
nix run .#microvm-update-HOSTNAME
Build microvm locally and deploy
nix run .#microvm-update-HOSTNAME-local
Update MicroVM from our Hydra
Our Hydra runs nix flake update
daily in the updater.timer
,
pushing it to the flake-update
branch so that it can build fresh
systems. This branch is setup as the source flake in all the MicroVMs,
so the following is all that is needed on a MicroVM-hosting server:
microvm -Ru $hostname
Cluster deployment with Skyflake
About
Skyflake provides Hyperconverged Infrastructure to run NixOS MicroVMs on a cluster. Our setup unifies networking with one bridge per VLAN. Persistent storage is replicated with Cephfs.
Recognize nixosConfiguration for our Skyflake deployment by the
self.nixosModules.cluster-options
module being included.
User interface
We use the less-privileged c3d2@
user for deployment. This flake's
name on the cluster is config
. Other flakes can coexist in the same
user so that we can run separately developed projects like
dump-dvb. leon and potentially other users can deploy Flakes and
MicroVMs without name clashes.
Deploying
git push this repo to any machine in the cluster, preferably to Hydra because there building won't disturb any services.
You don't deploy all MicroVMs at once. Instead, Skyflake allows you to select NixOS systems by the branches you push to. You must commit before you push!
Example: deploy nixosConfigurations mucbot
and sdrweb
(HEAD
is your
current commit)
git push c3d2@hydra.serv.zentralwerk.org:config HEAD:mucbot HEAD:sdrweb
This will:
- Build the configuration on Hydra, refusing the branch update on broken builds (through a git hook)
- Copy the MicroVM package and its dependencies to the binary cache that is accessible to all nodes with Cephfs
- Submit one job per MicroVM into the Nomad cluster
Deleting a nixosConfiguration's branch will stop the MicroVM in Nomad.
Updating
TODO: how would you like it?
MicroVM status
ssh c3d2@hydra.serv.zentralwerk.org status
Debugging for cluster admins
Nomad
Check the cluster state
nomad server members
Nomad servers coordinate the cluster.
Nomad clients run the tasks.
Browse in the terminal
wander and damon are nice TUIs that are preinstalled on our cluster nodes.
Browse with a browser
First, tunnel TCP port :4646
from a cluster server:
ssh -L 4646:localhost:4646 root@server10.cluster.zentralwerk.org
Then, visit https://localhost:4646 for for full klickibunti.
Reset the Nomad state on a node
After upgrades, Nomad servers may fail rejoining the cluster. Do this to make a Nomad server behave like a newborn:
systemctl stop nomad
rm -rf /var/lib/nomad/server/raft/
systemctl start nomad
Secrets management
Secrets Management Using sops-nix
Adding a new host
Edit .sops.yaml
:
- Add an AGE key for this host. Comments in this file tell you how to do it.
- Add a
creation_rules
section forhost/$host/*.yaml
files
Editing a hosts secrets
Edit .sops.yaml
to add files for a new host and its SSH pubkey.
# Get sops
nix develop
# Decrypt, start en EDITOR, encrypt
sops hosts/.../secrets.yaml
# Push
git commit -a -m "Add new secrets for new server"
git push
Secrets management with PGP
Add your gpg-id to the .gpg-id file in secrets and let somebody re-encrypt it for you. Maybe this works for you, maybe not. I did it somehow:
PASSWORD_STORE_DIR=$(pwd) tr '\n' ' ' < .gpg-id | xargs -I{} pass init {}
Your gpg key has to have the Authenticate flag set. If not update it and push it to a keyserver and wait. This is necessary, so you can login to any machine with your gpg key.
Laptops / Desktops
This repo could be used in the past as a module. While still technically possible, it is not recommended because the amounts of flake inputs highly increased and the modules are not designed with that in mind.
For end user modules take a look at the c3d2-user-module.
For the deployment options take a look at deployment.
File system setup
Set the disko
options for the machine and run:
$(nix --extra-experimental-features "flakes nix-command" build --print-out-paths --no-link -L '.#nixosConfigurations.HOSTNAME.config.system.build.diskoScript')
When adding new disks the paths under /dev/disk/by-id/
should be used, so that the script is idempotent across device restarts.
Install new server
- Copy the nix files from an existing, similar host.
- Disable all secrets until after the installation is finished.
- Set
simd.arch
option to the output ofnix --extra-experimental-features "flakes nix-command" shell nixpkgs#gcc -c gcc -march=native -Q --help=target | grep march
and update the comment next to it- If that returns
x86_64
search on a search engine for theark.intel.com
entry for the processor which can be found by catting/proc/cpuinfo
- If that returns
- Generate
networking.hostId
withhead -c4 /dev/urandom | od -A none -t x4
according to the options description. - Boot live ISO
- If your ssh key is not baked into the iso, set a password for the
nixos
with passwd to be able to log in over ssh.
- If your ssh key is not baked into the iso, set a password for the
rsync
the this directory into the live system.- Stop the raid if one booted up
mdadm --stop /dev/md126
- generate and apply disk layout with disko (see above).
- Generate
hardware-configuration.nix
withsudo nixos-generate-config --root /mnt
.- If luks disks should be decrypted in initrd over ssh then:
- Make sure
boot.initrd.luks.devices.*.devices
is set. - Enable
boot.initrd.network.enable
andboot.initrd.network.ssh.enable
- Add the required kernel modules, which can be found with
lshw -C network
(look fordriver=
), for the network interfaces in initrd toboot.initrd.availableKernelModules
. - Enable DHCP in the
hardware-configuration.nix
for all interfaces
- Make sure
- If luks disks should be decrypted in initrd over ssh then:
- Install nixos system with
sudo nixos-install --root /mnt --no-channel-copy --flake .#HOSTNAME
. - After a reboot add the age key to sops-nix with
nix shell nixpkgs#ssh-to-age
andssh-to-age < /etc/ssh/ssh_host_ed25519_key.pub
. - Add
/etc/machine-id
and luks password to sops secrets. - Enable and deploy secrets again.
- Improve new machine setup by automating easy to automate steps and document others.
- Commit everything and push