Add cj.deployment module

That way we can configure the depployment tags and everything in a
single location.
This commit is contained in:
Moritz 'e1mo' Fromm 2023-07-28 10:31:36 +02:00
parent 52a0991bfb
commit 047d73dc78
No known key found for this signature in database
GPG key ID: 1D5D79A439E787F1
9 changed files with 54 additions and 16 deletions

View file

@ -1,6 +1,7 @@
{ config, lib, pkgs, inputs, ... }: { { config, lib, pkgs, inputs, ... }: {
imports = [ imports = [
./users.nix ./users.nix
../modules/deployment.nix
# Monitoring is applicable to all hosts, thus placing it here # Monitoring is applicable to all hosts, thus placing it here
../services/monitoring ../services/monitoring
]; ];

View file

@ -57,7 +57,7 @@
}; };
defaults = { name, config, ... }: { defaults = { name, config, ... }: {
deployment = { deployment = {
tags = if name == "shirley" then [ "prod" ] else [ "dev" ]; tags = [ config.cj.deployment.environment ];
targetHost = config.networking.fqdn; targetHost = config.networking.fqdn;
targetUser = null; targetUser = null;
}; };

View file

@ -1,5 +1,5 @@
{ lib, pkgs, baseDomain, ... }: { { lib, pkgs, baseDomain, ... }: {
_module.args.baseDomain = "dev.chaos.jetzt"; cj.deployment.environment = "dev";
imports = [ imports = [
./hardware-config.nix ./hardware-config.nix

View file

@ -1,5 +1,5 @@
{ pkgs, baseDomain, ... }: { { pkgs, baseDomain, ... }: {
_module.args.baseDomain = "chaos.jetzt"; cj.deployment.environment = "prod";
imports = [ imports = [
./hardware-config.nix ./hardware-config.nix

26
modules/deployment.nix Normal file
View file

@ -0,0 +1,26 @@
{ config
, options
, lib
, ... }:
let
inherit (lib) mkOption types optionalString;
cfg = config.cj.deployment;
isDev = cfg.environment == "dev";
in
{
options.cj.deployment = {
environment = mkOption {
description = "Environment this host will be used for. Affects both colmena deploy groups and the baseDomain";
type = types.enum [ "dev" "prod" ];
};
};
config = {
_module.args = {
inherit isDev;
baseDomain = "${optionalString isDev "dev."}chaos.jetzt";
};
};
}

View file

@ -1,10 +1,12 @@
{ { pkgs
pkgs, , config
config, , lib
lib, , baseDomain
baseDomain, , isDev
... , ...
}: let }:
let
fpm_pool = "dokuwiki-${dw_domain}"; fpm_pool = "dokuwiki-${dw_domain}";
fpm_cfg = config.services.phpfpm.pools.${fpm_pool}; fpm_cfg = config.services.phpfpm.pools.${fpm_pool};
dw_domain = "wiki.${baseDomain}"; dw_domain = "wiki.${baseDomain}";
@ -143,7 +145,7 @@ in {
}; };
plugin.oauthkeycloak = { plugin.oauthkeycloak = {
key = get_secret "dokuwiki/keycloak_key"; key = get_secret "dokuwiki/keycloak_key";
openidurl = "https://sso.chaos.jetzt/auth/realms/chaos-jetzt/.well-known/openid-configuration"; openidurl = "https://sso.chaos.jetzt/auth/realms/${if isDev then "dev" else "chaos-jetzt"}/.well-known/openid-configuration";
}; };
}; };

View file

@ -37,7 +37,7 @@
isMe = host: host.config.networking.fqdn == fqdn; isMe = host: host.config.networking.fqdn == fqdn;
others = filterAttrs (_: !isMe) outputs.nixosConfigurations; others = filterAttrs (_: !isMe) outputs.nixosConfigurations;
isDev = host: (substring 0 3 host._module.args.baseDomain) == "dev"; isDev = host: host._module.args.isDev;
allHosts = outputs.nixosConfigurations // externalTargets; allHosts = outputs.nixosConfigurations // externalTargets;
/* /*
Right now we only have one non-dev host in our NixOS setup (the ansible hosts don't monitor the NixOS hosts). Right now we only have one non-dev host in our NixOS setup (the ansible hosts don't monitor the NixOS hosts).

View file

@ -1,9 +1,13 @@
{ lib, config, pkgs, baseDomain, ... }: { lib
, config
, pkgs
, baseDomain
, isDev
, ... }:
let let
vwDbUser = config.users.users.vaultwarden.name; vwDbUser = config.users.users.vaultwarden.name;
vwDbName = config.users.users.vaultwarden.name; vwDbName = config.users.users.vaultwarden.name;
isDev = (builtins.substring 0 3 baseDomain) == "dev";
isDevStr = lib.optionalString isDev; isDevStr = lib.optionalString isDev;
in { in {
sops.secrets = { sops.secrets = {

View file

@ -1,4 +1,10 @@
{ lib, pkgs, config, baseDomain, ...}: { lib
, pkgs
, config
, baseDomain
, isDev
, ...}:
let let
matrixWellKnown = { matrixWellKnown = {
client."m.homeserver".base_url = "https://matrix.${baseDomain}/"; client."m.homeserver".base_url = "https://matrix.${baseDomain}/";
@ -6,7 +12,6 @@ let
}; };
toJSONFile = name: value: pkgs.writeText name (builtins.toJSON value); toJSONFile = name: value: pkgs.writeText name (builtins.toJSON value);
matrixWellKnownDir = pkgs.linkFarm "matrix-well-known" (builtins.mapAttrs toJSONFile matrixWellKnown); matrixWellKnownDir = pkgs.linkFarm "matrix-well-known" (builtins.mapAttrs toJSONFile matrixWellKnown);
isDev = (builtins.substring 0 3 baseDomain) == "dev";
webroot = "${config.users.users."web-deploy".home}/public"; webroot = "${config.users.users."web-deploy".home}/public";
deployPubKey = if isDev then deployPubKey = if isDev then
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRmpgMjXQCjA/YPNJvaNdKMjr0jnLtwKKbLCIisjeBw dev-deploykey@chaos.jetzt" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRmpgMjXQCjA/YPNJvaNdKMjr0jnLtwKKbLCIisjeBw dev-deploykey@chaos.jetzt"