nix-config/flake.nix

74 lines
2.2 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";
secrets = {
url = "git+ssh://git@gitea.c3d2.de:2222/c3d2-admins/secrets.git";
flake = false;
};
2020-06-11 07:50:42 +02:00
};
2020-04-15 19:00:56 +02:00
2021-02-22 12:31:58 +01:00
outputs = { self, nixpkgs, secrets }:
let
forAllSystems = f:
nixpkgs.lib.genAttrs [ "aarch64-linux" "x86_64-linux" ]
(system: f system);
in {
2021-02-22 12:31:58 +01:00
inherit (nixpkgs) legacyPackages;
2021-02-22 12:31:58 +01:00
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 $@
'';
in {
glotzbert-nixos-rebuild = mkDeploy "glotzbert" "glotzbert.hq.c3d2.de";
glotzbert-wake = pkgs.writeScriptBin "glotzbert-wake" ''
#!${pkgs.runtimeShell}
exec ${pkgs.wol}/bin/wol ${hostRegistry.hosts.glotzbert.ether}
'';
});
2020-08-04 17:15:07 +02:00
2021-02-22 12:31:58 +01:00
nixosConfigurations = let
nixosSystem' =
# Our custom NixOS builder
{ system ? "x86_64-linux", ... }@args:
nixpkgs.lib.nixosSystem (args // {
inherit system;
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-22 12:31:58 +01:00
glotzbert = nixosSystem' { modules = [ ./hosts/glotzbert ]; };
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
};
}