Compare commits

...

2 Commits

9 changed files with 122 additions and 67 deletions

View File

@@ -0,0 +1,53 @@
{ config, pkgs, lib, ... }:
{
# Binary cache server using nix-serve
# Serves built packages to other hosts in the cluster for faster rebuilds
#
# Setup:
# 1. Deploy this host first
# 2. SSH in and get public key: cat /persist/nix-cache/cache-pub-key.txt
# 3. Add that key to common/global/nix.nix in trusted-public-keys
# 4. Deploy all other hosts to pick up the cache
# Ensure cache directory is persisted
environment.persistence."/persist".directories = [
{ directory = "/var/nix-cache"; user = "nix-serve"; group = "nix-serve"; mode = "0755"; }
];
# Auto-generate cache keys on first boot
systemd.services.nix-cache-key-init = {
description = "Generate binary cache keys if missing";
wantedBy = [ "multi-user.target" ];
before = [ "nix-serve.service" ];
path = [ pkgs.nix ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
CACHE_DIR="/persist/nix-cache"
mkdir -p "$CACHE_DIR"
if [ ! -f "$CACHE_DIR/cache-priv-key.pem" ]; then
echo "Generating binary cache key pair..."
nix-store --generate-binary-cache-key ${config.networking.hostName}-cache "$CACHE_DIR/cache-priv-key.pem" "$CACHE_DIR/cache-pub-key.txt"
chmod 600 "$CACHE_DIR/cache-priv-key.pem"
chmod 644 "$CACHE_DIR/cache-pub-key.txt"
echo "Binary cache keys generated at $CACHE_DIR"
echo "Public key:"
cat "$CACHE_DIR/cache-pub-key.txt"
fi
'';
};
# Enable nix-serve
services.nix-serve = {
enable = true;
secretKeyFile = "/persist/nix-cache/cache-priv-key.pem";
bindAddress = "0.0.0.0";
port = 5000;
};
# Open firewall for LAN access
networking.firewall.allowedTCPPorts = [ 5000 ];
}

View File

@@ -1,8 +1,30 @@
{ {
nix.settings.trusted-users = [ nix.settings = {
trusted-users = [
"root" "root"
"@wheel" "@wheel"
]; ];
# Binary cache configuration
substituters = [
"http://c3:5000" # Local cluster cache on c3
"https://cache.nixos.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
# TODO: Add c3 cache public key here after first deploy of c3
# Get it with: ssh c3 cat /persist/nix-cache/cache-pub-key.txt
# "c3-cache:..."
];
# Performance tuning
max-jobs = "auto"; # Use all cores for parallel builds
cores = 0; # Each build can use all cores
max-substitution-jobs = 16; # Faster fetching from caches
http-connections = 25; # More parallel downloads
download-attempts = 3; # Retry failed downloads
};
nix.gc = { nix.gc = {
automatic = true; automatic = true;
dates = "weekly"; dates = "weekly";

View File

@@ -26,12 +26,8 @@ in
cidr = "100.64.0.0/10"; cidr = "100.64.0.0/10";
}; };
host_volume = { host_volume = {
code = { services = {
path = "/data/compute/code"; path = "/data/services";
read_only = true;
};
appdata = {
path = "/data/compute/appdata";
read_only = false; read_only = false;
}; };
nix-store = { nix-store = {

View File

@@ -62,7 +62,7 @@ See [CLUSTER_REVAMP.md](./CLUSTER_REVAMP.md) for detailed procedures.
- [x] prometheus.hcl - migrated to `/data/services` - [x] prometheus.hcl - migrated to `/data/services`
- [x] grafana.hcl - migrated to `/data/services` (2025-10-23) - [x] grafana.hcl - migrated to `/data/services` (2025-10-23)
- [x] loki.hcl - migrated to `/data/services` - [x] loki.hcl - migrated to `/data/services`
- [ ] vector.hcl - needs update to remove glusterfs log collection (line 26, 101-109) - [x] vector.hcl - removed glusterfs log collection (2025-10-23)
### Databases (HIGH) ### Databases (HIGH)
- [x] clickhouse.hcl - migrated to `/data/services` - [x] clickhouse.hcl - migrated to `/data/services`
@@ -71,9 +71,8 @@ See [CLUSTER_REVAMP.md](./CLUSTER_REVAMP.md) for detailed procedures.
### Web Applications (HIGH-MEDIUM) ### Web Applications (HIGH-MEDIUM)
- [x] wordpress.hcl - migrated to `/data/services` - [x] wordpress.hcl - migrated to `/data/services`
- [x] gitea.hcl - migrated to `/data/services` (2025-10-23) - [x] gitea.hcl - migrated to `/data/services` (2025-10-23)
- [ ] wiki.hcl - uses `appdata` volume (points to `/data/compute/appdata`) - [x] wiki.hcl - migrated to `/data/services` (2025-10-23)
- [x] plausible.hcl - stateless, no changes needed - [x] plausible.hcl - stateless, no changes needed
- [ ] tiddlywiki.hcl - uses `appdata` volume (points to `/data/compute/appdata`)
### Web Applications (LOW, may be deprecated) ### Web Applications (LOW, may be deprecated)
- [x] vikunja.hcl - migrated to `/data/services` (2025-10-23, not running) - [x] vikunja.hcl - migrated to `/data/services` (2025-10-23, not running)
@@ -93,8 +92,8 @@ See [CLUSTER_REVAMP.md](./CLUSTER_REVAMP.md) for detailed procedures.
- [x] urbit.hcl - migrated to `/data/services` - [x] urbit.hcl - migrated to `/data/services`
- [x] webodm.hcl - migrated to `/data/services` (2025-10-23, not running) - [x] webodm.hcl - migrated to `/data/services` (2025-10-23, not running)
- [x] velutrack.hcl - migrated to `/data/services` - [x] velutrack.hcl - migrated to `/data/services`
- [ ] resol-gateway.hcl - uses `code` volume (points to `/data/compute/code`) - [x] resol-gateway.hcl - migrated to `/data/services` (2025-10-23)
- [ ] igsync.hcl - uses `appdata` volume (points to `/data/compute/appdata`) - [x] igsync.hcl - migrated to `/data/services` (2025-10-23)
- [x] jupyter.hcl - migrated to `/data/services` (2025-10-23, not running) - [x] jupyter.hcl - migrated to `/data/services` (2025-10-23, not running)
- [x] whoami.hcl - stateless test service, no changes needed - [x] whoami.hcl - stateless test service, no changes needed
@@ -103,7 +102,7 @@ See [CLUSTER_REVAMP.md](./CLUSTER_REVAMP.md) for detailed procedures.
- [x] postgres-backup.hcl - migrated to `/data/services` - [x] postgres-backup.hcl - migrated to `/data/services`
### Host Volume Definitions (CRITICAL) ### Host Volume Definitions (CRITICAL)
- [ ] common/nomad.nix - update host_volume paths from `/data/compute/{appdata,code}` to `/data/services/{appdata,code}` - [x] common/nomad.nix - consolidated `appdata` and `code` volumes into single `services` volume (2025-10-23)
### Verification ### Verification
- [ ] All services healthy in Nomad - [ ] All services healthy in Nomad
@@ -144,22 +143,18 @@ See [CLUSTER_REVAMP.md](./CLUSTER_REVAMP.md) for detailed procedures.
--- ---
**Last updated**: 2025-10-23 21:16 **Last updated**: 2025-10-23 22:30
**Current phase**: Phase 4 in progress (26/35 services migrated, 4 host-volume services + config updates remaining, 4 stateless) **Current phase**: Phase 4 complete! All services migrated to NFS
**Note**: Phase 1 (fractal NixOS conversion) deferred until after GlusterFS migration is complete **Note**: Phase 1 (fractal NixOS conversion) deferred until after GlusterFS migration is complete
## Migration Summary ## Migration Summary
**Already migrated to `/data/services` (26 services):** **All services migrated to `/data/services` (30 total):**
mysql, mysql-backup, postgres, postgres-backup, redis, clickhouse, prometheus, grafana, loki, unifi, wordpress, gitea, traefik, evcc, weewx, netbox, farmos, webodm, jupyter, vikunja, urbit, code-server, beancount, velutrack, maps, media mysql, mysql-backup, postgres, postgres-backup, redis, clickhouse, prometheus, grafana, loki, vector, unifi, wordpress, gitea, wiki, traefik, evcc, weewx, netbox, farmos, webodm, jupyter, vikunja, urbit, code-server, beancount, velutrack, maps, media, resol-gateway, igsync
**Still need migration (4 services using host volumes):**
- wiki (appdata), tiddlywiki (appdata), igsync (appdata), resol-gateway (code)
- These require updating common/nomad.nix host_volume definitions first
**Stateless/no changes needed (4 services):** **Stateless/no changes needed (4 services):**
authentik, adminer, plausible, whoami authentik, adminer, plausible, whoami
**Configuration updates needed:** **Configuration changes:**
- vector.hcl: remove glusterfs log collection - common/nomad.nix: consolidated `appdata` and `code` volumes into single `services` volume
- common/nomad.nix: update host_volume paths - vector.hcl: removed glusterfs log collection

View File

@@ -4,6 +4,7 @@
../../common/encrypted-btrfs-layout.nix ../../common/encrypted-btrfs-layout.nix
../../common/global ../../common/global
../../common/compute-node.nix ../../common/compute-node.nix
../../common/binary-cache-server.nix
./hardware.nix ./hardware.nix
]; ];

View File

@@ -19,24 +19,24 @@ job "igsync" {
read_only = true read_only = true
source = "sw" source = "sw"
} }
volume "appdata" { volume "services" {
type = "host" type = "host"
read_only = false read_only = false
source = "appdata" source = "services"
} }
task "sync" { task "sync" {
driver = "exec" driver = "exec"
config { config {
command = "/appdata/igsync/run.sh" command = "/data/services/igsync/run.sh"
} }
user = "ppetru" user = "ppetru"
volume_mount { volume_mount {
volume = "appdata" volume = "services"
destination = "/appdata" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"

View File

@@ -2,10 +2,10 @@ job "resol-gateway" {
datacenters = ["alo"] datacenters = ["alo"]
group "gw" { group "gw" {
volume "code" { volume "services" {
type = "host" type = "host"
read_only = true read_only = true
source = "code" source = "services"
} }
volume "nix-store" { volume "nix-store" {
type = "host" type = "host"
@@ -29,12 +29,12 @@ job "resol-gateway" {
config { config {
command = "/sw/bin/node" command = "/sw/bin/node"
args = ["/code/resol-vbus/examples/json-live-data-server/index.js"] args = ["/data/services/resol-vbus/examples/json-live-data-server/index.js"]
} }
volume_mount { volume_mount {
volume = "code" volume = "services"
destination = "/code" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"

View File

@@ -23,7 +23,6 @@ job "vector" {
ports = ["api", "metrics"] ports = ["api", "metrics"]
volumes = [ volumes = [
"/var/run/docker.sock:/var/run/docker.sock:ro", "/var/run/docker.sock:/var/run/docker.sock:ro",
"/var/log/glusterfs:/var/log/glusterfs:ro",
"/var/log/journal:/var/log/journal:ro", "/var/log/journal:/var/log/journal:ro",
"/etc/machine-id:/etc/machine-id:ro", "/etc/machine-id:/etc/machine-id:ro",
] ]
@@ -98,16 +97,6 @@ if length(result) > 0 {
.host = del(.label."com.hashicorp.nomad.node_name") .host = del(.label."com.hashicorp.nomad.node_name")
''' '''
[sources.glusterfs_raw]
type = "file"
include = [ "/var/log/glusterfs/**/*.log" ]
[transforms.glusterfs_transformed]
type = "remap"
inputs = [ "glusterfs_raw" ]
source = '''
.job_name = .file
'''
[sources.journald_raw] [sources.journald_raw]
type = "journald" type = "journald"
[transforms.journald_transformed] [transforms.journald_transformed]
@@ -122,7 +111,6 @@ if length(result) > 0 {
inputs = [ inputs = [
"vector_transformed", "vector_transformed",
"docker_transformed", "docker_transformed",
"glusterfs_transformed",
"journald_transformed", "journald_transformed",
] ]
endpoint = "http://[[ range service "loki" ]][[ .Address ]]:[[ .Port ]][[ end ]]" endpoint = "http://[[ range service "loki" ]][[ .Address ]]:[[ .Port ]][[ end ]]"

View File

@@ -2,10 +2,10 @@ job "wiki" {
datacenters = ["alo"] datacenters = ["alo"]
group "servers" { group "servers" {
volume "appdata" { volume "services" {
type = "host" type = "host"
read_only = false read_only = false
source = "appdata" source = "services"
} }
volume "nix-store" { volume "nix-store" {
type = "host" type = "host"
@@ -31,8 +31,8 @@ job "wiki" {
config { config {
command = "/sw/bin/node" command = "/sw/bin/node"
args = [ args = [
"/appdata/wiki/node_modules/tiddlywiki/tiddlywiki.js", "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
"/appdata/wiki/captainslog", "/data/services/wiki/captainslog",
"--listen", "--listen",
"host=0.0.0.0", "host=0.0.0.0",
"port=${NOMAD_PORT_captainslog}", "port=${NOMAD_PORT_captainslog}",
@@ -46,8 +46,8 @@ job "wiki" {
user = "ppetru" user = "ppetru"
volume_mount { volume_mount {
volume = "appdata" volume = "services"
destination = "/appdata" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"
@@ -80,8 +80,8 @@ job "wiki" {
config { config {
command = "/sw/bin/node" command = "/sw/bin/node"
args = [ args = [
"/appdata/wiki/node_modules/tiddlywiki/tiddlywiki.js", "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
"/appdata/wiki/alo", "/data/services/wiki/alo",
"--listen", "--listen",
"host=0.0.0.0", "host=0.0.0.0",
"port=${NOMAD_PORT_alo}", "port=${NOMAD_PORT_alo}",
@@ -93,8 +93,8 @@ job "wiki" {
} }
volume_mount { volume_mount {
volume = "appdata" volume = "services"
destination = "/appdata" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"
@@ -128,8 +128,8 @@ job "wiki" {
config { config {
command = "/sw/bin/node" command = "/sw/bin/node"
args = [ args = [
"/appdata/wiki/node_modules/tiddlywiki/tiddlywiki.js", "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
"/appdata/wiki/pispace", "/data/services/wiki/pispace",
"--listen", "--listen",
"host=0.0.0.0", "host=0.0.0.0",
"port=${NOMAD_PORT_pispace}", "port=${NOMAD_PORT_pispace}",
@@ -141,8 +141,8 @@ job "wiki" {
} }
volume_mount { volume_mount {
volume = "appdata" volume = "services"
destination = "/appdata" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"
@@ -176,8 +176,8 @@ job "wiki" {
config { config {
command = "/sw/bin/node" command = "/sw/bin/node"
args = [ args = [
"/appdata/wiki/node_modules/tiddlywiki/tiddlywiki.js", "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
"/appdata/wiki/grok", "/data/services/wiki/grok",
"--listen", "--listen",
"host=0.0.0.0", "host=0.0.0.0",
"port=${NOMAD_PORT_grok}", "port=${NOMAD_PORT_grok}",
@@ -189,8 +189,8 @@ job "wiki" {
} }
volume_mount { volume_mount {
volume = "appdata" volume = "services"
destination = "/appdata" destination = "/data/services"
} }
volume_mount { volume_mount {
volume = "nix-store" volume = "nix-store"