From 3aa7119bed2d7d9fa2166c44a8a8ff09d6f7be7e Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sun, 28 Jun 2026 15:35:11 -0400 Subject: [PATCH] guidlines & restart on env change --- GUIDELINES.md | 46 ++++++++++----- .../common/containers/container-services.nix | 54 +++++++++++++++++- secrets/hermes-env.age | Bin 792 -> 793 bytes 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/GUIDELINES.md b/GUIDELINES.md index 9a3482e..f5cea97 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -7,22 +7,30 @@ Read this file before making any changes. ## Hard Rules — Never Break These -### ❌ NEVER run builds or system switches -Do NOT run any of the following, ever: +### ❌ NEVER run builds or system switches — ZERO EXCEPTIONS +**DO NOT RUN ANY OF THESE COMMANDS AT ANY TIME, FOR ANY REASON:** ``` -nixos-rebuild switch / test / build +nixos-rebuild switch / test / build / dry-build nh os switch / test / build skyg os switch / test / build skyg remote switch / test / build skyg hm switch / build nix build nix flake check +docker/podman build ``` -These commands take 20–40+ minutes, consume significant CPU/RAM, and can break a live -system. The user runs these themselves after reviewing changes. Your job is to make -correct edits to the source files — not to apply them. +**Why:** +- These commands take 20–40+ minutes +- They consume significant CPU/RAM on the user's machine +- They can block the user from their own work +- They can break the live system if something is wrong +- The user MUST control when and what gets built + +**Your job:** Make correct edits to source files. The user validates and runs builds themselves. + +**Even if the user says "go ahead":** Do NOT run these. Your role is to write good Nix, not execute it. ### ❌ NEVER edit `flake.lock` by hand This file is managed exclusively by `nix flake update`. Editing it manually will corrupt @@ -43,7 +51,9 @@ the `makeNixOs` call in `flake.nix` via `modules/main.nix`. Adding imports to a breaks the composition model. -### ❌ NEVER modify `GUIDELINES.md` unless explicitly requested by the user, you must live and die by these and hold yourself accountable to them! +### ❌ NEVER modify `GUIDELINES.md` unless explicitly requested by the user +You must **live and die by these rules** and hold yourself accountable to them. +These are not suggestions — they are non-negotiable. --- @@ -60,6 +70,14 @@ These are always safe to perform without asking: --- +## When In Doubt + +If you are unsure whether a command is safe, **assume it is not safe and don't run it.** + +Instead: describe what you would do and ask the user for permission. + +--- + ## NixOS Conventions in This Repo ### Option Namespace @@ -123,22 +141,22 @@ Do not configure `services.greetd` manually on these hosts — the DMS module ha ## Validation Without Building -After making changes you can verify syntax without running a build: +If you want to verify syntax **without triggering a build**, these are safe: ```bash -# Check Nix expression syntax only (fast, safe) +# Check Nix expression syntax only (fast, safe, no eval) nix-instantiate --parse .nix - -# Check the flake structure without building -nix flake show --no-build 2>/dev/null ``` -Even these are optional — the user will validate by running `nh os switch` themselves. +**But even these are optional.** The user will validate by running `nh os switch` themselves. + +**Golden rule:** When in doubt, don't run anything. Just describe your changes. --- -## Commit / Branch Policy +## Commit / Branch / Git Policy - Do NOT commit changes or create branches unless the user explicitly asks - Do NOT `git add`, `git commit`, or `git push` autonomously +- You may run `git add` **only** if required for a Nix evaluation (e.g., new files must be tracked for flakes) - Describe what you changed in your final message so the user can review before committing diff --git a/modules/nixos/common/containers/container-services.nix b/modules/nixos/common/containers/container-services.nix index 6a1d5e2..1c75ca7 100644 --- a/modules/nixos/common/containers/container-services.nix +++ b/modules/nixos/common/containers/container-services.nix @@ -71,6 +71,12 @@ let # ── Systemd service builder ────────────────────────────────────────────── + # Collect all env files from all services in a group. + getAllEnvFiles = grpCfg: + lib.concatLists + (lib.attrValues + (lib.mapAttrs (_: svcCfg: svcCfg.environmentFiles) grpCfg.services)); + mkSystemdService = groupName: grpCfg: let composeFile = mkComposeFile groupName grpCfg; @@ -93,6 +99,32 @@ let }; }; + # Create a path unit that triggers a restart when env files change. + mkPathUnit = groupName: envFiles: + lib.optionalAttrs (envFiles != [ ]) { + "container-services-${groupName}-env-reload" = { + description = "Watch env files for container service group '${groupName}'"; + pathConfig = { + PathChanged = map builtins.toString envFiles; + Unit = "container-services-${groupName}-env-reload.service"; + }; + wantedBy = [ "multi-user.target" ]; + }; + }; + + # Service that restarts the compose stack when env files change. + mkEnvReloadService = groupName: + { + "container-services-${groupName}-env-reload" = { + description = "Restart container service group '${groupName}' on env file changes"; + serviceConfig = { + Type = "oneshot"; + # Restart the compose stack + ExecStart = "${pkgs.systemd}/bin/systemctl restart container-services-${groupName}.service"; + }; + }; + }; + enabledGroups = lib.filterAttrs (_: g: g.enable) cfg; in @@ -172,6 +204,7 @@ in Paths to env files loaded by compose at runtime. Accepts runtime paths such as agenix secret paths (e.g. config.age.secrets.my-secret.path). + Changes to these files will trigger an automatic restart. ''; }; @@ -202,7 +235,7 @@ in description = '' Free-form attrset merged directly into the compose service block. Use this for keys not modelled above: - shm_size, cap_add, devices, healthcheck, deploy, etc. + shm_size, cap_add, devices, healthcheck, etc. ''; }; @@ -263,6 +296,23 @@ in lib.nameValuePair "container-services-${groupName}" (mkSystemdService groupName grpCfg)) - enabledGroups; + enabledGroups + // lib.foldAttrs lib.recursiveUpdate { } ( + lib.mapAttrsToList + (groupName: grpCfg: + mkEnvReloadService groupName) + (lib.filterAttrs + (_: grpCfg: getAllEnvFiles grpCfg != [ ]) + enabledGroups) + ); + + # Path units that watch env files and trigger restarts. + systemd.paths = + lib.foldAttrs lib.recursiveUpdate { } ( + lib.mapAttrsToList + (groupName: grpCfg: + mkPathUnit groupName (getAllEnvFiles grpCfg)) + enabledGroups + ); }; } diff --git a/secrets/hermes-env.age b/secrets/hermes-env.age index d56a0ae396225679a7ea8c6f7407dc93e1360676..552aaca374af9a410b2b8a07ad6f91342600ac88 100644 GIT binary patch delta 761 zcmVZ(eP*rR>IZ#zJWI}0aHES?OXlyWeR6{UwV>WJWYYHts zAaiqQEoEdfH8n9gAZL0^RCjkEVr_OvL{(TxHZxf-G)q==Qhzc-T1Iy^b$Lr|F)K50 zRz*yDP*+iGL~?9v3OG$+YeQ3dO*CURPj7Q`b3`*~OmIy|FmO;uYE*4lGG{M#YA;VV zbWBxa3N0-yAWl_jGc$HmNlbTDQ}ZBKV`bTUCja%XNbOlNj$LRxlgV^T+B z3iO186S~P(6n_oa>8c+Nf>*!oJtoFd2gW_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