From 0d4698ab78423cf238c10e411b7d1df3a24b4166 Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Thu, 29 Jun 2023 17:11:13 +0200 Subject: [PATCH] Create a way to deploy rest of terranix without containers Signed-off-by: Magic_RB --- flake.lock | 6 +++--- flake.nix | 9 +++++++++ home-manager/modules/pantalaimon.nix | 10 +++++++++- terranix/containers/email/default.nix | 10 +++++++++- terranix/containers/gateway-mesh/default.nix | 5 ++++- terranix/containers/gitea/default.nix | 6 ++++-- terranix/containers/home-assistant/default.nix | 6 ++++-- terranix/containers/hydra/default.nix | 6 ++++-- terranix/containers/ingress-blowhole/default.nix | 6 ++++-- terranix/containers/ingress-toothpick/default.nix | 5 ++++- terranix/containers/jellyfin/default.nix | 5 ++++- terranix/containers/matrix/default.nix | 10 ++++++++-- terranix/containers/syncthing/default.nix | 5 ++++- terranix/containers/website/default.nix | 5 ++++- terranix/default.nix | 5 +++++ 15 files changed, 79 insertions(+), 20 deletions(-) diff --git a/flake.lock b/flake.lock index 204832c..030f9af 100644 --- a/flake.lock +++ b/flake.lock @@ -1058,11 +1058,11 @@ "terranix": "terranix" }, "locked": { - "lastModified": 1687130036, - "narHash": "sha256-U7q2iwNNdB0A7GHyLjNYLWluOVJO+K0LtiOV0Y3/vuY=", + "lastModified": 1687982768, + "narHash": "sha256-GofM1CCW5l4hQtgea7lqUMQs4kRc/unx9As/vGG92hg=", "owner": "~magic_rb", "repo": "uterranix", - "rev": "30dd60117a71c3f6bb152af03ef6f7fd686abf1c", + "rev": "9ee50d0b284d76cd5b2abde709c927066d2c319b", "type": "sourcehut" }, "original": { diff --git a/flake.nix b/flake.nix index 32cac6a..9bf677e 100644 --- a/flake.nix +++ b/flake.nix @@ -110,6 +110,15 @@ nixos = mapAttrs (_: v: v.config.system.build.toplevel) config.flake.nixosConfigurations; }; + uterranix.preCommands = '' + TF_VAR_dont_deploy_containers=false + if [ "${self.rev or ""}" == "" ] || [ "${self.narHask or ""}" == "" ] + then + TF_VAR_dont_deploy_containers=true + fi + export TF_VAR_dont_deploy_containers + ''; + uterranix.config = [ ./terranix/default.nix { diff --git a/home-manager/modules/pantalaimon.nix b/home-manager/modules/pantalaimon.nix index 13ee3d2..3a0dfef 100644 --- a/home-manager/modules/pantalaimon.nix +++ b/home-manager/modules/pantalaimon.nix @@ -1,7 +1,15 @@ -{ ... }: +{ pkgs, ... }: { services.pantalaimon = { enable = true; + package = pkgs.pantalaimon.overrideAttrs (old: { + src = pkgs.fetchFromGitHub { + owner = "matrix-org"; + repo = "pantalaimon"; + rev = "3968c69aa846889970df1372ba9aa54c1c5e4290"; + hash = "sha256-JdoJB68QtxPhFeZCHd+0ZOlUDbQV3HeBsxW0KbhnDSs="; + }; + }); settings = { Default = diff --git a/terranix/containers/email/default.nix b/terranix/containers/email/default.nix index de30427..92065d8 100644 --- a/terranix/containers/email/default.nix +++ b/terranix/containers/email/default.nix @@ -1,10 +1,17 @@ -{ elib, vars, ... }: +{ elib, tflib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { + variable."dont_deploy_containers" = { + type = "boolean"; + description = "Whether the data to deploy containers properly is available."; + }; + resource."vault_policy"."dovecot-policy" = nfsVolume { name = "dovecot-policy"; policy = '' @@ -40,6 +47,7 @@ in }; resource."nomad_job"."email" = { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; diff --git a/terranix/containers/gateway-mesh/default.nix b/terranix/containers/gateway-mesh/default.nix index e4fa385..3ac2063 100644 --- a/terranix/containers/gateway-mesh/default.nix +++ b/terranix/containers/gateway-mesh/default.nix @@ -1,10 +1,13 @@ -{ elib, ... }: +{ tflib, elib, ... }: let inherit (elib) nomadJob; + inherit (tflib) + tf; in { resource."nomad_job"."mesh" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; vars = { "datacenters" = builtins.toJSON [ diff --git a/terranix/containers/gitea/default.nix b/terranix/containers/gitea/default.nix index 1a81a75..dd0b337 100644 --- a/terranix/containers/gitea/default.nix +++ b/terranix/containers/gitea/default.nix @@ -1,8 +1,10 @@ -{ elib, vars, ... }: +{ tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."gitea-db" = nfsVolume { @@ -31,8 +33,8 @@ in }; resource."nomad_job"."gitea" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; - vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; flake_sha = vars.flake_sha; diff --git a/terranix/containers/home-assistant/default.nix b/terranix/containers/home-assistant/default.nix index 68c394d..09dc2c0 100644 --- a/terranix/containers/home-assistant/default.nix +++ b/terranix/containers/home-assistant/default.nix @@ -1,8 +1,10 @@ -{ elib, vars, ... }: +{ tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."home-assistant_hass" = nfsVolume { @@ -69,8 +71,8 @@ in }; resource."nomad_job"."home-assistant" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; - vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; flake_sha = vars.flake_sha; diff --git a/terranix/containers/hydra/default.nix b/terranix/containers/hydra/default.nix index 0deda2c..2307269 100644 --- a/terranix/containers/hydra/default.nix +++ b/terranix/containers/hydra/default.nix @@ -1,8 +1,10 @@ -{ config, elib, vars, ... }: +{ config, tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."hydra-db" = nfsVolume { @@ -39,8 +41,8 @@ in }; resource."nomad_job"."hydra" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; - vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; flake_sha = vars.flake_sha; diff --git a/terranix/containers/ingress-blowhole/default.nix b/terranix/containers/ingress-blowhole/default.nix index c004baf..b416fc5 100644 --- a/terranix/containers/ingress-blowhole/default.nix +++ b/terranix/containers/ingress-blowhole/default.nix @@ -1,12 +1,14 @@ -{ elib, vars, ... }: +{ tflib, elib, vars, ... }: let inherit (elib) nomadJob; + inherit (tflib) + tf; in { resource."nomad_job"."ingress" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; - vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; flake_sha = vars.flake_sha; diff --git a/terranix/containers/ingress-toothpick/default.nix b/terranix/containers/ingress-toothpick/default.nix index fe6e17f..3d726e5 100644 --- a/terranix/containers/ingress-toothpick/default.nix +++ b/terranix/containers/ingress-toothpick/default.nix @@ -1,8 +1,10 @@ -{ elib, secret, vars, ... }: +{ tflib, elib, secret, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."ingress-letsencrypt" = nfsVolume { @@ -14,6 +16,7 @@ in }; resource."nomad_job"."ingress" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; diff --git a/terranix/containers/jellyfin/default.nix b/terranix/containers/jellyfin/default.nix index b1a73e2..e913bdb 100644 --- a/terranix/containers/jellyfin/default.nix +++ b/terranix/containers/jellyfin/default.nix @@ -1,8 +1,10 @@ -{ elib, ... }: +{ tflib, elib, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."jellyfin-cache" = nfsVolume { @@ -30,6 +32,7 @@ in }; resource."nomad_job"."jellyfin" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; }; } diff --git a/terranix/containers/matrix/default.nix b/terranix/containers/matrix/default.nix index fd4654c..607fcd1 100644 --- a/terranix/containers/matrix/default.nix +++ b/terranix/containers/matrix/default.nix @@ -1,8 +1,10 @@ -{ config, elib, vars, ... }: +{ config, tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_volume"."matrix-synapse" = nfsVolume { @@ -136,6 +138,7 @@ in }; resource."nomad_job"."matrix-synapse" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./matrix-synapse.hcl; vars = { flake_ref = "${vars.flake_host}?ref=${vars.flake_ref}&rev=${vars.flake_rev}"; @@ -144,6 +147,7 @@ in }; resource."nomad_job"."matrix-mautrix-discord" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./matrix-mautrix-discord.hcl; vars = { flake_ref = "${vars.flake_host}?ref=${vars.flake_ref}&rev=${vars.flake_rev}"; @@ -152,6 +156,7 @@ in }; resource."nomad_job"."matrix-mautrix-facebook" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./matrix-mautrix-facebook.hcl; vars = { flake_ref = "${vars.flake_host}?ref=${vars.flake_ref}&rev=${vars.flake_rev}"; @@ -160,6 +165,7 @@ in }; resource."nomad_job"."matrix-mautrix-signal" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./matrix-mautrix-signal.hcl; vars = { flake_ref = "${vars.flake_host}?ref=${vars.flake_ref}&rev=${vars.flake_rev}"; @@ -168,8 +174,8 @@ in }; resource."nomad_job"."matrix-heisenbridge" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./matrix-heisenbridge.hcl; - vars = { flake_ref = "${vars.flake_host}?ref=${vars.flake_ref}&rev=${vars.flake_rev}"; flake_sha = vars.flake_sha; diff --git a/terranix/containers/syncthing/default.nix b/terranix/containers/syncthing/default.nix index 465ce7f..d653d05 100644 --- a/terranix/containers/syncthing/default.nix +++ b/terranix/containers/syncthing/default.nix @@ -1,8 +1,10 @@ -{ pkgs, elib, vars, ... }: +{ pkgs, tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; sharePrefix = "/mnt/kyle/infrastructure/syncthing"; in @@ -32,6 +34,7 @@ in }; resource."nomad_job"."syncthing" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; diff --git a/terranix/containers/website/default.nix b/terranix/containers/website/default.nix index 2909566..a46febd 100644 --- a/terranix/containers/website/default.nix +++ b/terranix/containers/website/default.nix @@ -1,11 +1,14 @@ -{ pkgs, elib, vars, ... }: +{ pkgs, tflib, elib, vars, ... }: let inherit (elib) nfsVolume nomadJob; + inherit (tflib) + tf; in { resource."nomad_job"."website" = nomadJob { + count = tf "var.dont_deploy_containers ? 0 : 1"; jobspec = ./job.hcl; vars = { flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; diff --git a/terranix/default.nix b/terranix/default.nix index 36c2925..206df7c 100644 --- a/terranix/default.nix +++ b/terranix/default.nix @@ -42,6 +42,11 @@ in sensitive = true; }; + variable."dont_deploy_containers" = { + type = "boolean"; + description = "Whether the data to deploy containers properly is available."; + }; + provider."hcloud" = { token = tf "var.hcloud_token"; };