Sandro Jäckel
bc652e852a
Flake lock file updates: • Updated input 'buzzrelay': 'github:astro/buzzrelay/98b976dc8118d232650e79956955f1af43752828?narHash=sha256-nI0gC9GrhBYApufqDxWfUpYGYFGCC6WIcpFKrJ04sb4%3D' (2024-10-29) → 'github:astro/buzzrelay/95fe271d9ab933e238c55304c96f1ba47dca2ccf?narHash=sha256-asplXZWqItbH7XG/Qi3xwlJMQUqlI7buq3cm4ZHp0RI%3D' (2024-11-04) • Updated input 'c3d2-user-module': 'git+https://gitea.c3d2.de/c3d2/nix-user-module.git?ref=refs/heads/master&rev=455cad6b16a1608544db2dadc703a73306ff4488' (2024-10-22) → 'git+https://gitea.c3d2.de/c3d2/nix-user-module.git?ref=refs/heads/master&rev=966e97fd1b1f31237d5510591726a51bce4cedf7' (2024-11-05) • Updated input 'caveman': 'git+https://gitea.c3d2.de/astro/caveman.git?ref=refs/heads/main&rev=4f9956dc12a4cc210342995aaa178b6a9f7b8d9c' (2024-10-15) → 'git+https://gitea.c3d2.de/astro/caveman.git?ref=refs/heads/main&rev=7b997caec70331de95334bba0104e2623fa4bb6c' (2024-11-05) • Updated input 'disko': 'github:nix-community/disko/3979285062d6781525cded0f6c4ff92e71376b55?narHash=sha256-o5m5WzvY6cGIDupuOvjgNSS8AN6yP2iI9MtUC6q/uos%3D' (2024-10-29) → 'github:nix-community/disko/856a2902156ba304efebd4c1096dbf7465569454?narHash=sha256-sdY29RWz0S7VbaoTwSy6RummdHKf0wUTaBlqPxrtvmQ%3D' (2024-11-04) • Updated input 'dns': 'git+https://gitea.c3d2.de/c3d2/dns.git?ref=refs/heads/master&rev=ce7220a0778a0c9f68e56295961c675c832c9878' (2024-11-01) → 'git+https://gitea.c3d2.de/c3d2/dns.git?ref=refs/heads/master&rev=9c32a7b24ae378c06a996d44123c2062cc244bb2' (2024-11-05) • Updated input 'fenix': 'github:nix-community/fenix/a9d2e5fa8d77af05240230c9569bbbddd28ccfaf?narHash=sha256-tvN9v5gTxLI5zOKsNvYl1aUxIitHm8Nj3vKdXNfJo50%3D' (2024-10-01) → 'github:nix-community/fenix/87b4d20f896c99018dde4702a9c6157b516f2a76?narHash=sha256-U1DWb5c3EfkA7pqx5V1H4AWRA%2BEaE6UJ0lIRvK1RxgM%3D' (2024-11-01) • Updated input 'fenix/rust-analyzer-src': 'github:rust-lang/rust-analyzer/28830ff2f1158ee92f4852ef3ec35af0935d1562?narHash=sha256-xxgUHwwJ%2B1xQQoUWvLDo807IZ0MDldkfr9N1G4fvNJU%3D' (2024-09-30) → 'github:rust-lang/rust-analyzer/0ba893e1a00d92557ac91efb771d72eee36ca687?narHash=sha256-0Uq%2B/B8eu7pw8B8pxuGdFYKjcVLwNMcHfDxU9sXh7rg%3D' (2024-10-31) • Updated input 'heliwatch': 'git+https://gitea.c3d2.de/astro/heliwatch.git?ref=refs/heads/master&rev=2a0901b5d9e4add54e7ee1a08113aad28fff614e' (2024-10-15) → 'git+https://gitea.c3d2.de/astro/heliwatch.git?ref=refs/heads/master&rev=6dc6e161c200eaf061be632fb2f26df4008e4d36' (2024-11-05) • Updated input 'microvm': 'github:astro/microvm.nix/6ff444ef6cfd5d2effb6c4f50da2ca6f20f2677f?narHash=sha256-ZiQPP6LE%2BSLKbS0UYNeDax08whSXlhZeniDzzLQGVEw%3D' (2024-10-30) → 'github:astro/microvm.nix/93122446d6001f9789d05e565f73bebfa3f53b50?narHash=sha256-RxV89z3TwhQT0Wue42aSPh3O7hXGbAFYHHNSnW9h6P8%3D' (2024-11-01) • Updated input 'nixos-hardware': 'github:nixos/nixos-hardware/07d15e8990d5d86a631641b4c429bc0a7400cfb8?narHash=sha256-z5ILcmwMtiCoHTXS1KsQWqigO7HJO8sbyK7f7wn9F/E%3D' (2024-10-29) → 'github:nixos/nixos-hardware/2e78b1af8025108ecd6edaa3ab09695b8a4d3d55?narHash=sha256-XrnZLkLiBYNlwV5gus/8DT7nncF1TS5la6Be7rdVOpI%3D' (2024-11-05) • Updated input 'nixos-modules': 'github:NuschtOS/nixos-modules/a58cb29c730c2aefaa5ce880255ea7118dc352f2?narHash=sha256-Vz/imEXFipKBzNLjpXdfhX5u0jAyw6GbXRJqc9DkBCk%3D' (2024-10-30) → 'github:NuschtOS/nixos-modules/49e201d923ad8e95b462477c14beaba72c0eb3c7?narHash=sha256-9GQ0WESPtM5oMpSRYuNZp1MecVpQLqWzUnWQsBliFIM%3D' (2024-11-05) • Updated input 'nixpkgs': 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=backports-24.05&rev=4590e3bcd1a4f2f7083288e934fdfd51fc5bbfce&shallow=1' (2024-10-31) → 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=backports-24.05&rev=73943c414266db5ec0e980e678e77458f00379d2&shallow=1' (2024-11-05) • Updated input 'nixpkgs-taler': 'github:eljamm/nixpkgs/81c0838375f7999d0a11f8776210ea70f8539ad9?narHash=sha256-g9xcmhHBGdu%2Bgs%2B9inZyOD2TSJjH0uASzrIrYL6C9H8%3D' (2024-10-29) → 'github:eljamm/nixpkgs/9b47f79ce96cb0e23664975c6f1aa2e435b48ddc?narHash=sha256-8qKVDr%2BDsUff8Eh68I4r8jqJJTH9njGVRktN7Wp3n1g%3D' (2024-11-01) • Updated input 'nixpkgs-unstable': 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=nixos-unstable&rev=49e9f9ce64a6b15b0a001815b2756a3ad919106d&shallow=1' (2024-10-27) → 'git+https://github.com/NuschtOS/nuschtpkgs.git?ref=nixos-unstable&rev=6325fc4eff0863d818844fca99b435e3fc5a095f&shallow=1' (2024-11-03) • Updated input 'nuschtos-search': 'github:NuschtOS/search/4e0a7a95a3df3333771abc4df6a656e7baf67106?narHash=sha256-uTxvqDohfG85%2BzldO5Tf1B%2BfuAF8ZhMouNwG5S6OAnA%3D' (2024-10-31) → 'github:NuschtOS/search/aa5214c81b904a19f7a54f7a8f288f7902586eee?narHash=sha256-F4H98tjNgySlSLItuOqHYo9LF85rFoS/Vr0uOrq7BM4%3D' (2024-11-04) • Updated input 'nuschtos-search/ixx': 'github:NuschtOS/ixx/65c207c92befec93e22086da9456d3906a4e999c?narHash=sha256-YcyJLvTmN6uLEBGCvYoMLwsinblXMkoYkNLEO4WnKus%3D' (2024-10-21) → 'github:NuschtOS/ixx/9fd01aad037f345350eab2cd45e1946cc66da4eb?narHash=sha256-EiOq8jF4Z/zQe0QYVc3%2BqSKxRK//CFHMB84aYrYGwEs%3D' (2024-10-26) • Updated input 'openwrt': 'git+https://git.openwrt.org/openwrt/openwrt.git?ref=openwrt-23.05&rev=c46b689149ac18d654d12dfddeb102feb938e4aa' (2024-10-29) → 'git+https://git.openwrt.org/openwrt/openwrt.git?ref=openwrt-23.05&rev=e70669e6901e579d46bb67ee95e348b8e9fb79fb' (2024-11-05) • Updated input 'openwrt-imagebuilder': 'github:astro/nix-openwrt-imagebuilder/cc2ebbaf08fa86da15b3c0048b8737b776d83cc5?narHash=sha256-6bMT4p61ln/fuug7HLg6M7IGp58tTAq2jOSzracbjHE%3D' (2024-10-30) → 'github:astro/nix-openwrt-imagebuilder/7e427dc22bad8a090cfa66c9fc1bb6013587938c?narHash=sha256-CKGA24HkkUWnsAvCmjtyqSQS/tc1j6SRqzR0XMAxvwI%3D' (2024-11-05) • Updated input 'sops-nix': 'github:Mic92/sops-nix/1666d16426abe79af5c47b7c0efa82fd31bf4c56?narHash=sha256-qm0uCtM9bg97LeJTKQ8dqV/FvqRN%2BompyW4GIJruLuw%3D' (2024-10-27) → 'github:Mic92/sops-nix/59d6988329626132eaf107761643f55eb979eef1?narHash=sha256-ZGmI%2B3AbT8NkDdBQujF%2BHIxZ%2BsWXuyT6X8B49etWY2g%3D' (2024-11-04) • Updated input 'sshlogd': 'git+https://gitea.c3d2.de/astro/sshlogd.git?ref=refs/heads/main&rev=e724c1d97275e50db8c470693b4d547ffba1a158' (2024-10-09) → 'git+https://gitea.c3d2.de/astro/sshlogd.git?ref=refs/heads/main&rev=e5bd786db76612b62e8a152e8ffeca5ad062c34f' (2024-11-05) • Updated input 'ticker': 'git+https://gitea.c3d2.de/astro/ticker.git?ref=refs/heads/master&rev=ee0b43f0d4f6929a97549104d6b165fbf080873f' (2024-11-04) → 'git+https://gitea.c3d2.de/astro/ticker.git?ref=refs/heads/master&rev=fbcf0b650de2fcf6eae9803cf0dedccb8155ab1d' (2024-11-05) • Updated input 'zentralwerk': 'git+https://gitea.c3d2.de/zentralwerk/network.git?ref=refs/heads/master&rev=e5fa22ced70e175a68e79a6fec64e8007170f142' (2024-10-30) → 'git+https://gitea.c3d2.de/zentralwerk/network.git?ref=refs/heads/master&rev=1452b3b8778f2465a0423a26d243e1e884911bde' (2024-11-05) • Updated input 'zentralwerk/c3d2-dns': 'git+https://gitea.c3d2.de/c3d2/dns.git?ref=refs/heads/master&rev=116c2ba2dd92676735f92085a634acdb38e7b3ad' (2024-10-23) → 'git+https://gitea.c3d2.de/c3d2/dns.git?ref=refs/heads/master&rev=9c32a7b24ae378c06a996d44123c2062cc244bb2' (2024-11-05) |
||
---|---|---|
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 build --print-out-paths --no-link -L '.#nixosConfigurations.HOSTNAME.config.system.build.disko')
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 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.- generate and apply disk layout with disko (see above).
- Generate
hardware-configuration.nix
withsudo nixos-generate-config --no-filesystems --root /mnt
.- If luks disks should be decrypted in initrd over ssh, enable DHCP in the
hardware-configuration.nix
for the interfaces that should be used for that.
- If luks disks should be decrypted in initrd over ssh, enable DHCP in the
- Install nixos system with
sudo nixos-install --root /mnt --no-channel-copy --no-root-passwd --flake .#HOSTNAME
. - After a reboot add 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