nixos-servers/flake.nix

77 lines
2.3 KiB
Nix
Raw Normal View History

2023-11-05 17:43:32 +00:00
{
description = "NixOS definitions for our physical servers";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2023-11-11 23:04:37 +00:00
deploy-rs.url = "github:serokell/deploy-rs";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-11-05 17:43:32 +00:00
};
outputs = { self, nixpkgs, deploy-rs, disko, agenix, nixpkgs-unstable, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
machines = import ./machines;
mkNixosSystems = systemDef:
nixpkgs.lib.foldlAttrs (acc: name: machine:
acc // {
"${name}" = nixpkgs.lib.nixosSystem (systemDef machine);
}) { } machines;
mkDeployNodes = nodeDef:
nixpkgs.lib.foldlAttrs
(acc: name: machine: acc // { "${name}" = nodeDef machine; }) { }
machines;
2023-11-11 23:04:37 +00:00
in {
devShells.${system}.default = pkgs.mkShell {
packages = [
pkgs.libsecret
# TODO: using nixos-anywhere from nixos-unstable produces buffer overflow.
# Related to this issue: https://github.com/nix-community/nixos-anywhere/issues/242
# Should wait until this is merged in nixos-unstable.
# pkgs-unstable.nixos-anywhere
pkgs-unstable.deploy-rs
];
};
2023-11-11 23:04:37 +00:00
2023-11-15 12:10:27 +00:00
formatter.${system} = pkgs.nixfmt;
2023-11-11 23:04:37 +00:00
nixosConfigurations = mkNixosSystems (machine: {
inherit system;
modules = [
2023-11-22 17:28:55 +00:00
machine.specificConfig
disko.nixosModules.disko
agenix.nixosModules.default
./configuration.nix
2023-11-22 17:28:55 +00:00
{
networking.hostName = machine.name;
}
];
});
2023-11-11 23:04:37 +00:00
deploy = {
sshUser = "root";
user = "root";
nodes = mkDeployNodes (machine: {
hostname = machine.hostname;
profiles.hypervisor = {
path = deploy-rs.lib.${system}.activate.nixos
self.nixosConfigurations.${machine.name};
};
});
2023-11-11 23:04:37 +00:00
};
checks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
2023-11-05 17:43:32 +00:00
};
}