nix-config/flake.nix
2023-02-12 19:53:41 +01:00

826 lines
22 KiB
Nix

{
description = "C3D2 NixOS configurations";
nixConfig = {
extra-substituters = [ "https://nix-serve.hq.c3d2.de" ];
extra-trusted-public-keys = [ "nix-serve.hq.c3d2.de:KZRGGnwOYzys6pxgM8jlur36RmkJQ/y8y62e52fj1ps=" ];
};
inputs = {
# use sandro's fork full with cherry-picked fixes
nixos.url = "github:SuperSandro2000/nixpkgs/nixos-22.11";
nixos-mobilizon.url = "github:minijackson/nixpkgs/init-mobilizon";
nixos-hardware.url = "github:nixos/nixos-hardware";
# nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# nixos-unstable-simd.url = "github:SuperSandro2000/nixpkgs/nixos-unstable-simd";
affection-src = {
url = "git+https://gitea.nek0.eu/nek0/affection";
inputs = {
nixpkgs.follows = "nixos";
flake-utils.follows = "flake-utils";
};
};
alert2muc = {
url = "git+https://gitea.c3d2.de/astro/alert2muc";
inputs = {
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
utils.follows = "flake-utils";
};
};
bevy-mandelbrot = {
# url = "github:matelab/bevy_mandelbrot";
url = "git+https://gitea.c3d2.de/astro/bevy-mandelbrot.git?ref=main";
inputs = {
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
rust-overlay.follows = "rust-overlay";
};
};
bevy-julia = {
# url = "github:matelab/bevy_julia";
url = "git+https://gitea.c3d2.de/astro/bevy-julia.git?ref=main";
inputs = {
nixpkgs.follows = "nixos";
naersk.follows = "naersk";
rust-overlay.follows = "rust-overlay";
};
};
buzz2elastic = {
url = "git+https://gitea.c3d2.de/astro/buzz2elastic";
inputs = {
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
utils.follows = "flake-utils";
};
};
buzzrelay = {
url = "github:astro/buzzrelay";
inputs = {
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
utils.follows = "flake-utils";
};
};
caveman = {
url = "git+https://gitea.c3d2.de/astro/caveman.git?ref=main";
inputs = {
nixpkgs.follows = "nixos";
utils.follows = "flake-utils";
fenix.follows = "fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
naersk.follows = "naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
};
};
c3d2-user-module = {
url = "git+https://gitea.c3d2.de/C3D2/nix-user-module.git";
inputs = {
nixos-modules.follows = "nixos-modules";
nixpkgs-lib.follows = "nixos";
};
};
deployment = {
url = "git+https://gitea.c3d2.de/C3D2/deployment.git";
inputs = {
zentralwerk.follows = "zentralwerk";
};
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixos";
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixos";
};
flake-utils.url = "github:numtide/flake-utils";
harmonia = {
url = "github:nix-community/harmonia";
inputs = {
flake-parts.follows = "flake-parts";
nixpkgs.follows = "nixos";
};
};
heliwatch = {
url = "git+https://gitea.c3d2.de/astro/heliwatch.git";
inputs = {
fenix.follows = "fenix";
nixpkgs.follows = "nixos";
naersk.follows = "naersk";
utils.follows = "flake-utils";
};
};
# hydra-ca.url = "github:mlabs-haskell/hydra/aciceri/ca-derivations";
microvm = {
url = "github:astro/microvm.nix";
inputs = {
nixpkgs.follows = "nixos";
flake-utils.follows = "flake-utils";
};
};
naersk = {
url = "github:nix-community/naersk";
inputs = {
nixpkgs.follows = "nixos";
};
};
nixos-modules = {
url = "github:SuperSandro2000/nixos-modules";
inputs.nixpkgs-lib.follows = "nixos";
};
oparl-scraper = {
url = "github:offenesdresden/ratsinfo-scraper/oparl";
flake = false;
};
openwrt = {
url = "git+https://git.openwrt.org/openwrt/openwrt.git?ref=openwrt-21.02";
flake = false;
};
openwrt-imagebuilder = {
url = "github:astro/nix-openwrt-imagebuilder";
inputs = {
nixpkgs.follows = "nixos";
};
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixos";
};
};
scrapers = {
url = "git+https://gitea.c3d2.de/astro/scrapers.git";
flake = false;
};
skyflake = {
url = "github:astro/skyflake";
inputs = {
microvm.follows = "microvm";
nixpkgs.follows = "nixos";
};
};
sshlogd = {
url = "git+https://gitea.c3d2.de/astro/sshlogd.git?ref=main";
inputs = {
utils.follows = "flake-utils";
naersk.follows = "naersk";
nixpkgs.follows = "nixos";
fenix.follows = "fenix";
};
};
# deprecated
secrets.url = "git+ssh://gitea@gitea.c3d2.de/c3d2-admins/secrets.git";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs = {
nixpkgs.follows = "nixos";
nixpkgs-stable.follows = "nixos";
};
};
spacemsg = {
url = "github:astro/spacemsg";
flake = false;
};
ticker = {
url = "git+https://gitea.c3d2.de/astro/ticker.git";
inputs = {
fenix.follows = "fenix";
# causes build failure
# naersk.follows = "naersk";
nixpkgs.follows = "nixos";
utils.follows = "flake-utils";
};
};
tigger = {
url = "github:astro/tigger";
flake = false;
};
tracer = {
# url = "git+https://gitea.nek0.eu/nek0/tracer";
url = "git+https://gitea.c3d2.de/astro/tracer";
inputs = {
affection-src.follows = "affection-src";
nixpkgs.follows = "nixos";
flake-utils.follows = "flake-utils";
};
};
yammat = {
url = "git+https://gitea.c3d2.de/C3D2/yammat.git";
inputs.nixpkgs.follows = "nixos";
};
zentralwerk = {
url = "git+https://gitea.c3d2.de/zentralwerk/network.git";
inputs = {
nixpkgs.follows = "nixos";
openwrt.follows = "openwrt";
openwrt-imagebuilder.follows = "openwrt-imagebuilder";
};
};
};
outputs = inputs@{ self, alert2muc, c3d2-user-module, deployment, fenix, harmonia, heliwatch, microvm, naersk, nixos, nixos-hardware, nixos-modules, buzz2elastic, buzzrelay, caveman, oparl-scraper, scrapers, secrets, skyflake, sshlogd, sops-nix, spacemsg, ticker, tigger, yammat, zentralwerk, ... }:
let
inherit (nixos) lib;
extractZwHosts = { hosts4, hosts6, ... }:
lib.recursiveUpdate (
builtins.foldl' (result: name:
lib.recursiveUpdate result {
"${name}".ip4 = hosts4."${name}";
}
) {} (builtins.attrNames hosts4)
) (
builtins.foldl' (result: ctx:
builtins.foldl' (result: name:
lib.recursiveUpdate result {
"${name}".ip6 = hosts6."${ctx}"."${name}";
}
) result (builtins.attrNames hosts6."${ctx}")
) {} (builtins.attrNames hosts6)
);
hostRegistry =
builtins.foldl' (result: net:
lib.recursiveUpdate result (extractZwHosts zentralwerk.lib.config.site.net."${net}")
) {} [ "core" "cluster" "c3d2" "serv" "flpk" "pub" ];
overlayList = [
fenix.overlays.default
heliwatch.overlay
naersk.overlay
self.overlays
];
# Our custom NixOS builder
nixosSystem' =
{ nixpkgs ? inputs.nixos
, modules
, system ? "x86_64-linux"
}@args:
{ inherit args; } // lib.nixosSystem {
inherit system;
modules = [
(_: {
_module.args = {
inherit hostRegistry inputs zentralwerk;
};
nixpkgs.overlays = overlayList;
})
self.nixosModules.c3d2
c3d2-user-module.nixosModule
harmonia.nixosModules.harmonia
nixos-modules.nixosModule
./config
./modules/audio-server.nix
./modules/c3d2.nix
./modules/stats.nix
./modules/pi-sensors.nix
] ++ modules;
};
in {
overlays = import ./overlays {
inherit (inputs) tracer bevy-mandelbrot bevy-julia;
};
legacyPackages = lib.attrsets.mapAttrs (_: pkgs: pkgs.appendOverlays overlayList) nixos.legacyPackages;
lib = { inherit hostRegistry; };
packages = import ./packages.nix { inherit hostRegistry inputs lib microvm secrets self; };
nixosConfigurations = {
auth = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/auth
];
};
bind = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/bind
];
};
blogs = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/blogs
];
};
broker = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/broker
];
};
buzzrelay = nixosSystem' {
modules = [
self.nixosModules.microvm
buzzrelay.nixosModules.default
./hosts/buzzrelay
];
};
c3d2-web = nixosSystem' {
modules = [
{ _module.args = { inherit nixos; }; }
self.nixosModules.microvm
./hosts/c3d2-web
];
};
caveman = nixosSystem' {
modules = [
self.nixosModules.microvm
caveman.nixosModule
./hosts/caveman
];
};
dacbert = nixosSystem' {
modules = [
nixos-hardware.nixosModules.raspberry-pi-4
self.nixosModules.rpi-netboot
./hosts/dacbert
];
system = "aarch64-linux";
};
dn42 = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/dn42
{
# TODO: migrate to sops
nixpkgs.overlays = [ secrets.overlays.dn42 ];
}
];
};
direkthilfe = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/direkthilfe
];
};
drone = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/drone
];
};
factorio = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/factorio
];
};
freifunk = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/freifunk
{
# TODO: migrate to sops
nixpkgs.overlays = with secrets.overlays; [
freifunk ospf
];
}
];
};
ftp = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/ftp
];
};
gitea = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/gitea
];
};
glotzbert = nixosSystem' {
modules = [
./hosts/glotzbert
nixos-hardware.nixosModules.common-cpu-intel
nixos-hardware.nixosModules.common-pc-ssd
];
};
gnunet = nixosSystem' {
modules = [
self.nixosModules.cluster-options
./hosts/gnunet
];
};
grafana = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/grafana
];
};
hedgedoc = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/hedgedoc
];
};
hydra = nixosSystem' {
modules = [
self.nixosModules.cluster
skyflake.nixosModules.default
harmonia.nixosModules.harmonia
./hosts/hydra
];
};
jabber = nixosSystem' {
modules = [
{
# TODO: migrate to sops
nixpkgs.overlays = with secrets.overlays; [ jabber ];
}
self.nixosModules.microvm
./hosts/jabber
];
};
leon = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/leon
];
};
leoncloud = nixosSystem' {
modules = [
self.nixosModules.cluster-options
./hosts/leoncloud
];
};
mailtngbert = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/mailtngbert
];
system = "x86_64-linux";
};
mastodon = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/mastodon
];
};
matemat = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/matemat
yammat.nixosModule
];
};
mediawiki = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/mediawiki
];
};
mobilizon = nixosSystem' {
# TODO: pending https://github.com/NixOS/nixpkgs/pull/119132
# cherry-picked by sandro into his 22.11 fork
# nixpkgs = inputs.nixos-mobilizon;
modules = [
self.nixosModules.microvm
./hosts/mobilizon
];
};
mucbot = nixosSystem' {
modules = [
"${tigger}/module.nix"
{
_module.args = { inherit tigger; };
# TODO: migrate to sops
nixpkgs.overlays = [ secrets.overlays.mucbot ];
}
./hosts/mucbot
self.nixosModules.cluster-options
];
};
network-homepage = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/network-homepage
];
};
nfsroot = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/nfsroot
{
_module.args.tftproots = nixos.lib.filterAttrs (name: _:
builtins.match ".+-tftproot" name != null
) self.packages.x86_64-linux;
}
];
};
nncp = nixosSystem' {
modules = [
self.nixosModules.microvm
self.nixosModules.nncp
./hosts/nncp
];
};
oparl = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/oparl
{
_module.args = { inherit oparl-scraper; };
}
];
};
owncast = nixosSystem' {
modules = [
self.nixosModules.cluster-options
./hosts/owncast
];
};
oxigraph = nixosSystem' {
modules = [
self.nixosModules.cluster-options
./hosts/oxigraph
];
};
prometheus = nixosSystem' {
modules = [
self.nixosModules.microvm
alert2muc.nixosModules.default
./hosts/prometheus
];
};
pulsebert = nixosSystem' {
modules = [
./hosts/pulsebert
# build: outputs.nixosConfigurations.pulsebert.config.system.build.sdImage
# run: unzstd -cd result/sd-image/nixos-sd-image-*-aarch64-linux.img.zst | pv -br | sudo dd bs=4M of=/dev/sdX
"${inputs.nixos}/nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel.nix"
{
nixpkgs = {
hostPlatform = "aarch64-linux";
# buildPlatform = "x86_64-linux";
};
}
];
};
public-access-proxy = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/public-access-proxy
];
};
radiobert = nixosSystem' {
modules = [
./hosts/radiobert
];
system = "aarch64-linux";
};
riscbert = nixosSystem' {
modules = [
nixos-hardware.nixosModules.starfive-visionfive-v1
./hosts/riscbert
{
nixpkgs.crossSystem = {
config = "riscv64-unknown-linux-gnu";
system = "riscv64-linux";
};
}
];
system = "x86_64-linux";
};
rpi-netboot = nixosSystem' {
modules = [
{ _module.args = { inherit nixos; }; }
nixos-hardware.nixosModules.raspberry-pi-4
self.nixosModules.rpi-netboot
./hosts/rpi-netboot
];
system = "aarch64-linux";
};
schalter = nixosSystem' {
modules = [
"${nixos}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix"
./hosts/schalter
];
system = "x86_64-linux";
};
scrape = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/scrape
{
_module.args = { inherit scrapers; };
# TODO: migrate to sops
nixpkgs.overlays = [ secrets.overlays.scrape ];
}
];
};
sdrweb = nixosSystem' {
modules = [
self.nixosModules.cluster-options
{
# TODO: migrate to sops
nixpkgs.overlays = [ secrets.overlays.mucbot ];
}
heliwatch.nixosModules.heliwatch
./hosts/sdrweb
];
};
server8 = nixosSystem' {
modules = [
./hosts/server8
self.nixosModules.cluster-network
self.nixosModules.cluster
skyflake.nixosModules.default
{ _module.args = { inherit self; }; }
];
};
server9 = nixosSystem' {
modules = [
./hosts/server9
microvm.nixosModules.host
self.nixosModules.microvm-host
self.nixosModules.cluster-network
self.nixosModules.cluster
skyflake.nixosModules.default
{ _module.args = { inherit self; }; }
];
};
server10 = nixosSystem' {
modules = [
./hosts/server10
microvm.nixosModules.host
self.nixosModules.microvm-host
self.nixosModules.cluster-network
self.nixosModules.cluster
skyflake.nixosModules.default
{ _module.args = { inherit self; }; }
];
};
spaceapi = nixosSystem' {
modules = [
self.nixosModules.microvm
"${spacemsg}/spaceapi/module.nix"
./hosts/spaceapi
];
};
sshlog = nixosSystem' {
modules = [
self.nixosModules.cluster-options
sshlogd.nixosModule
./hosts/sshlog
];
};
stream = nixosSystem' {
modules = [
self.nixosModules.cluster-options
./hosts/stream
];
};
ticker = nixosSystem' {
modules = [
self.nixosModules.microvm
ticker.nixosModules.ticker
./hosts/ticker
];
};
tmppleroma = nixosSystem' {
modules = [
self.nixosModules.cluster-options
sshlogd.nixosModule
./hosts/tmppleroma
];
};
zengel = nixosSystem' {
modules = [
self.nixosModules.microvm
./hosts/zengel
];
};
};
nixosModules = {
c3d2 = {
imports = [
sops-nix.nixosModule
./modules/audio-server.nix
./modules/autoupdate.nix
./modules/backup.nix
./modules/c3d2.nix
./modules/nncp.nix
./modules/monitoring.nix
./modules/plume.nix
./modules/stats.nix
];
c3d2.sshKeys = (import ./ssh-public-keys.nix).users;
c3d2.nncp.neigh = import ./modules/nncp-relays.nix;
};
cluster = ./modules/cluster;
cluster-options = deployment.nixosModules.deployment-options;
cluster-network = ./modules/cluster/network.nix;
microvm.imports = [
microvm.nixosModules.microvm
./modules/microvm.nix
];
microvm-host = ./modules/microvm-host.nix;
nncp = ./modules/nncp.nix;
rpi-netboot = ./modules/rpi-netboot.nix;
};
# `nix develop`
devShell = lib.mapAttrs (system: sopsPkgs:
with nixos.legacyPackages.${system};
mkShell {
sopsPGPKeyDirs = [ "./keys" ];
nativeBuildInputs = [
sopsPkgs.sops-import-keys-hook
];
}
) sops-nix.packages;
hydraJobs =
lib.mapAttrs (_: nixos.lib.hydraJob) (
let
getBuildEntryPoint = _: nixosSystem: nixosSystem.config.microvm.declaredRunner or nixosSystem.config.system.build.toplevel;
in
lib.mapAttrs getBuildEntryPoint self.nixosConfigurations
# // lib.mapAttrs' (hostname: nixosSystem: lib.nameValuePair
# # job display name
# (hostname + "-nox")
# (getBuildEntryPoint null (nixosSystem' (nixosSystem.args // (with nixosSystem.args; {
# modules = modules ++ [
# {
# # simd.enable = lib.mkForce true;
# environment.noXlibs = true;
# }
# ];
# # nixpkgs = nixos-unstable-simd;
# }))))
# ) self.nixosConfigurations
// nixos.lib.filterAttrs (name: attr:
(builtins.match ".+-tftproot" name != null && lib.isDerivation attr)
) self.packages.aarch64-linux
);
};
}