nixos-servers/flake.nix

103 lines
2.9 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.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2023-11-11 23:04:37 +00:00
deploy-rs.url = "github:serokell/deploy-rs";
kubenix = {
url = "github:hall/kubenix";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-01-07 19:24:12 +00:00
dns = {
url = "github:kirelagin/dns.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-01-17 20:28:15 +00:00
microvm = {
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-11-05 17:43:32 +00:00
};
outputs =
2024-01-17 20:28:15 +00:00
{ self, nixpkgs, deploy-rs, disko, agenix, kubenix, nixpkgs-unstable, dns, microvm, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
2024-01-23 20:36:29 +00:00
lib = pkgs.lib;
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
machines = import ./nixos/machines;
2024-01-28 10:48:13 +00:00
physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines;
# TODO: Maybe use mergeAttrLists
mkNixosSystems = systemDef:
2023-12-15 14:11:14 +00:00
nixpkgs.lib.foldlAttrs
(acc: name: machine:
acc // {
"${name}" = nixpkgs.lib.nixosSystem (systemDef machine);
})
{ }
2024-01-28 10:48:13 +00:00
physicalMachines;
mkDeployNodes = nodeDef:
nixpkgs.lib.foldlAttrs
2023-12-15 14:11:14 +00:00
(acc: name: machine: acc // { "${name}" = nodeDef machine; })
{ }
2024-01-28 10:48:13 +00:00
physicalMachines;
2023-12-15 14:11:14 +00:00
in
{
devShells.${system}.default = pkgs.mkShell {
packages = with 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
openssl
postgresql_15
opentofu
cdrtools
kubectl
ansible
];
};
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;
2024-01-28 10:48:13 +00:00
specialArgs = { inherit machines machine kubenix dns microvm disko agenix; };
modules = [ ./nixos ];
});
2023-11-11 23:04:37 +00:00
deploy = {
sshUser = "root";
user = "root";
nodes = mkDeployNodes (machine: {
2024-01-28 10:48:13 +00:00
# TODO: simply get this from nixos configuration?
hostname = "${machine.hostName}.${machine.domain}";
2024-01-16 20:47:41 +00:00
profiles.system = {
path = deploy-rs.lib.${system}.activate.nixos
2024-01-28 10:48:13 +00:00
self.nixosConfigurations.${machine.hostName};
};
});
2023-11-11 23:04:37 +00:00
};
checks = builtins.mapAttrs
2023-12-15 14:11:14 +00:00
(system: deployLib: deployLib.deployChecks self.deploy)
deploy-rs.lib;
2023-11-05 17:43:32 +00:00
};
}