This repository has been archived on 2024-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
test-installer-configuration/flake.nix

189 lines
5.1 KiB
Nix
Raw Normal View History

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
2024-11-07 17:10:05 +01:00
flake-parts.url = "github:hercules-ci/flake-parts";
git-hooks.url = "github:cachix/git-hooks.nix";
2024-11-07 17:10:05 +01:00
2024-11-11 16:35:26 +01:00
# snf.url = "path:/home/niols/git/fediversity/simple-nixos-fediverse"; #dev
snf.url = "git+https://git.fediversity.eu/fediversity/simple-nixos-fediverse.git";
2024-10-01 13:56:15 +02:00
disko.url = "github:nix-community/disko";
2024-11-07 18:08:29 +01:00
nixops4.url = "github:nixops4/nixops4";
nixops4-nixos.url = "github:nixops4/nixops4/eval";
};
2024-11-08 16:15:39 +01:00
outputs =
inputs@{
self,
flake-parts,
nixpkgs,
snf,
...
}:
2024-11-07 17:10:05 +01:00
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.nixops4-nixos.modules.flake.default
inputs.git-hooks.flakeModule
];
2024-11-08 16:15:39 +01:00
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
2024-11-07 18:08:29 +01:00
];
2024-11-08 16:15:39 +01:00
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
{
formatter = pkgs.nixfmt-rfc-style;
2024-10-01 13:56:15 +02:00
pre-commit.settings.hooks = {
nixfmt-rfc-style.enable = true;
deadnix.enable = true;
};
devShells.default = pkgs.mkShell {
packages = [ inputs'.nixops4.packages.default ];
shellHook = config.pre-commit.installationScript;
};
2024-11-07 17:10:05 +01:00
};
2024-11-11 15:44:04 +01:00
flake.vmIdTo03d =
id:
let
sid = toString id;
in
if id >= 0 && id <= 9 then
"00${sid}"
else if id >= 10 && id <= 99 then
"0${sid}"
else
sid;
flake.allVmIds = # 100 -- 255
let
allVmIdsFrom = x: if x > 255 then [ ] else [ x ] ++ allVmIdsFrom (x + 1);
in
allVmIdsFrom 100;
2024-11-07 17:10:05 +01:00
flake.nixosConfigurations.provisioning =
let
inherit (builtins) map listToAttrs;
2024-11-08 16:15:39 +01:00
makeProvisioningConfiguration =
vmid:
nixpkgs.lib.nixosSystem {
modules = [
{ procolix.vmid = vmid; }
./procolixVm.nix
inputs.disko.nixosModules.default
];
};
2024-11-07 17:10:05 +01:00
in
2024-11-08 16:15:39 +01:00
listToAttrs (
map (vmid: {
2024-11-11 15:44:04 +01:00
name = "fedi${self.vmIdTo03d vmid}";
2024-11-08 16:15:39 +01:00
value = makeProvisioningConfiguration vmid;
}) self.allVmIds
);
2024-11-07 17:10:05 +01:00
flake.isoInstallers.provisioning =
2024-11-08 16:15:39 +01:00
let
inherit (builtins) mapAttrs;
in
2024-11-08 16:21:52 +01:00
mapAttrs (
vmname:
snf.mkInstaller {
inherit nixpkgs;
hostKeys = {
rsa = {
private = ./hostKeys/${vmname}/ssh_host_rsa_key;
public = ./hostKeys/${vmname}/ssh_host_rsa_key.pub;
};
ed25519 = {
private = ./hostKeys/${vmname}/ssh_host_ed25519_key;
public = ./hostKeys/${vmname}/ssh_host_ed25519_key.pub;
};
};
}
) self.nixosConfigurations.provisioning;
2024-11-07 18:08:29 +01:00
2024-11-08 16:15:39 +01:00
nixops4Deployments.default =
{ providers, ... }:
2024-11-07 18:08:29 +01:00
let
2024-11-08 16:21:52 +01:00
inherit (builtins) readFile;
2024-11-07 18:08:29 +01:00
makeProcolixVmResource = vmid: vmconfig: {
type = providers.local.exec;
2024-11-08 16:15:39 +01:00
imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos ];
2024-11-07 18:08:29 +01:00
ssh.opts = "";
2024-11-11 15:44:04 +01:00
ssh.host = "95.215.187.${self.vmIdTo03d vmid}";
ssh.hostPublicKey = readFile ./hostKeys/fedi${self.vmIdTo03d vmid}/ssh_host_ed25519_key.pub;
2024-11-07 18:08:29 +01:00
nixpkgs = inputs.nixpkgs;
2024-11-08 16:15:39 +01:00
nixos.module =
{ pkgs, modulesPath, ... }:
{
imports = [
vmconfig
{ procolix.vmid = vmid; }
./procolixVm.nix
inputs.snf.nixosModules.fediversity
inputs.disko.nixosModules.default
];
};
2024-11-07 18:08:29 +01:00
};
in
2024-11-08 16:15:39 +01:00
{
providers.local = inputs.nixops4-nixos.modules.nixops4Provider.local;
2024-11-07 18:08:29 +01:00
2024-11-08 16:15:39 +01:00
resources = {
2024-11-11 16:02:32 +01:00
fedi100 = makeProcolixVmResource 100 { };
fedi101 = makeProcolixVmResource 101 {
2024-11-08 16:15:39 +01:00
fediversity = {
enable = true;
2024-11-11 16:02:32 +01:00
domain = "fedi101.niols.fr";
2024-11-08 16:15:39 +01:00
pixelfed.enable = true;
2024-11-07 18:08:29 +01:00
};
};
2024-11-11 16:02:32 +01:00
2024-11-11 16:32:15 +01:00
fedi102 = makeProcolixVmResource 102 {
fediversity = {
enable = true;
domain = "fedi102.niols.fr";
mastodon.enable = true;
temp.cores = 1; # FIXME: should come from NixOps4 eventually
};
};
2024-11-11 16:02:32 +01:00
2024-11-11 17:17:56 +01:00
fedi103 = makeProcolixVmResource 103 (
{ pkgs, ... }:
{
fediversity = {
enable = true;
domain = "fedi103.niols.fr";
peertube.enable = true;
temp.peertubeSecretsFile = pkgs.writeText "secret" ''
574e093907d1157ac0f8e760a6deb1035402003af5763135bae9cbd6abe32b24
'';
};
}
);
2024-11-07 18:08:29 +01:00
};
2024-11-08 16:15:39 +01:00
};
};
}