sbc-deploys/flake.nix

236 lines
7.1 KiB
Nix
Raw Normal View History

2023-01-25 01:58:10 +00:00
{
description = "A very basic flake";
inputs = {
deploy-rs.url = "github:serokell/deploy-rs";
nixpkgs.url = "github:nixos/nixpkgs/master";
image-builder.url = "git+https://git.asonix.dog/asonix/nixos-aarch64-images";
};
2023-01-25 02:49:00 +00:00
outputs = { self, deploy-rs, image-builder, nixpkgs }:
let
pkgs = import nixpkgs {
system = "aarch64-linux";
};
btrbkPrimary = { subvolumes ? [ ] }: {
snapshot_dir = "@snapshots";
subvolume = builtins.foldl'
(acc: subvol: acc // {
${subvol} = { };
})
{ }
subvolumes;
};
btrbkSecondary = { target-dir, subvolumes ? [ ] }: {
target = "send-receive ${target-dir}";
subvolume = builtins.foldl'
(acc: subvol: acc // {
${subvol} = {
snapshot_dir = "@snapshots";
snapshot_preserve_min = "all";
snapshot_create = "no";
};
})
{ }
subvolumes;
};
nextcloudSubvolumes = [
"@nc-config"
"@nc-data"
"@postgres"
"@redis"
"@gitea"
"@gitea-conf"
"@pihole"
"@papermc"
"@docker-cfg"
"@garage"
"@garage-config"
];
2023-01-25 04:55:24 +00:00
2023-01-25 05:08:04 +00:00
postgresSubvolumes = [
"postgres"
"postgres-cfg"
];
2023-01-25 04:55:24 +00:00
sharedModule = { extraPackages ? [ ] }: {
2023-01-25 02:49:00 +00:00
services.openssh.settings.PasswordAuthentication = false;
2023-01-25 02:46:51 +00:00
2023-01-25 02:49:00 +00:00
# Use the extlinux boot loader. (NixOS wants to enable GRUB by default)
boot.loader.grub.enable = false;
# Enables the generation of /boot/extlinux/extlinux.conf
boot.loader.generic-extlinux-compatible.enable = true;
2023-01-25 02:46:51 +00:00
users.users.asonix = {
isNormalUser = true;
description = "Tavi";
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3+mNUlokSKZQNXJAuGm2LCHelKuElWLJArzIYZQYEPbrFaE+J8VtfNbMMD1qVI21ksfcqvFQW4aiP4+BFDxTOGW0uBmUHWKxkyyU39y2yhnsa+svwwIooc+Iwkxw0atzSMEBb94UaZlq9cKMSnG9RGeRFqfYnW2s49wpU79wk6zEFUuOHCMKn4R7zqkPac7IyjxZeKlspY3fOasNH4zyrkbhEOlvrwEOdRNTRNCWWzDcinIVZjfmErHlSynshx9yLnCGkLBxHSxgI2TVyR3RlQ3aGbHtB3QN5X7/T/dwXJFJ11P1Q2bC3XP3hHCogDqXcPvDTFSQEM/mZuFcKNbsn asonix@asonix-tower"
];
};
2023-01-25 02:49:00 +00:00
fileSystems."/" =
2023-01-25 02:46:51 +00:00
{
2023-01-25 02:49:00 +00:00
device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
fsType = "ext4";
};
environment.systemPackages = with pkgs; [
btrbk
] ++ extraPackages;
services.btrbk = {
sshAccess = [
{
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTqU3EvTgY5/e9m6YyQWypQPK58t9iPmPnPYAvnODGB asonix@lionheart";
roles = [ "source" "info" "send" ];
}
];
extraPackages = with pkgs; [ xz ];
instances.btrbk.settings = {
transaction_log = "/var/log/btrbk.log";
stream_buffer = "512m";
snapshot_preserve_min = "2d";
snapshot_preserve = "35d 20w 12m";
target_preserve_min = "24h";
target_preserve = "24h 7d";
archive_preserve_min = "latest";
archive_preserve = "12m 10y";
ssh_user = "btrbk";
ssh_identity = "/etc/btrbk/ssh/backup-ssh-key";
backend_remote = "btrfs-progs-sudo";
};
};
2023-01-25 02:46:51 +00:00
};
2023-01-25 01:58:10 +00:00
2023-01-25 05:08:04 +00:00
makeDockerConfig = { hostname, volume, baseModule }: nixpkgs.lib.nixosSystem {
2023-01-25 04:55:24 +00:00
system = "aarch64-linux";
modules = [
2023-01-25 05:08:04 +00:00
baseModule
2023-01-25 04:55:24 +00:00
(sharedModule
2023-01-25 02:49:00 +00:00
{
2023-01-25 04:55:24 +00:00
extraPackages = with pkgs; [
docker
docker-compose
];
})
{
2023-01-25 05:08:04 +00:00
networking.hostName = hostname;
2023-01-25 02:49:00 +00:00
2023-01-25 04:55:24 +00:00
virtualisation.docker.enable = true;
services.btrbk.instances.btrbk.settings.volume = volume;
}
];
};
deployer = { hostname, configuration }: {
hostname = hostname;
2023-01-25 02:49:00 +00:00
profiles.system = {
user = "root";
sshOpts = [
"-i"
"/home/asonix/.ssh/nix-installer"
];
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
{
2023-01-25 05:08:04 +00:00
nixosConfigurations = with image-builder.packages.aarch64-linux.modules; {
nextcloud1 = makeDockerConfig {
hostname = "nextcloud1";
volume = {
# "ssh://192.168.20.28/btrfs/hdd" = btrbkSecondary {
# target-dir = "/btrfs/hdd/@snapshots";
# subvolumes = nextcloudSubvolumes;
# };
"/btrfs/hdd" = btrbkPrimary {
subvolumes = nextcloudSubvolumes;
};
2023-01-25 04:55:24 +00:00
};
2023-01-25 05:08:04 +00:00
baseModule = rockPro64v2;
2023-01-25 04:55:24 +00:00
};
2023-01-25 05:08:04 +00:00
nextcloud2 = makeDockerConfig {
hostname = "nextcloud2";
2023-01-25 04:55:24 +00:00
volume = {
"ssh://192.168.20.21/btrfs/hdd" = btrbkSecondary {
target-dir = "/btrfs/hdd/@snapshots";
subvolumes = nextcloudSubvolumes;
};
# "/btrfs/hdd" = btrbkPrimary {
# subvolumes = nextcloudSubvolumes;
# };
};
2023-01-25 05:08:04 +00:00
baseModule = rockPro64v2;
2023-01-25 04:55:24 +00:00
};
2023-01-25 05:08:04 +00:00
redtail1 = makeDockerConfig {
hostname = "redtail1";
volume = {
"ssh://192.168.20.24/btrfs/ssd" = btrbkSecondary {
target-dir = "/btrfs/ssd/@snapshots";
subvolumes = postgresSubvolumes;
};
# "/btrfs/ssd" = btrbkPrimary {
# subvolumes = postgresSubvolumes;
# };
};
baseModule = rock64;
};
redtail2 = makeDockerConfig {
hostname = "redtail2";
volume = {
# "ssh://192.168.20.23/btrfs/ssd" = btrbkSecondary {
# target-dir = "/btrfs/ssd/@snapshots";
# subvolumes = postgresSubvolumes;
# };
"/btrfs/ssd" = btrbkPrimary {
subvolumes = postgresSubvolumes;
};
};
baseModule = rock64;
};
whitestorm1 = makeDockerConfig {
hostname = "whitestorm1";
volume = {
# "ssh://192.168.20.11/btrfs/ssd" = btrbkSecondary {
# target-dir = "/btrfs/ssd/@snapshots";
# subvolumes = postgresSubvolumes;
# };
"/btrfs/ssd" = btrbkPrimary {
subvolumes = postgresSubvolumes;
};
};
baseModule = rock64;
};
whitestorm2 = makeDockerConfig {
hostname = "whitestorm2";
volume = {
"ssh://192.168.20.26/btrfs/ssd" = btrbkSecondary {
target-dir = "/btrfs/ssd/@snapshots";
subvolumes = postgresSubvolumes;
};
# "/btrfs/ssd" = btrbkPrimary {
# subvolumes = postgresSubvolumes;
# };
};
baseModule = rock64;
};
};
2023-01-25 04:55:24 +00:00
deploy.nodes.nextcloud2 = deployer {
hostname = "192.168.20.28";
configuration = self.nixosConfigurations.nextcloud2;
};
2023-01-25 01:58:10 +00:00
};
}