mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
feat: add minio+cockroachdb
This commit is contained in:
parent
bdd402ffeb
commit
2d615951a2
11 changed files with 121 additions and 12 deletions
|
|
@ -109,6 +109,8 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.cockroachdb.locality = "provider=oracle,region=${oci-root.outputs.oci_region.import},ad=${cfg.ad},host=${config.networking.hostName}";
|
||||||
|
|
||||||
deploy.tf =
|
deploy.tf =
|
||||||
let
|
let
|
||||||
compartment_id = oci-root.resources.oci_kw_compartment.importAttr "id";
|
compartment_id = oci-root.resources.oci_kw_compartment.importAttr "id";
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ in {
|
||||||
_module.args.tf = mapNullable (target: target.tf) target;
|
_module.args.tf = mapNullable (target: target.tf) target;
|
||||||
out = jsonConfig;
|
out = jsonConfig;
|
||||||
deploy.tf = {
|
deploy.tf = {
|
||||||
|
terraform.environment.ESPHOME = "${pkgs.esphome}";
|
||||||
attrs = [ "import" "imports" "out" "attrs" "triggers" ];
|
attrs = [ "import" "imports" "out" "attrs" "triggers" ];
|
||||||
import = genAttrs cfg.tf.imports (target: meta.deploy.targets.${target}.tf);
|
import = genAttrs cfg.tf.imports (target: meta.deploy.targets.${target}.tf);
|
||||||
out.set = removeAttrs cfg.tf cfg.tf.attrs;
|
out.set = removeAttrs cfg.tf cfg.tf.attrs;
|
||||||
|
|
@ -75,7 +76,7 @@ in {
|
||||||
provider = "local";
|
provider = "local";
|
||||||
type = "file";
|
type = "file";
|
||||||
inputs = {
|
inputs = {
|
||||||
filename = "${tf.terraform.dataDir}/esphome-${name}-secrets.json";
|
filename = "${builtins.toString tf.terraform.dataDir}/esphome-${name}-secrets.json";
|
||||||
content = secretsFile;
|
content = secretsFile;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -86,10 +87,13 @@ in {
|
||||||
provisioners = [
|
provisioners = [
|
||||||
{
|
{
|
||||||
type = "local-exec";
|
type = "local-exec";
|
||||||
local-exec.command = ''
|
local-exec = {
|
||||||
${pkgs.esphome}/bin/esphome compile ${closureConfig} ${tf.resources."${name}-secrets".refAttr "filename"}
|
working_dir = builtins.toString tf.terraform.dataDir;
|
||||||
${pkgs.esphome}/bin/esphome upload ${closureConfig} --device ${name}.local
|
command = ''
|
||||||
'';
|
${pkgs.esphome}/bin/esphome compile ${closureConfig} ${tf.resources."${name}-secrets".refAttr "filename"}
|
||||||
|
${pkgs.esphome}/bin/esphome upload ${closureConfig} ${tf.resources."${name}-secrets".refAttr "filename"} --device ${name}.local
|
||||||
|
'';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
@ -103,7 +107,7 @@ in {
|
||||||
path = if length parts > 1 then head parts else "password";
|
path = if length parts > 1 then head parts else "password";
|
||||||
in nameValuePair "${config.esphome.name}-secret-${name}" ({
|
in nameValuePair "${config.esphome.name}-secret-${name}" ({
|
||||||
value.shellCommand = let
|
value.shellCommand = let
|
||||||
bitw = pkgs.writeShellScriptBin "bitw" ''${pkgs.rbw-bitw}/bin/bitw -p gpg://${config.network.nodes.all.${builtins.getEnv "HOME_HOSTNAME"}.secrets.repo.bitw.source} "$@"'';
|
bitw = pkgs.writeShellScriptBin "bitw" ''${pkgs.rbw-bitw}/bin/bitw -p gpg://${meta.network.nodes.all.${builtins.getEnv "HOME_HOSTNAME"}.secrets.repo.bitw.source} "$@"'';
|
||||||
in "${bitw}/bin/bitw get ${path} -f ${field}";
|
in "${bitw}/bin/bitw get ${path} -f ${field}";
|
||||||
type = "string";
|
type = "string";
|
||||||
sensitive = true;
|
sensitive = true;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{ config, pkgs, lib, ... }: {
|
{ config, pkgs, lib, meta, ... }: {
|
||||||
_module.args.pkgs = lib.mkDefault pkgs;
|
_module.args.pkgs = lib.mkDefault meta.pkgs;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
services.vaultwarden
|
services.vaultwarden
|
||||||
services.weechat
|
services.weechat
|
||||||
services.znc
|
services.znc
|
||||||
|
services.cockroachdb
|
||||||
];
|
];
|
||||||
|
|
||||||
nixfiles.oci = {
|
nixfiles.oci = {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,11 @@
|
||||||
services.nginx
|
services.nginx
|
||||||
services.access
|
services.access
|
||||||
services.irlsite
|
services.irlsite
|
||||||
|
services.cockroachdb
|
||||||
];
|
];
|
||||||
|
|
||||||
|
services.cockroachdb.locality = "provider=buyvm,region=luxembourg,host=${config.networking.hostName}";
|
||||||
|
|
||||||
boot = {
|
boot = {
|
||||||
loader.grub = {
|
loader.grub = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,36 @@
|
||||||
group = "hass";
|
group = "hass";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
secrets.variables.latitude = {
|
||||||
|
path = "secrets/home-assistant";
|
||||||
|
field = "latitude";
|
||||||
|
};
|
||||||
|
|
||||||
|
secrets.variables.longitude = {
|
||||||
|
path = "secrets/home-assistant";
|
||||||
|
field = "longitude";
|
||||||
|
};
|
||||||
|
|
||||||
|
secrets.variables.elevation = {
|
||||||
|
path = "secrets/home-assistant";
|
||||||
|
field = "elevation";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
secrets.files.home-assistant-secrets = {
|
||||||
|
text = builtins.toJSON {
|
||||||
|
latitude = tf.variables.latitude.ref;
|
||||||
|
longitude = tf.variables.longitude.ref;
|
||||||
|
elevation = tf.variables.elevation.ref;
|
||||||
|
};
|
||||||
|
owner = "hass";
|
||||||
|
group = "hass";
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.home-assistant = {
|
systemd.services.home-assistant = {
|
||||||
preStart = lib.mkBefore ''
|
preStart = lib.mkBefore ''
|
||||||
rm ${config.services.home-assistant.configDir}/integration.json
|
cp --no-preserve=mode ${config.secrets.files.home-assistant-secrets.path} ${config.services.home-assistant.configDir}/secrets.yaml
|
||||||
cp --no-preserve=mode ${config.secrets.files.ha-integration.path} ${config.services.home-assistant.configDir}/integration.json
|
cp --no-preserve=mode ${config.secrets.files.ha-integration.path} ${config.services.home-assistant.configDir}/integration.yaml
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,6 +67,11 @@
|
||||||
homeassistant = {
|
homeassistant = {
|
||||||
name = "Gensokyo";
|
name = "Gensokyo";
|
||||||
unit_system = "metric";
|
unit_system = "metric";
|
||||||
|
latitude = "!secret latitude";
|
||||||
|
longitude = "!secret longitude";
|
||||||
|
elevation = "!secret elevation";
|
||||||
|
currency = "CAD";
|
||||||
|
time_zone = "America/Vancouver";
|
||||||
external_url = "https://home.gensokyo.zone";
|
external_url = "https://home.gensokyo.zone";
|
||||||
};
|
};
|
||||||
frontend = {
|
frontend = {
|
||||||
|
|
@ -93,7 +124,7 @@
|
||||||
};
|
};
|
||||||
google_assistant = {
|
google_assistant = {
|
||||||
project_id = "gensokyo-5cfaf";
|
project_id = "gensokyo-5cfaf";
|
||||||
service_account = "!include integration.json";
|
service_account = "!include integration.yaml";
|
||||||
};
|
};
|
||||||
homekit = {
|
homekit = {
|
||||||
name = "Tewi";
|
name = "Tewi";
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
(modulesPath + "/installer/scan/not-detected.nix")
|
(modulesPath + "/installer/scan/not-detected.nix")
|
||||||
hardware.local
|
hardware.local
|
||||||
nixos.network
|
nixos.network
|
||||||
|
services.cockroachdb
|
||||||
./kanidm.nix
|
./kanidm.nix
|
||||||
./vouch.nix
|
./vouch.nix
|
||||||
./home-assistant.nix
|
./home-assistant.nix
|
||||||
|
|
@ -14,6 +15,8 @@
|
||||||
./nginx.nix
|
./nginx.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
services.cockroachdb.locality = "provider=local,network=gensokyo,host=${config.networking.hostName}";
|
||||||
|
|
||||||
networks = {
|
networks = {
|
||||||
gensokyo = {
|
gensokyo = {
|
||||||
interfaces = [
|
interfaces = [
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,11 @@
|
||||||
services.tvheadend
|
services.tvheadend
|
||||||
services.zfs
|
services.zfs
|
||||||
services.plex
|
services.plex
|
||||||
|
services.cockroachdb
|
||||||
];
|
];
|
||||||
|
|
||||||
|
services.cockroachdb.locality = "provider=local,network=chitei,host=${config.networking.hostName}";
|
||||||
|
|
||||||
boot.supportedFilesystems = singleton "zfs";
|
boot.supportedFilesystems = singleton "zfs";
|
||||||
|
|
||||||
fileSystems = {
|
fileSystems = {
|
||||||
|
|
|
||||||
21
services/cockroachdb.nix
Normal file
21
services/cockroachdb.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{ config, meta, lib, ... }: let
|
||||||
|
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
||||||
|
inherit (lib.strings) concatStringsSep;
|
||||||
|
in {
|
||||||
|
services = {
|
||||||
|
cockroachdb = {
|
||||||
|
enable = true;
|
||||||
|
insecure = true;
|
||||||
|
join = concatStringsSep "," (mapAttrsToList (_: nixos:
|
||||||
|
"${nixos.networks.tailscale.ipv4}:${builtins.toString nixos.services.cockroachdb.listen.port}"
|
||||||
|
) (filterAttrs (_: nixos: nixos.services.cockroachdb.enable) meta.network.nodes.nixos));
|
||||||
|
http = {
|
||||||
|
address = config.networks.tailscale.ipv4;
|
||||||
|
port = 8973;
|
||||||
|
};
|
||||||
|
listen = {
|
||||||
|
address = config.networks.tailscale.ipv4;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
41
services/minio.nix
Normal file
41
services/minio.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
{ config, lib, ... }: let
|
||||||
|
import (lib.modules) mkIf mkDefault;
|
||||||
|
cfg = config.services.minio;
|
||||||
|
in {
|
||||||
|
options.services.minio.isNAS = mkEnableFunction "NAS lack of defaults";
|
||||||
|
|
||||||
|
config = {
|
||||||
|
secrets = {
|
||||||
|
variables = mapAttrs' (name: value: nameValuePair "minio-${name}-key" value) (genAttrs ["access" "secret"] (name: {
|
||||||
|
path = "gensokyo/minio";
|
||||||
|
field = "${name}-key";
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
files = {
|
||||||
|
minio-root-credentials = {
|
||||||
|
text = ''
|
||||||
|
MINIO_ROOT_USER=${tf.variables.minio-access-key.ref}
|
||||||
|
MINIO_ROOT_PASSWORD=${tf.variables.minio-secret-key.ref}
|
||||||
|
'';
|
||||||
|
owner = "minio";
|
||||||
|
group = "minio";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = mkIf !cfg.isNAS ''
|
||||||
|
v /minio 700 minio minio
|
||||||
|
'';
|
||||||
|
|
||||||
|
services = {
|
||||||
|
minio = {
|
||||||
|
region = config.services.cockroachdb.locality;
|
||||||
|
enable = true;
|
||||||
|
dataDir = lib.optional !cfg.isNAS "/minio";
|
||||||
|
listenAddress = "${config.networks.tailscale.ipv4}:9000";
|
||||||
|
consoleAddress = "${config.networks.tailcale.ipv4}:9001";
|
||||||
|
rootCredentialsFile = config.secrets.files.minio-root-credentials.path;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
2
tf
2
tf
|
|
@ -1 +1 @@
|
||||||
Subproject commit 109f880332d0f9f4cfaf2ed8db8e9cee577a6cbd
|
Subproject commit 158e27e798d8808a0a54127122a6ceaffa2b12a7
|
||||||
Loading…
Add table
Add a link
Reference in a new issue