From e2c240ba4bef55c571e4ff1d41605c0d9221faf3 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Sat, 19 Sep 2026 21:01:23 -0400 Subject: [PATCH] refactor(python): use dedicated runtime environments --- .github/workflows/merge_flake_lock_update.yml | 1 - .github/workflows/update-flake-lock.yml | 1 - common/global/programs.nix | 1 - common/optional/zfs/snapshot.nix | 13 +++++++- overlays/default.nix | 31 ------------------- shell.nix | 3 +- systems/brain/services/heater.nix | 16 +++++++++- systems/jeeves/runners/nix_builder.nix | 9 +++++- systems/jeeves/services/gems.nix | 18 ++++++++++- 9 files changed, 53 insertions(+), 40 deletions(-) diff --git a/.github/workflows/merge_flake_lock_update.yml b/.github/workflows/merge_flake_lock_update.yml index d923269..fe94edc 100644 --- a/.github/workflows/merge_flake_lock_update.yml +++ b/.github/workflows/merge_flake_lock_update.yml @@ -15,7 +15,6 @@ jobs: steps: - name: merge_flake_lock_update run: >- - nix develop .#devShells.x86_64-linux.default -c python -m python.gitea_flake_lock merge --repo "${{ github.repository }}" env: diff --git a/.github/workflows/update-flake-lock.yml b/.github/workflows/update-flake-lock.yml index aa126b7..dd6c148 100644 --- a/.github/workflows/update-flake-lock.yml +++ b/.github/workflows/update-flake-lock.yml @@ -21,6 +21,5 @@ jobs: JEEVES_BOT_TOKEN: ${{ secrets.JEEVES_BOT_TOKEN }} GITEA_URL: https://gitea.tmmworkshop.com run: >- - nix develop .#devShells.x86_64-linux.default -c python -m python.gitea_flake_lock update --repo "${{ github.repository }}" diff --git a/common/global/programs.nix b/common/global/programs.nix index 57d8819..bb69bd1 100644 --- a/common/global/programs.nix +++ b/common/global/programs.nix @@ -2,6 +2,5 @@ { environment.systemPackages = with pkgs; [ git - my_python ]; } diff --git a/common/optional/zfs/snapshot.nix b/common/optional/zfs/snapshot.nix index d2126fb..b2c4168 100644 --- a/common/optional/zfs/snapshot.nix +++ b/common/optional/zfs/snapshot.nix @@ -34,6 +34,17 @@ in }; config = lib.mkIf cfg.enable { + nixpkgs.overlays = [ + (final: _prev: { + snapshot_manager_python = final.python314.withPackages ( + ps: with ps; [ + apprise + typer + ] + ); + }) + ]; + systemd = { services.snapshot_manager = { description = "ZFS Snapshot Manager"; @@ -45,7 +56,7 @@ in }; serviceConfig = { Type = "oneshot"; - ExecStart = "${pkgs.my_python}/bin/python -m python.tools.snapshot_manager ${lib.escapeShellArg cfg.path}"; + ExecStart = "${pkgs.snapshot_manager_python}/bin/python -m python.tools.snapshot_manager ${lib.escapeShellArg cfg.path}"; } // lib.optionalAttrs (cfg.EnvironmentFile != null) { EnvironmentFile = cfg.EnvironmentFile; diff --git a/overlays/default.nix b/overlays/default.nix index 114df6b..2451e19 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -17,35 +17,4 @@ test-exclusions = import ./test-exclusions.nix; x86-64-v3-workarounds = import ./x86-64-v3-workarounds.nix; - - python-env = final: _prev: { - my_python = final.python314.withPackages ( - ps: with ps; [ - alembic - apprise - fastapi - fastapi-cli - httpx - jinja2 - mypy - pgvector - psycopg - pydantic - pyfakefs - pytest - pytest-cov - pytest-mock - pytest-xdist - python-multipart - pydantic-settings - ruff - sqlalchemy - tenacity - tinytuya - typer - uvicorn - websockets - ] - ); - }; } diff --git a/shell.nix b/shell.nix index 13d40cb..40cf992 100644 --- a/shell.nix +++ b/shell.nix @@ -8,7 +8,7 @@ # loader path, which NixOS does not provide globally. ebook-search = pkgs.mkShell { nativeBuildInputs = with pkgs; [ - my_python + python314 uv ]; LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ @@ -23,7 +23,6 @@ nix home-manager git - my_python ssh-to-age gnupg diff --git a/systems/brain/services/heater.nix b/systems/brain/services/heater.nix index 398b8dc..a35803c 100644 --- a/systems/brain/services/heater.nix +++ b/systems/brain/services/heater.nix @@ -4,6 +4,20 @@ ... }: { + nixpkgs.overlays = [ + (final: _prev: { + heater_python = final.python314.withPackages ( + ps: with ps; [ + fastapi + pydantic + tinytuya + typer + uvicorn + ] + ); + }) + ]; + networking.firewall.allowedTCPPorts = [ 8124 ]; systemd.services.heater-api = { @@ -17,7 +31,7 @@ serviceConfig = { Type = "simple"; - ExecStart = "${pkgs.my_python}/bin/python -m python.heater.main --host 0.0.0.0 --port 8124"; + ExecStart = "${pkgs.heater_python}/bin/python -m python.heater.main --host 0.0.0.0 --port 8124"; EnvironmentFile = "/etc/heater.env"; Restart = "on-failure"; RestartSec = "5s"; diff --git a/systems/jeeves/runners/nix_builder.nix b/systems/jeeves/runners/nix_builder.nix index 46af0c7..81a27af 100644 --- a/systems/jeeves/runners/nix_builder.nix +++ b/systems/jeeves/runners/nix_builder.nix @@ -23,6 +23,13 @@ let ... }: let + giteaAutomationPython = pkgs.python314.withPackages ( + ps: with ps; [ + httpx + pydantic + typer + ] + ); runnerConfigFile = (pkgs.formats.yaml { }).generate "gitea-runner.yaml" { }; registerRunner = pkgs.writeShellApplication { name = "register-gitea-runner"; @@ -96,8 +103,8 @@ let curl gawk gitMinimal + giteaAutomationPython gnused - my_python nix nixfmt nixos-rebuild diff --git a/systems/jeeves/services/gems.nix b/systems/jeeves/services/gems.nix index 9164d1e..a7893d0 100644 --- a/systems/jeeves/services/gems.nix +++ b/systems/jeeves/services/gems.nix @@ -8,6 +8,22 @@ let stateDir = "${vars.services}/gems"; in { + nixpkgs.overlays = [ + (final: _prev: { + gems_python = final.python314.withPackages ( + ps: with ps; [ + fastapi + jinja2 + pydantic + pydantic-settings + python-multipart + typer + uvicorn + ] + ); + }) + ]; + users.groups.gems = { }; users.users.gems = { isSystemUser = true; @@ -36,7 +52,7 @@ in Type = "simple"; User = "gems"; Group = "gems"; - ExecStart = "${pkgs.my_python}/bin/python -m python.gems.main --host 0.0.0.0 --port 8002"; + ExecStart = "${pkgs.gems_python}/bin/python -m python.gems.main --host 0.0.0.0 --port 8002"; Restart = "on-failure"; RestartSec = "5s"; StandardOutput = "journal";