sbc-deploys/flake.nix

244 lines
6.7 KiB
Nix
Raw Normal View History

2023-01-25 01:58:10 +00:00
{
description = "A very basic flake";
inputs = {
2023-01-26 03:26:30 +00:00
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-01-25 01:58:10 +00:00
image-builder.url = "git+https://git.asonix.dog/asonix/nixos-aarch64-images";
2023-01-26 03:26:30 +00:00
nixpkgs.url = "github:nixos/nixpkgs/master";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-01-25 01:58:10 +00:00
};
2023-01-26 03:26:30 +00:00
outputs = { self, deploy-rs, image-builder, nixpkgs, sops-nix }:
let
sharedModule = import ./modules/shared;
btrbkModule = import ./modules/btrbk;
dockerModule = import ./modules/docker;
subvolumesModule = import ./modules/subvolumes;
k3sModule = import ./modules/k3s;
2023-01-26 03:26:30 +00:00
makeConfig = { hostname, extraModules ? [ ] }:
with image-builder.packages.aarch64-linux.modules;
nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
sops-nix.nixosModules.sops
sharedModule
userModule
{
networking.hostName = hostname;
}
] ++ extraModules;
};
2023-01-26 06:57:59 +00:00
makeK3sConfig = { hostname, serverIp ? null }:
with image-builder.packages.aarch64-linux.modules;
makeConfig {
inherit hostname;
extraModules = [
soquartz-blade
(if serverIp == null
then
k3sModule.server
else
k3sModule.agent {
inherit serverIp;
})
{
services.lvm.enable = true;
fileSystems = {
"/var/lib/rancher" = {
device = "/dev/nvme0n1p1";
fsType = "ext4";
options = [ "defaults" "rw" ];
};
};
}
];
};
makeNextcloudConfig = { hostname, primaryIp ? null }:
with image-builder.packages.aarch64-linux.modules;
let
device = "/dev/mapper/cryptdrive1";
mountDir = "/btrfs/hdd";
subvolumes = [
"@nc-config"
"@nc-data"
"@postgres"
"@redis"
"@gitea"
"@gitea-conf"
"@pihole"
"@papermc"
"@docker-cfg"
"@garage"
"@garage-config"
];
in
makeConfig {
inherit hostname;
2023-01-26 06:57:59 +00:00
extraModules = [
rockPro64v2
dockerModule
(btrbkModule {
inherit mountDir primaryIp subvolumes;
})
(if primaryIp == null then
(subvolumesModule {
inherit device subvolumes;
}) else { })
({ config, ... }: {
sops.secrets.nextcloudKeyFile = {
format = "binary";
sopsFile = ./secrets/nextcloudKeyFile.bin;
};
environment.etc.crypttab = {
enable = true;
text = ''
cryptdrive1 /dev/sda1 ${config.sops.secrets.nextcloudKeyFile.path} luks
cryptdrive2 /dev/sdb1 ${config.sops.secrets.nextcloudKeyFile.path} luks
cryptdrive3 /dev/sdc1 ${config.sops.secrets.nextcloudKeyFile.path} luks
'';
};
fileSystems."${mountDir}" = {
inherit device;
fsType = "btrfs";
options = [ "defaults" "compress=zstd" "rw" ];
};
})
];
};
makePostgresConfig = { hostname, keyFile, primaryIp ? null }:
with image-builder.packages.aarch64-linux.modules;
let
device = "/dev/mapper/cryptdrive1";
mountDir = "/btrfs/ssd";
subvolumes = [
"@postgres"
"@postgres-cfg"
];
in
makeConfig {
inherit hostname;
extraModules = [
rock64
dockerModule
(btrbkModule {
inherit mountDir primaryIp subvolumes;
})
(if primaryIp == null then
(subvolumesModule {
inherit device subvolumes;
}) else { })
({ config, ... }:
let
keyFilePath = config.sops.secrets."${keyFile}".path;
in
{
sops.secrets.${keyFile} = {
format = "binary";
sopsFile = ./secrets/${keyFile}.bin;
};
environment.etc.crypttab = {
enable = true;
text = ''
cryptdrive1 /dev/sda1 ${keyFilePath} luks
'';
};
fileSystems."${mountDir}" = {
inherit device;
fsType = "btrfs";
options = [ "defaults" "compress=zstd" "rw" ];
};
})
];
};
2023-01-25 04:55:24 +00:00
deployer = { hostname, configuration }: {
hostname = hostname;
2023-01-25 02:49:00 +00:00
profiles.system = {
2023-01-26 03:26:30 +00:00
sshUser = "asonix";
2023-01-25 02:49:00 +00:00
user = "root";
2023-01-26 03:26:30 +00:00
magicRollback = false;
2023-01-25 02:49:00 +00:00
sshOpts = [
"-i"
2023-01-26 03:26:30 +00:00
"/home/asonix/.ssh/kube-rsa"
"-t"
2023-01-25 02:49:00 +00:00
];
2023-01-25 04:55:24 +00:00
path = deploy-rs.lib.aarch64-linux.activate.nixos configuration;
2023-01-25 02:49:00 +00:00
};
2023-01-25 01:58:10 +00:00
};
2023-01-25 04:55:24 +00:00
in
{
nixosConfigurations = {
2023-01-26 06:57:59 +00:00
nextcloud1 = makeNextcloudConfig {
2023-01-25 05:08:04 +00:00
hostname = "nextcloud1";
# primaryIp = "192.168.20.28";
2023-01-25 04:55:24 +00:00
};
2023-01-26 06:57:59 +00:00
nextcloud2 = makeNextcloudConfig {
2023-01-25 05:08:04 +00:00
hostname = "nextcloud2";
primaryIp = "192.168.20.21";
2023-01-25 04:55:24 +00:00
};
redtail1 = makePostgresConfig {
2023-01-25 05:08:04 +00:00
hostname = "redtail1";
keyFile = "redtailKeyFile";
primaryIp = "192.168.20.24";
2023-01-25 05:08:04 +00:00
};
redtail2 = makePostgresConfig {
2023-01-25 05:08:04 +00:00
hostname = "redtail2";
keyFile = "redtailKeyFile";
# primaryIp = "192.168.20.23";
2023-01-25 05:08:04 +00:00
};
whitestorm1 = makePostgresConfig {
2023-01-25 05:08:04 +00:00
hostname = "whitestorm1";
keyFile = "whitestormKeyFile";
# primaryIp = "192.168.20.11";
2023-01-25 05:08:04 +00:00
};
2023-01-26 18:22:12 +00:00
whitestorm2 = makePostgresConfig {
2023-01-25 05:08:04 +00:00
hostname = "whitestorm2";
keyFile = "whitestormKeyFile";
primaryIp = "192.168.20.26";
2023-01-25 05:08:04 +00:00
};
k3s1 = makeK3sConfig {
hostname = "k3s1";
};
k3s2 = makeK3sConfig {
hostname = "k3s2";
serverIp = "192.168.20.120";
};
2023-01-25 05:08:04 +00:00
};
2023-01-25 04:55:24 +00:00
deploy.nodes.nextcloud2 = deployer {
hostname = "192.168.20.28";
configuration = self.nixosConfigurations.nextcloud2;
};
deploy.nodes.k3s1 = deployer {
hostname = "192.168.20.120";
configuration = self.nixosConfigurations.k3s1;
};
2023-01-25 01:58:10 +00:00
};
}