nix-config/flake.nix

99 lines
3.0 KiB
Nix
Raw Normal View History

{
description = "C3D2 NixOS configurations";
2020-06-11 07:50:42 +02:00
inputs = {
2020-10-26 16:06:42 +01:00
nixpkgs.url = "github:nixos/nixpkgs/release-20.09";
2021-02-24 11:52:19 +01:00
secrets.url = "git+ssh://git@gitea.c3d2.de:2222/c3d2-admins/secrets.git";
2020-06-11 07:50:42 +02:00
};
2020-04-15 19:00:56 +02:00
outputs = { self, nixpkgs, secrets, nixos-hardware }:
2021-02-22 12:31:58 +01:00
let
forAllSystems = f:
nixpkgs.lib.genAttrs [ "aarch64-linux" "x86_64-linux" ]
(system: f system);
2021-02-24 11:52:19 +01:00
hostRegistry = import ./host-registry.nix;
2021-02-22 12:31:58 +01:00
in {
2021-02-22 12:31:58 +01:00
inherit (nixpkgs) legacyPackages;
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:
let target = "root@${host}";
in pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell}
set -ev
nix-copy-closure --to ${target} ${self}
exec ssh -t ${target} nixos-rebuild --flake ${self}#${name} $@
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-24 11:52:19 +01:00
dhcp-nixos-rebuild = mkDeploy "dhcp" hostRegistry.hosts.dhcp.ip4;
2021-02-22 12:31:58 +01:00
glotzbert-nixos-rebuild = mkDeploy "glotzbert" "glotzbert.hq.c3d2.de";
2021-02-22 13:21:31 +01:00
glotzbert-wake = mkWake "glotzbert";
pulsebert-nixos-rebuild = mkDeploy "pulsebert" "pulsebert.hq.c3d2.de";
pulsebert-wake = mkWake "pulsebert";
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
2021-02-22 13:21:31 +01:00
{ ... }@args:
2021-02-22 12:31:58 +01:00
nixpkgs.lib.nixosSystem (args // {
2021-02-24 11:52:19 +01:00
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";
};
})
];
});
in {
2020-08-04 17:15:07 +02:00
2021-02-24 11:52:19 +01:00
dhcp = nixosSystem' {
modules = [
./hosts/containers/dhcp
secrets.nixosModules.admins
secrets.nixosModules.dhcp
];
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-02-22 13:21:31 +01:00
system = "x86_64-linux";
};
pulsebert = nixosSystem' {
modules = [ ./hosts/pulsebert secrets.nixosModules.dhcp ];
2021-02-22 13:21:31 +01:00
system = "aarch64-linux";
};
2020-08-04 17:15:07 +02:00
};
2021-02-22 12:31:58 +01:00
nixosModules.c3d2 = import ./lib;
2021-02-22 12:31:58 +01:00
};
}