86 lines
2.5 KiB
Nix
86 lines
2.5 KiB
Nix
{
|
|
description = "C3D2 NixOS configurations";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/release-20.09";
|
|
secrets = {
|
|
url = "git+ssh://git@gitea.c3d2.de:2222/c3d2-admins/secrets.git";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, secrets }:
|
|
let
|
|
forAllSystems = f:
|
|
nixpkgs.lib.genAttrs [ "aarch64-linux" "x86_64-linux" ]
|
|
(system: f system);
|
|
in {
|
|
|
|
inherit (nixpkgs) legacyPackages;
|
|
|
|
packages = forAllSystems (system:
|
|
let
|
|
hostRegistry = import ./host-registry.nix;
|
|
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} \
|
|
nix shell \
|
|
${self}#nixosConfigurations.${name}.config.system.build.toplevel \
|
|
--command switch-to-configuration $@
|
|
'';
|
|
mkWake = name:
|
|
pkgs.writeScriptBin "${name}-wake" ''
|
|
#!${pkgs.runtimeShell}
|
|
exec ${pkgs.wol}/bin/wol ${hostRegistry.hosts.${name}.ether}
|
|
'';
|
|
in {
|
|
glotzbert-nixos-rebuild = mkDeploy "glotzbert" "glotzbert.hq.c3d2.de";
|
|
glotzbert-wake = mkWake "glotzbert";
|
|
|
|
pulsebert-nixos-rebuild = mkDeploy "pulsebert" "pulsebert.hq.c3d2.de";
|
|
pulsebert-wake = mkWake "pulsebert";
|
|
});
|
|
|
|
nixosConfigurations = let
|
|
nixosSystem' =
|
|
# Our custom NixOS builder
|
|
{ ... }@args:
|
|
nixpkgs.lib.nixosSystem (args // {
|
|
extraModules = [
|
|
self.nixosModules.c3d2
|
|
({ pkgs, ... }: {
|
|
nix = {
|
|
package = pkgs.nixFlakes;
|
|
extraOptions = "experimental-features = nix-command flakes";
|
|
};
|
|
})
|
|
];
|
|
});
|
|
in {
|
|
|
|
glotzbert = nixosSystem' {
|
|
modules = [ ./hosts/glotzbert ];
|
|
system = "x86_64-linux";
|
|
};
|
|
|
|
pulsebert = nixosSystem' {
|
|
modules = [ ./hosts/pulsebert ];
|
|
system = "aarch64-linux";
|
|
};
|
|
|
|
};
|
|
|
|
nixosModules.c3d2 = import ./lib;
|
|
|
|
};
|
|
}
|