Fediversity/infra/flake-part.nix

73 lines
1.6 KiB
Nix
Raw Normal View History

2025-01-30 09:57:56 +01:00
{
self,
inputs,
lib,
...
}:
2025-01-30 09:53:45 +01:00
let
inherit (lib) attrValues mapAttrs;
2025-01-30 09:57:56 +01:00
inherit (lib.attrsets) genAttrs;
2025-01-30 09:53:45 +01:00
makeResource =
vmid:
{ providers, ... }:
let
2025-01-31 14:03:37 +01:00
vmConfig = import (./. + "/${vmid}");
2025-01-30 09:53:45 +01:00
in
{
type = providers.local.exec;
imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos ];
2025-01-31 14:03:37 +01:00
2025-01-30 09:53:45 +01:00
ssh = {
2025-01-31 14:03:37 +01:00
host = vmConfig.procolix.vm.ip4;
2025-01-30 09:53:45 +01:00
opts = "";
hostPublicKey = self.keys.systems.${vmid};
};
2025-01-31 14:03:37 +01:00
2025-01-30 09:53:45 +01:00
nixpkgs = inputs.nixpkgs;
2025-01-31 14:03:37 +01:00
2025-01-30 09:53:45 +01:00
nixos.module = {
imports = [
2025-01-31 14:03:37 +01:00
## NOTE: We import an attrset as a NixOS module, for convenience, so
## as to be able to use it in NixOps4 and to grab information from it
## (eg. the IP) without evaluating the whole configuration first.
vmConfig
2025-01-30 09:53:45 +01:00
./common
self.nixosModules.ageSecrets
];
2025-01-31 14:03:37 +01:00
## Necessary to filter Age secrets.
fediversity.hostPublicKey = self.keys.systems.${vmid};
## FIXME: Remove direct root authentication once the NixOps4 NixOS
## provider supports users with password-less sudo.
users.users.root.openssh.authorizedKeys.keys = attrValues self.keys.contributors;
2025-01-30 09:53:45 +01:00
};
};
2025-01-30 09:57:56 +01:00
makeDeployments = mapAttrs (
_: vmids:
2024-12-16 13:06:35 +01:00
{ providers, ... }:
{
providers.local = inputs.nixops4-nixos.modules.nixops4Provider.local;
2025-01-30 09:57:56 +01:00
resources = genAttrs vmids (vmid: makeResource vmid { inherit providers; });
}
);
2024-12-16 13:06:35 +01:00
2025-01-30 09:57:56 +01:00
in
{
nixops4Deployments = makeDeployments {
git = [
"vm02116"
"fedi300"
];
web = [ "vm02187" ];
other = [
"vm02179"
"vm02186"
];
};
}