forked from Fediversity/Fediversity
Start building a procolixVm
resource module
This commit is contained in:
parent
aed74dc599
commit
4f761bfc1f
2 changed files with 64 additions and 34 deletions
|
@ -6,53 +6,29 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) attrValues mapAttrs;
|
inherit (lib) mapAttrs;
|
||||||
inherit (lib.attrsets) genAttrs;
|
inherit (lib.attrsets) genAttrs;
|
||||||
|
|
||||||
makeResource =
|
makeResource =
|
||||||
vmid:
|
vmName:
|
||||||
{ providers, ... }:
|
{ providers, ... }:
|
||||||
let
|
|
||||||
vmConfig = import (./. + "/${vmid}");
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
type = providers.local.exec;
|
_module.args = { inherit self inputs providers; };
|
||||||
imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos ];
|
|
||||||
|
|
||||||
ssh = {
|
imports = [
|
||||||
host = vmConfig.procolix.vm.ip4;
|
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||||
opts = "";
|
./procolixResource.nix
|
||||||
hostPublicKey = self.keys.systems.${vmid};
|
];
|
||||||
};
|
|
||||||
|
|
||||||
nixpkgs = inputs.nixpkgs;
|
procolixVm.name = vmName;
|
||||||
|
|
||||||
nixos.module = {
|
|
||||||
imports = [
|
|
||||||
## 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
|
|
||||||
|
|
||||||
./common
|
|
||||||
self.nixosModules.ageSecrets
|
|
||||||
];
|
|
||||||
|
|
||||||
## 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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
makeDeployments = mapAttrs (
|
makeDeployments = mapAttrs (
|
||||||
_: vmids:
|
_: vmNames:
|
||||||
{ providers, ... }:
|
{ providers, ... }:
|
||||||
{
|
{
|
||||||
providers.local = inputs.nixops4.modules.nixops4Provider.local;
|
providers.local = inputs.nixops4.modules.nixops4Provider.local;
|
||||||
resources = genAttrs vmids (vmid: makeResource vmid { inherit providers; });
|
resources = genAttrs vmNames (vmName: makeResource vmName { inherit providers; });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
54
infra/procolixResource.nix
Normal file
54
infra/procolixResource.nix
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
inputs,
|
||||||
|
providers,
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib) attrValues mkOption;
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
procolixVm.name = mkOption { };
|
||||||
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let
|
||||||
|
vmConfig = import (./. + "/${config.procolixVm.name}");
|
||||||
|
in
|
||||||
|
{
|
||||||
|
type = providers.local.exec;
|
||||||
|
|
||||||
|
ssh = {
|
||||||
|
host = vmConfig.procolix.vm.ip4;
|
||||||
|
opts = "";
|
||||||
|
hostPublicKey = self.keys.systems.${config.procolixVm.name};
|
||||||
|
};
|
||||||
|
|
||||||
|
nixpkgs = inputs.nixpkgs;
|
||||||
|
|
||||||
|
nixos.module = {
|
||||||
|
imports = [
|
||||||
|
## 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
|
||||||
|
|
||||||
|
./common
|
||||||
|
|
||||||
|
self.nixosModules.ageSecrets
|
||||||
|
];
|
||||||
|
|
||||||
|
## Necessary to filter Age secrets.
|
||||||
|
fediversity.hostPublicKey = self.keys.systems.${config.procolixVm.name};
|
||||||
|
|
||||||
|
## 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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue