2023-11-05 17:43:32 +00:00
|
|
|
{
|
|
|
|
description = "NixOS definitions for our physical servers";
|
|
|
|
|
|
|
|
inputs = {
|
2023-12-17 15:22:22 +00:00
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
|
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";
|
2024-02-27 19:14:53 +00:00
|
|
|
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
|
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";
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
2023-11-29 09:02:50 +00:00
|
|
|
outputs =
|
2024-02-27 19:14:53 +00:00
|
|
|
{ self, nixpkgs, deploy-rs, disko, agenix, nixpkgs-unstable, dns, microvm, nixos-hardware, ... }:
|
2023-11-15 10:41:45 +00:00
|
|
|
let
|
2024-02-28 20:39:23 +00:00
|
|
|
controllerArch = "x86_64-linux";
|
|
|
|
pkgs = nixpkgs.legacyPackages.${controllerArch};
|
2024-01-23 20:36:29 +00:00
|
|
|
lib = pkgs.lib;
|
2024-02-28 20:39:23 +00:00
|
|
|
pkgs-unstable = nixpkgs-unstable.legacyPackages.${controllerArch};
|
2024-02-28 23:28:38 +00:00
|
|
|
machines = (lib.modules.evalModules { modules = [ (import ./nixos/machines) ]; }).config.machines;
|
2024-01-28 10:48:13 +00:00
|
|
|
physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines;
|
2023-11-15 12:06:59 +00:00
|
|
|
mkNixosSystems = systemDef:
|
2024-01-28 12:57:36 +00:00
|
|
|
builtins.mapAttrs
|
|
|
|
(name: machine:
|
|
|
|
nixpkgs.lib.nixosSystem (systemDef name machine)
|
|
|
|
)
|
2024-01-28 10:48:13 +00:00
|
|
|
physicalMachines;
|
2023-11-15 12:06:59 +00:00
|
|
|
mkDeployNodes = nodeDef:
|
2024-01-28 12:57:36 +00:00
|
|
|
builtins.mapAttrs
|
|
|
|
(name: machine: nodeDef name machine)
|
2024-01-28 10:48:13 +00:00
|
|
|
physicalMachines;
|
2023-12-15 14:11:14 +00:00
|
|
|
in
|
|
|
|
{
|
2024-02-28 20:39:23 +00:00
|
|
|
devShells.${controllerArch}.default = pkgs.mkShell {
|
2023-12-17 15:22:22 +00:00
|
|
|
packages = with 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-12-17 15:22:22 +00:00
|
|
|
openssl
|
|
|
|
postgresql_15
|
|
|
|
opentofu
|
|
|
|
cdrtools
|
|
|
|
kubectl
|
|
|
|
ansible
|
2023-11-15 11:55:57 +00:00
|
|
|
];
|
2023-11-15 10:41:45 +00:00
|
|
|
};
|
2023-11-11 23:04:37 +00:00
|
|
|
|
2024-02-28 20:39:23 +00:00
|
|
|
formatter.${controllerArch} = pkgs.nixfmt;
|
2023-11-11 23:04:37 +00:00
|
|
|
|
2024-01-28 11:55:58 +00:00
|
|
|
nixosConfigurations = mkNixosSystems (name: machine: {
|
2024-02-26 22:08:12 +00:00
|
|
|
system = machine.arch;
|
|
|
|
|
2024-02-27 19:14:53 +00:00
|
|
|
specialArgs = { inherit machines machine dns microvm disko agenix nixos-hardware; };
|
2024-01-28 13:08:28 +00:00
|
|
|
modules = [
|
|
|
|
./nixos
|
|
|
|
{ networking.hostName = name; }
|
|
|
|
];
|
2023-11-15 12:06:59 +00:00
|
|
|
});
|
2023-11-11 23:04:37 +00:00
|
|
|
|
|
|
|
deploy = {
|
|
|
|
sshUser = "root";
|
|
|
|
user = "root";
|
|
|
|
|
2024-01-28 11:55:58 +00:00
|
|
|
nodes = mkDeployNodes (name: machine: {
|
|
|
|
hostname = self.nixosConfigurations.${name}.config.networking.fqdn;
|
2024-01-16 20:47:41 +00:00
|
|
|
profiles.system = {
|
2024-02-28 20:39:23 +00:00
|
|
|
remoteBuild = machine.arch != controllerArch;
|
2024-02-27 22:28:52 +00:00
|
|
|
path = deploy-rs.lib."${machine.arch}".activate.nixos
|
2024-01-28 11:55:58 +00:00
|
|
|
self.nixosConfigurations.${name};
|
2023-11-15 12:06:59 +00:00
|
|
|
};
|
|
|
|
});
|
2023-11-11 23:04:37 +00:00
|
|
|
};
|
|
|
|
|
2024-02-28 20:39:23 +00:00
|
|
|
# Deploy-rs' flake checks seem broken for architectures different from the deployment machine.
|
|
|
|
# We skip these here.
|
2023-11-11 23:04:37 +00:00
|
|
|
checks = builtins.mapAttrs
|
2024-02-28 20:39:23 +00:00
|
|
|
(system: deployLib:
|
|
|
|
deployLib.deployChecks (self.deploy // {
|
|
|
|
nodes = (lib.attrsets.filterAttrs
|
|
|
|
(name: node:
|
|
|
|
machines.${name}.arch == controllerArch
|
|
|
|
)
|
|
|
|
self.deploy.nodes);
|
|
|
|
})
|
|
|
|
)
|
2023-12-15 14:11:14 +00:00
|
|
|
deploy-rs.lib;
|
2023-11-05 17:43:32 +00:00
|
|
|
};
|
|
|
|
}
|