2023-11-05 17:43:32 +00:00
|
|
|
{
|
|
|
|
description = "NixOS definitions for our physical servers";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
|
2023-11-15 10:41:45 +00:00
|
|
|
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
2023-11-11 23:04:37 +00:00
|
|
|
deploy-rs.url = "github:serokell/deploy-rs";
|
2023-12-16 14:45:17 +00:00
|
|
|
kubenix = {
|
|
|
|
url = "github:hall/kubenix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-11-29 09:02:50 +00:00
|
|
|
|
2023-11-14 22:53:04 +00:00
|
|
|
disko = {
|
|
|
|
url = "github:nix-community/disko";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-11-29 09:02:50 +00:00
|
|
|
|
2023-11-14 22:53:04 +00:00
|
|
|
agenix = {
|
|
|
|
url = "github:ryantm/agenix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-11-05 17:43:32 +00:00
|
|
|
};
|
|
|
|
|
2023-11-29 09:02:50 +00:00
|
|
|
outputs =
|
2023-12-16 14:45:17 +00:00
|
|
|
{ self, nixpkgs, deploy-rs, disko, agenix, nixpkgs-unstable, kubenix, ... }:
|
2023-11-15 10:41:45 +00:00
|
|
|
let
|
|
|
|
system = "x86_64-linux";
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
|
2023-11-15 12:06:59 +00:00
|
|
|
machines = import ./machines;
|
2023-12-14 20:42:58 +00:00
|
|
|
# TODO: Maybe use mergeAttrLists
|
2023-11-15 12:06:59 +00:00
|
|
|
mkNixosSystems = systemDef:
|
2023-12-15 14:11:14 +00:00
|
|
|
nixpkgs.lib.foldlAttrs
|
|
|
|
(acc: name: machine:
|
|
|
|
acc // {
|
|
|
|
"${name}" = nixpkgs.lib.nixosSystem (systemDef machine);
|
|
|
|
})
|
|
|
|
{ }
|
|
|
|
machines;
|
2023-11-15 12:06:59 +00:00
|
|
|
mkDeployNodes = nodeDef:
|
|
|
|
nixpkgs.lib.foldlAttrs
|
2023-12-15 14:11:14 +00:00
|
|
|
(acc: name: machine: acc // { "${name}" = nodeDef machine; })
|
|
|
|
{ }
|
|
|
|
machines;
|
|
|
|
in
|
|
|
|
{
|
2023-11-15 10:41:45 +00:00
|
|
|
devShells.${system}.default = pkgs.mkShell {
|
2023-11-15 11:55:57 +00:00
|
|
|
packages = [
|
|
|
|
pkgs.libsecret
|
2023-11-15 12:37:13 +00:00
|
|
|
# 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
|
2023-11-15 11:55:57 +00:00
|
|
|
pkgs-unstable.deploy-rs
|
2023-11-25 12:41:49 +00:00
|
|
|
pkgs.openssl
|
|
|
|
pkgs.postgresql_15
|
2023-11-25 20:00:21 +00:00
|
|
|
pkgs-unstable.opentofu
|
|
|
|
pkgs.cdrtools
|
2023-12-14 20:42:58 +00:00
|
|
|
pkgs.kubectl
|
2023-11-15 11:55:57 +00:00
|
|
|
];
|
2023-11-15 10:41:45 +00:00
|
|
|
};
|
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
|
|
|
|
2023-11-15 12:06:59 +00:00
|
|
|
nixosConfigurations = mkNixosSystems (machine: {
|
|
|
|
inherit system;
|
2023-12-16 14:45:17 +00:00
|
|
|
specialArgs = { inherit kubenix; };
|
2023-11-15 12:06:59 +00:00
|
|
|
modules = [
|
2023-12-16 22:47:18 +00:00
|
|
|
machine.nixosModule
|
2023-11-15 12:06:59 +00:00
|
|
|
disko.nixosModules.disko
|
|
|
|
agenix.nixosModules.default
|
|
|
|
./configuration.nix
|
2023-11-22 17:54:05 +00:00
|
|
|
{ networking.hostName = machine.name; }
|
2023-11-15 12:06:59 +00:00
|
|
|
];
|
|
|
|
});
|
2023-11-11 23:04:37 +00:00
|
|
|
|
|
|
|
deploy = {
|
|
|
|
sshUser = "root";
|
|
|
|
user = "root";
|
|
|
|
|
2023-11-15 12:06:59 +00:00
|
|
|
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
|
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
|
|
|
};
|
|
|
|
}
|