self-hosting/flake.nix

73 lines
2.4 KiB
Nix
Raw Normal View History

{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
2021-07-15 17:09:32 +02:00
common = {
modules = [
./hardware/hcloud.nix
./modules/openssh.nix
2021-07-15 17:46:14 +02:00
./environment.nix
2021-07-15 17:09:32 +02:00
];
};
2021-07-15 17:33:31 +02:00
in
{
devShell.x86_64-linux = pkgs.mkShell {
2021-07-15 17:09:32 +02:00
buildInputs = with pkgs; [
2021-07-15 17:33:31 +02:00
nixpkgs-fmt
2021-07-15 17:09:32 +02:00
terraform_0_14
sops
];
};
2021-07-15 17:09:32 +02:00
nixosConfigurations = {
db1 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
2021-07-15 17:33:31 +02:00
modules = common.modules ++ [
2021-07-15 17:09:32 +02:00
./modules/postgresql.nix
2021-07-15 23:46:01 +02:00
./modules/custom-backup-job.nix
2021-07-15 17:09:32 +02:00
({
networking.hostName = "db1";
networking.domain = "banditlair.com";
networking.firewall.interfaces."enp7s0".allowedTCPPorts = [ 5432 ];
2021-07-15 23:46:01 +02:00
services.custom-backup-job = {
additionalReadWritePaths = [ "/nix/var/data/postgresql" ];
2021-07-17 01:02:26 +02:00
additionalPreHook = ''
${pkgs.postgresql_12}/bin/pg_dump -U synapse synapse > /nix/var/data/postgresql/synapse.dmp
${pkgs.postgresql_12}/bin/pg_dump -U nextcloud nextcloud > /nix/var/data/postgresql/nextcloud.dmp
'';
2021-07-15 23:46:01 +02:00
startAt = "03:00";
};
2021-07-15 17:09:32 +02:00
})
];
};
backend1 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
2021-07-15 17:33:31 +02:00
modules = common.modules ++ [
2021-07-17 00:24:30 +02:00
./modules/nginx.nix
2021-07-15 17:09:32 +02:00
./modules/murmur.nix
./modules/synapse.nix
2021-07-17 00:24:30 +02:00
./modules/nextcloud.nix
2021-07-15 23:46:01 +02:00
./modules/custom-backup-job.nix
2021-07-15 17:09:32 +02:00
({
networking.hostName = "backend1";
networking.domain = "banditlair.com";
2021-07-24 03:02:54 +02:00
networking.localCommands = "ip addr add 95.216.177.3/32 dev enp1s0";
2021-07-15 17:09:32 +02:00
networking.firewall.allowedTCPPorts = [ 80 443 64738 ];
networking.firewall.allowedUDPPorts = [ 64738 ];
2021-07-15 23:46:01 +02:00
services.custom-backup-job = {
2021-07-17 01:02:26 +02:00
additionalPaths = [ "/var/lib/nextcloud/config" ];
2021-07-15 23:46:01 +02:00
additionalReadWritePaths = [ "/nix/var/data/murmur" ];
additionalPreHook = "cp /var/lib/murmur/murmur.sqlite /nix/var/data/murmur/murmur.sqlite";
startAt = "03:30";
};
2021-07-15 17:09:32 +02:00
})
];
};
};
};
}