nix-config/flake.nix

256 lines
7.4 KiB
Nix
Raw Normal View History

{
description = "C3D2 NixOS configurations";
2020-06-11 07:50:42 +02:00
inputs = {
2021-06-07 02:30:56 +02:00
nixpkgs.url = "github:nixos/nixpkgs/release-21.05";
2021-02-24 11:52:19 +01:00
secrets.url = "git+ssh://git@gitea.c3d2.de:2222/c3d2-admins/secrets.git";
2021-03-06 01:13:27 +01:00
yammat.url = "git+https://gitea.c3d2.de/astro/yammat.git?ref=nix";
2021-03-10 01:54:28 +01:00
yammat.inputs.nixpkgs.follows = "nixpkgs";
scrapers.url = "git+https://gitea.c3d2.de/astro/scrapers.git";
scrapers.flake = false;
2021-03-22 16:22:57 +01:00
tigger.url = "github:astro/tigger";
tigger.flake = false;
2020-06-11 07:50:42 +02:00
};
2020-04-15 19:00:56 +02:00
2021-03-22 16:22:57 +01:00
outputs = { self, nixpkgs, secrets, nixos-hardware, yammat, scrapers, tigger }:
2021-02-22 12:31:58 +01:00
let
2021-03-03 16:20:17 +01:00
forAllSystems = nixpkgs.lib.genAttrs [ "aarch64-linux" "x86_64-linux" ];
2021-02-24 11:52:19 +01:00
hostRegistry = import ./host-registry.nix;
2021-02-22 12:31:58 +01:00
in {
2021-02-26 20:22:15 +01:00
overlay = import ./overlay;
legacyPackages = forAllSystems
(system: nixpkgs.legacyPackages.${system}.extend self.overlay);
2021-02-22 12:31:58 +01:00
packages = forAllSystems (system:
let
pkgs = self.legacyPackages.${system};
mkDeploy =
# Generate a small script for copying this flake to the
# remote machine and bulding and switching there.
# Can be run with nix run c3d2#deploy-…
{ name
, host ? "${name}.hq.c3d2.de"
# remote builders to pass
, builders ? null
}:
2021-02-22 12:31:58 +01:00
let target = "root@${host}";
rebuildArg =
"--flake ${self}#${name}" +
(if builders != null
then " --builders \"" +
builtins.concatStringsSep " " builders +
"\""
else "");
2021-02-22 12:31:58 +01:00
in pkgs.writeScriptBin "${name}-nixos-rebuild" ''
2021-06-07 02:30:16 +02:00
#!${pkgs.runtimeShell} -e
2021-03-04 00:47:05 +01:00
nix-copy-closure --to ${target} ${secrets}
2021-02-22 12:31:58 +01:00
nix-copy-closure --to ${target} ${self}
if [ "$1" = "--flakify" ]; then
shift
exec ssh -t ${target} "nix-shell -p nixFlakes -p git --command '_NIXOS_REBUILD_REEXEC=1 nixos-rebuild ${rebuildArg} '$@"
else
exec ssh -t ${target} nixos-rebuild ${rebuildArg} $@
fi
2021-02-22 12:31:58 +01:00
'';
2021-02-22 13:21:31 +01:00
mkWake = name:
pkgs.writeScriptBin "${name}-wake" ''
#!${pkgs.runtimeShell}
exec ${pkgs.wol}/bin/wol ${hostRegistry.hosts.${name}.ether}
'';
# TODO: check if the ethernet address is reachable and if not,
# execute wol on a machine in HQ.
2021-02-22 12:31:58 +01:00
in {
2021-02-26 20:22:15 +01:00
inherit (pkgs) bmxd;
glotzbert-nixos-rebuild = mkDeploy { name = "glotzbert"; };
2021-02-22 13:21:31 +01:00
glotzbert-wake = mkWake "glotzbert";
pulsebert-nixos-rebuild = mkDeploy {
name = "pulsebert";
builders = [ "ssh://client@172.22.99.110" ];
};
2021-02-22 13:21:31 +01:00
pulsebert-wake = mkWake "pulsebert";
2021-03-03 16:20:17 +01:00
yggdrasil-nixos-rebuild = mkDeploy {
name = "yggdrasil";
host = "172.20.72.62";
};
freifunk-nixos-rebuild = mkDeploy {
name = "freifunk";
host = "freifunk.core.zentralwerk.dn42";
};
matemat-nixos-rebuild = mkDeploy {
name = "matemat";
};
scrape-nixos-rebuild = mkDeploy {
name = "scrape";
host = hostRegistry.hosts.scrape.ip4;
};
dn42-nixos-rebuild = mkDeploy {
name = "dn42";
};
grafana-nixos-rebuild = mkDeploy {
name = "grafana";
};
hydra-nixos-rebuild = mkDeploy {
name = "hydra";
host = hostRegistry.hosts.hydra.ip4;
};
mucbot-nixos-rebuild = mkDeploy {
name = "mucbot";
host = hostRegistry.hosts.mucbot.ip4;
};
kibana-nixos-rebuild = mkDeploy {
name = "kibana";
host = hostRegistry.hosts.kibana.ip4;
};
2021-02-22 12:31:58 +01:00
});
2020-08-04 17:15:07 +02:00
2021-02-22 12:31:58 +01:00
nixosConfigurations = let
nixosSystem' =
# Our custom NixOS builder
{ extraArgs ? {}, ... }@args:
2021-02-22 12:31:58 +01:00
nixpkgs.lib.nixosSystem (args // {
extraArgs = extraArgs // {
inherit hostRegistry;
};
2021-02-22 12:31:58 +01:00
extraModules = [
self.nixosModules.c3d2
({ pkgs, ... }: {
nix = {
package = pkgs.nixFlakes;
extraOptions = "experimental-features = nix-command flakes";
};
2021-02-26 20:22:15 +01:00
nixpkgs.overlays = [ self.overlay ];
2021-02-22 12:31:58 +01:00
})
];
});
in {
2020-08-04 17:15:07 +02:00
2021-02-26 20:22:15 +01:00
freifunk = nixosSystem' {
2021-03-05 01:16:57 +01:00
modules = [
./hosts/containers/freifunk
({ ... }: {
nixpkgs.overlays = with secrets.overlays; [
freifunk ospf
];
})
];
2021-02-26 20:22:15 +01:00
system = "x86_64-linux";
};
2021-02-22 13:21:31 +01:00
glotzbert = nixosSystem' {
modules = [
./hosts/glotzbert
nixos-hardware.nixosModules.common-cpu-intel
nixos-hardware.nixosModules.common-pc-ssd
2021-03-12 17:06:37 +01:00
secrets.nixosModules.admins
];
2021-02-22 13:21:31 +01:00
system = "x86_64-linux";
};
pulsebert = nixosSystem' {
modules = [ ./hosts/pulsebert ];
2021-02-22 13:21:31 +01:00
system = "aarch64-linux";
};
2020-08-04 17:15:07 +02:00
2021-03-03 16:20:17 +01:00
yggdrasil = nixosSystem' {
modules = [
./hosts/containers/yggdrasil
./lib/lxc-container.nix
./lib/users/emery.nix
({ ... }: {
nixpkgs.overlays = [ secrets.overlays.ospf ];
})
2021-03-03 16:20:17 +01:00
];
system = "x86_64-linux";
};
2021-03-06 01:13:27 +01:00
matemat = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/matemat
2021-03-10 01:54:28 +01:00
yammat.nixosModule
secrets.nixosModules.admins
2021-03-06 02:28:46 +01:00
({ ... }: {
nixpkgs.overlays = [ secrets.overlays.matemat ];
})
2021-03-06 01:13:27 +01:00
];
system = "x86_64-linux";
};
2021-03-06 02:57:35 +01:00
scrape = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/scrape
({ ... }: {
nixpkgs.overlays = [ secrets.overlays.scrape ];
})
];
extraArgs = { inherit scrapers; };
2021-03-06 02:57:35 +01:00
system = "x86_64-linux";
};
2021-03-11 15:59:00 +01:00
dn42 = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/dn42
({ ... }: {
nixpkgs.overlays = [ secrets.overlays.dn42 ];
})
];
system = "x86_64-linux";
};
2021-03-11 16:40:39 +01:00
grafana = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/grafana
];
system = "x86_64-linux";
};
2021-03-12 21:45:12 +01:00
hydra = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/hydra
];
system = "x86_64-linux";
};
2021-03-22 16:22:57 +01:00
mucbot = nixosSystem' {
modules = [
./lib/lxc-container.nix
"${tigger}/module.nix"
{ nixpkgs.overlays = [ secrets.overlays.mucbot ]; }
./hosts/containers/mucbot
];
extraArgs = { inherit tigger; };
system = "x86_64-linux";
};
2021-05-10 00:28:27 +02:00
kibana = nixosSystem' {
modules = [
./lib/lxc-container.nix
./hosts/containers/kibana
];
system = "x86_64-linux";
};
2020-08-04 17:15:07 +02:00
};
2021-02-22 12:31:58 +01:00
nixosModules.c3d2 = import ./lib;
};
}