From 066b3acec1d0caeb8439fbc65ce023a4e689de68 Mon Sep 17 00:00:00 2001 From: oqyude Date: Sun, 25 Oct 2026 02:09:45 +0300 Subject: [PATCH] refactor(nix): consolidate fragmented attribute-path writes Same owner written as '.a = ...; .b = ...;' repeated dotted paths is now one attrset block. Behaviour-preserving (values, list order and comments kept): - 3xui-reconfig description/serviceConfig in server/ and vds/ (separate units, different PANEL_URL - deliberately not extracted into a shared module) - authelia after/wants inside the existing config = mkIf wrapper - gitea-actions-runner settings: runner/metrics/health_check/container - boot.loader.grub, services.logind, pxe-infra.bridge, pipewire.alsa - nix.{distributedBuilds,buildMachines}; nix.settings on WSL (mkForce kept) - build.activation on termux (nix-on-droid freeform) Also in this commit: lamet.opencodes.zeroq.su upstream 6061 -> 4096 (verified by nix eval of the vhost proxyPass). nix-instantiate --parse: 12/12 files OK. --- configurations/any.nix | 8 +++++--- configurations/mini-laptop.nix | 12 +++++++---- configurations/mini-pc.nix | 6 ++++-- modules/server/authelia.nix | 6 ++++-- modules/server/builder.nix | 6 ++++-- modules/server/default.nix | 23 ++++++++++++--------- modules/server/gitea-runner.nix | 36 ++++++++++++++++++++------------- modules/server/nginx.nix | 2 +- modules/termux/default.nix | 10 +++++---- modules/vds/default.nix | 23 ++++++++++++--------- modules/wsl/builder.nix | 29 +++++++++++++------------- 11 files changed, 95 insertions(+), 66 deletions(-) diff --git a/configurations/any.nix b/configurations/any.nix index d56c994..a730709 100644 --- a/configurations/any.nix +++ b/configurations/any.nix @@ -25,7 +25,9 @@ device = "/dev/sda1"; fsType = "ext4"; }; - boot.loader.grub.enable = true; - boot.loader.grub.devices = [ "/dev/sda" ]; - boot.loader.grub.configurationLimit = 50; + boot.loader.grub = { + enable = true; + devices = [ "/dev/sda" ]; + configurationLimit = 50; + }; } diff --git a/configurations/mini-laptop.nix b/configurations/mini-laptop.nix index dcb38f7..b9624d5 100644 --- a/configurations/mini-laptop.nix +++ b/configurations/mini-laptop.nix @@ -67,8 +67,10 @@ # headless-сервер для engipy (sapphira проксирует /api/* на него). # Если пользователь берёт ноутбук в руки — пусть остаётся правило # по умолчанию (suspend); но для unattended-режима нужно ignore. - services.logind.lidSwitch = "ignore"; - services.logind.lidSwitchDocked = "ignore"; + services.logind = { + lidSwitch = "ignore"; + lidSwitchDocked = "ignore"; + }; system.stateVersion = "26.05"; @@ -87,8 +89,10 @@ # `modules/pxe-infra/` for the implementation. pxe-infra = { enable = true; - bridge.address = "10.66.0.1"; - bridge.prefixLength = 24; + bridge = { + address = "10.66.0.1"; + prefixLength = 24; + }; # ipxe.efi (universal, ~600K) instead of snp.efi (SNP-only, 310K). # snp.efi worked on linux-virt 6.18.56 but breaks on 6.18.57 # (delivered via aports 2b1f5137, 2026-10-16, kernel commit diff --git a/configurations/mini-pc.nix b/configurations/mini-pc.nix index b31f811..44ffda5 100644 --- a/configurations/mini-pc.nix +++ b/configurations/mini-pc.nix @@ -58,8 +58,10 @@ services.pipewire = { enable = lib.mkDefault true; systemWide = true; - alsa.enable = false; - alsa.support32Bit = true; + alsa = { + enable = false; + support32Bit = true; + }; pulse.enable = true; jack.enable = true; extraConfig.pipewire = { diff --git a/modules/server/authelia.nix b/modules/server/authelia.nix index 5b76050..767fb9b 100644 --- a/modules/server/authelia.nix +++ b/modules/server/authelia.nix @@ -192,8 +192,10 @@ in # creates to deploy credentials; depending on its name avoids the # "race between tmpfiles-setup and the sops materialiser" that the # previous tmpfiles-symlink design implicitly relied on. - systemd.services.authelia.after = [ "sops-nix.service" ]; - systemd.services.authelia.wants = [ "sops-nix.service" ]; + systemd.services.authelia = { + after = [ "sops-nix.service" ]; + wants = [ "sops-nix.service" ]; + }; # sops wiring. Guarded by builtins.pathExists so the flake still # evaluates when ./secrets/authelia.yaml hasn't been created yet — diff --git a/modules/server/builder.nix b/modules/server/builder.nix index 230ee6f..4c2f68e 100644 --- a/modules/server/builder.nix +++ b/modules/server/builder.nix @@ -102,8 +102,10 @@ in # populated. (The build-machine list still lands in /etc/nix/machines # but nix-daemon reads `builders`, not /etc/nix/machines, when # distributedBuilds is false.) - nix.distributedBuilds = true; - nix.buildMachines = map forNix config.host.builder.clients; + nix = { + distributedBuilds = true; + buildMachines = map forNix config.host.builder.clients; + }; # Nix 2.34's daemon does not act on `@/etc/nix/machines` (the file # format NixOS's nix-remote-build writes to): the `builders` config # key is parsed for display but `external-builders` stays empty and diff --git a/modules/server/default.nix b/modules/server/default.nix index 310efa2..06b7916 100644 --- a/modules/server/default.nix +++ b/modules/server/default.nix @@ -76,16 +76,19 @@ # # В otreca аналогичный юнит определён в `modules/vds/default.nix` с # другим `PANEL_URL`/`apiToken`. - systemd.services."3xui-reconfig".serviceConfig.Type = "oneshot"; - systemd.services."3xui-reconfig".serviceConfig.ExecStart = - lib.getExe config.modules."3x-ui".reconfig; - systemd.services."3xui-reconfig".serviceConfig.Environment = [ - "PANEL_URL=https://127.0.0.1:2049" - "PANEL_BASE=@base" - "PANEL_TOKEN=@api_token" - ]; - systemd.services."3xui-reconfig".description = - "Перегенерировать config.json 3x-ui из БД и рестартнуть xray (R1.18)."; + systemd.services."3xui-reconfig" = { + description = + "Перегенерировать config.json 3x-ui из БД и рестартнуть xray (R1.18)."; + serviceConfig = { + Type = "oneshot"; + ExecStart = lib.getExe config.modules."3x-ui".reconfig; + Environment = [ + "PANEL_URL=https://127.0.0.1:2049" + "PANEL_BASE=@base" + "PANEL_TOKEN=@api_token" + ]; + }; + }; # engipy webapp — split architecture: # - sapphira : host.engipy-frontend.enable → nginx vhost (engipy.zeroq.su) # с /api/* на rydiwo:8000 и / → /var/lib/engipy/web diff --git a/modules/server/gitea-runner.nix b/modules/server/gitea-runner.nix index 40b3d4e..7d0594d 100644 --- a/modules/server/gitea-runner.nix +++ b/modules/server/gitea-runner.nix @@ -56,24 +56,30 @@ in labels = [ "native:host" ]; # only host-executor; no docker required settings = { - runner.capacity = 1; # sequential on 2-core host - runner.timeout = "2h"; - runner.workdir_cleanup_age = "48h"; - runner.idle_cleanup_interval = "20m"; + runner = { + capacity = 1; # sequential on 2-core host + timeout = "2h"; + workdir_cleanup_age = "48h"; + idle_cleanup_interval = "20m"; + }; # Localhost-only. Co-resident processes can still reach it; scrape # via ssh+localhost if ever needed. - metrics.enabled = true; - metrics.addr = "127.0.0.1:9101"; + metrics = { + enabled = true; + addr = "127.0.0.1:9101"; + }; # Workspace in /tmp is tmpfs (size = ~50% of RAM ≈ 2.8 GiB # on sapphira), so the default 4 GB threshold would always trip. # 256 MiB is plenty for smoke-test workflows and still trips # meaningfully if tmpfs truly fills. - health_check.enabled = true; - health_check.min_free_disk_space_mb = 256; - health_check.interval = "5m"; - health_check.timeout = "30s"; + health_check = { + enabled = true; + min_free_disk_space_mb = 256; + interval = "5m"; + timeout = "30s"; + }; # Workspace in /tmp (tmpfs). Same approach as GH Actions runners — # ephemeral, always writable by the runner's UID. Avoids racing with @@ -85,10 +91,12 @@ in host.workdir_parent = "/tmp/gitea-runner-work"; # Defence in depth even though host labels never pull images. - container.docker_host = ""; - container.network = ""; - container.privileged = false; - container.options = ""; + container = { + docker_host = ""; + network = ""; + privileged = false; + options = ""; + }; }; # The PATH of every host-mode job. One shared list (lib/ci-tools.nix) with diff --git a/modules/server/nginx.nix b/modules/server/nginx.nix index 7f1d859..c4f7733 100644 --- a/modules/server/nginx.nix +++ b/modules/server/nginx.nix @@ -471,7 +471,7 @@ in forceSSL = true; enableACME = true; locations."/" = { - proxyPass = "http://100.106.21.39:6061"; + proxyPass = "http://100.106.21.39:4096"; proxyWebsockets = true; }; }; diff --git a/modules/termux/default.nix b/modules/termux/default.nix index e1e084f..21fae32 100644 --- a/modules/termux/default.nix +++ b/modules/termux/default.nix @@ -39,7 +39,8 @@ in ''; # Generate the host key on first activation (idempotent). - build.activation.sshd = '' + build.activation = { + sshd = '' if [[ ! -d "${sshdDir}" ]]; then $DRY_RUN_CMD rm -rf "${sshdTmpDir}" $DRY_RUN_CMD mkdir -p "${sshdTmpDir}" @@ -56,7 +57,7 @@ in # ~/.local/state/nix/profiles/channels (dangling until it exists), which # home-manager cannot link into. mkdir -p refuses to traverse a dangling # symlink, so create the real target dir instead. - build.activation.nixdefexpr = '' + nixdefexpr = '' $DRY_RUN_CMD mkdir -p "${config.user.home}/.local/state/nix/profiles/channels/nixpkgs" $DRY_RUN_CMD touch "${config.user.home}/.local/state/nix/profiles/channels/nixpkgs/.keep" ''; @@ -67,13 +68,14 @@ in # NOTE: tailscaled was removed — nixpkgs' linux build cannot run inside # proot (SELinux blocks netlink; needs GOOS=android or root). Re-add only # if that gets solved. - build.activation.services = '' + services = '' $DRY_RUN_CMD rm -rf ${serviceDir}/tailscaled $DRY_RUN_CMD mkdir -p ${serviceDir}/sshd/log $DRY_RUN_CMD ln -sfn ${sshdRun}/bin/sshd-run ${serviceDir}/sshd/run $DRY_RUN_CMD ln -sfn ${svLogRun}/bin/sv-log-run ${serviceDir}/sshd/log/run $DRY_RUN_CMD ln -sfn ${serviceDir} /etc/service - ''; + ''; + }; environment.packages = [ pkgs.runit diff --git a/modules/vds/default.nix b/modules/vds/default.nix index 5339d42..3af131f 100644 --- a/modules/vds/default.nix +++ b/modules/vds/default.nix @@ -37,16 +37,19 @@ # 3xui-reconfig.service` — без хоста. Это намеренно: владелец стартует # их по очереди; один из них адресует локальную панель, другой — удалённую, # и оба лечат одно и то же «сервер крутит старое».) - systemd.services."3xui-reconfig".serviceConfig.Type = "oneshot"; - systemd.services."3xui-reconfig".serviceConfig.ExecStart = - lib.getExe config.modules."3x-ui".reconfig; - systemd.services."3xui-reconfig".serviceConfig.Environment = [ - "PANEL_URL=https://pubray1.zeroq.su" - "PANEL_BASE=@base" - "PANEL_TOKEN=@api_token" - ]; - systemd.services."3xui-reconfig".description = - "Перегенерировать config.json 3x-ui из БД и рестартнуть xray (R1.18) — вариант для Otreca (публичный домен)."; + systemd.services."3xui-reconfig" = { + description = + "Перегенерировать config.json 3x-ui из БД и рестартнуть xray (R1.18) — вариант для Otreca (публичный домен)."; + serviceConfig = { + Type = "oneshot"; + ExecStart = lib.getExe config.modules."3x-ui".reconfig; + Environment = [ + "PANEL_URL=https://pubray1.zeroq.su" + "PANEL_BASE=@base" + "PANEL_TOKEN=@api_token" + ]; + }; + }; systemd.tmpfiles.rules = [ (xlib.helpers.mkTmpfile "d" "/mnt" "0755" "root" "root") diff --git a/modules/wsl/builder.nix b/modules/wsl/builder.nix index 220a9d0..13e7a3b 100644 --- a/modules/wsl/builder.nix +++ b/modules/wsl/builder.nix @@ -26,24 +26,25 @@ # actually deliver. `nixos-test` is dropped for the same reason — it # wants kvm anyway. # - # `mkForce` because the NixOS module base-config sets a non-empty - # default; without force the lists would concatenate and the WSL would - # *still* advertise kvm. - nix.settings.system-features = lib.mkForce [ - "benchmark" - "big-parallel" - ]; - # Builds arrive over SSH as the user `oqyude` (see # modules/server/builder.nix). On the default trusted-users = ["root"] # only root can call nix-store, so the SSH session would fail to realise # any .drv. Adding the SSH user to trusted-users lets the remote nix-build - # driver drive nix-store on the builder side. `mkForce` for the same - # concatenation reason as above. - nix.settings.trusted-users = lib.mkForce [ - "root" - "oqyude" - ]; + # driver drive nix-store on the builder side. + # + # `mkForce` on both lists because the NixOS module base-config sets a + # non-empty default; without force the lists would concatenate, and the + # WSL would *still* advertise kvm. + nix.settings = { + system-features = lib.mkForce [ + "benchmark" + "big-parallel" + ]; + trusted-users = lib.mkForce [ + "root" + "oqyude" + ]; + }; # The local daemon already parallelises across all 24 logical cores # (max-jobs = 24 is what we measured). When acting as a builder, we