From 8c3de690c9070bc90034e312d6cc722e945fd07b Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Sun, 12 Jul 2026 17:26:55 -0400 Subject: [PATCH] feat(ebook-search): set up uv cache management and pruning service --- .github/workflows/test_ebook_search.yml | 2 ++ python/ebook_search/docker/README.md | 6 ++--- systems/jeeves/runners/default.nix | 5 +++- systems/jeeves/runners/nix_builder.nix | 30 +++++++++++++++-------- systems/jeeves/runners/uv_cache_prune.nix | 28 +++++++++++++++++++++ systems/jeeves/scripts/zfs.sh | 1 + systems/jeeves/snapshot_config.toml | 6 +++++ systems/jeeves/vars.nix | 1 + 8 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 systems/jeeves/runners/uv_cache_prune.nix diff --git a/.github/workflows/test_ebook_search.yml b/.github/workflows/test_ebook_search.yml index 823adfa..788e7db 100644 --- a/.github/workflows/test_ebook_search.yml +++ b/.github/workflows/test_ebook_search.yml @@ -11,6 +11,8 @@ on: env: UV_PYTHON_DOWNLOADS: never + UV_CACHE_DIR: /var/cache/uv + UV_LINK_MODE: copy jobs: test-ebook-search: diff --git a/python/ebook_search/docker/README.md b/python/ebook_search/docker/README.md index 3606863..24a35b9 100644 --- a/python/ebook_search/docker/README.md +++ b/python/ebook_search/docker/README.md @@ -36,11 +36,11 @@ docker compose -f python/ebook_search/docker/docker-compose.yml ps The image builds its environment with uv from `pyproject.toml` + `uv.lock` in this directory — this is the source of truth for the container's dependencies. To add or -update a dependency, edit `pyproject.toml` here and regenerate the lock (requires uv -on the host; it is not in the nix dev shell): +update a dependency, edit `pyproject.toml` here and regenerate the lock (uv is +available in the `ebook-search` dev shell): ```sh -cd python/ebook_search/docker && uv lock +nix develop .#ebook-search -c uv lock --project python/ebook_search/docker ``` ## Tests diff --git a/systems/jeeves/runners/default.nix b/systems/jeeves/runners/default.nix index e24101d..60911a6 100644 --- a/systems/jeeves/runners/default.nix +++ b/systems/jeeves/runners/default.nix @@ -1,6 +1,9 @@ { ... }: { - imports = [ ./nix_builder.nix ]; + imports = [ + ./nix_builder.nix + ./uv_cache_prune.nix + ]; services.nix_builder.containers = { nix-builder-00.enable = true; diff --git a/systems/jeeves/runners/nix_builder.nix b/systems/jeeves/runners/nix_builder.nix index a5e47b7..239562d 100644 --- a/systems/jeeves/runners/nix_builder.nix +++ b/systems/jeeves/runners/nix_builder.nix @@ -62,6 +62,11 @@ in mountPoint = "/run/secrets/gitea-runners"; isReadOnly = true; }; + uv-cache = { + hostPath = vars.uv_cache; + mountPoint = "/var/cache/uv"; + isReadOnly = false; + }; }; config = { @@ -138,7 +143,6 @@ in nixos-rebuild nodejs treefmt - uv wget ]; }; @@ -154,14 +158,20 @@ in } ) cfg.containers; - systemd.services = builtins.listToAttrs ( - map (name: { - name = "container@${name}"; - value = { - requires = [ "gitea.service" ]; - after = [ "gitea.service" ]; - }; - }) (builtins.attrNames (filterAttrs (_: c: c.enable) cfg.containers)) - ); + systemd = { + services = builtins.listToAttrs ( + map (name: { + name = "container@${name}"; + value = { + requires = [ "gitea.service" ]; + after = [ "gitea.service" ]; + }; + }) (builtins.attrNames (filterAttrs (_: c: c.enable) cfg.containers)) + ); + + tmpfiles.rules = [ + "d ${vars.uv_cache} 0755 ${runnerUsername} ${runnerUsername} - -" + ]; + }; }; } diff --git a/systems/jeeves/runners/uv_cache_prune.nix b/systems/jeeves/runners/uv_cache_prune.nix new file mode 100644 index 0000000..19dad73 --- /dev/null +++ b/systems/jeeves/runners/uv_cache_prune.nix @@ -0,0 +1,28 @@ +{ pkgs, ... }: +let + vars = import ../vars.nix; + runnerUsername = "gitea-runner"; +in +{ + systemd = { + services.uv-cache-prune = { + description = "Prune the shared gitea runner uv cache"; + environment.UV_CACHE_DIR = vars.uv_cache; + serviceConfig = { + Type = "oneshot"; + User = runnerUsername; + Group = runnerUsername; + ExecStart = "${pkgs.uv}/bin/uv cache prune"; + }; + }; + + timers.uv-cache-prune = { + description = "Monthly prune of the shared gitea runner uv cache"; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "*-*-01 04:00:00"; + Persistent = true; + }; + }; + }; +} diff --git a/systems/jeeves/scripts/zfs.sh b/systems/jeeves/scripts/zfs.sh index 6938222..8dd630c 100644 --- a/systems/jeeves/scripts/zfs.sh +++ b/systems/jeeves/scripts/zfs.sh @@ -30,6 +30,7 @@ sudo zfs create media/secure/share -o mountpoint=/zfs/media/share -o exec=off # scratch datasets sudo zfs create scratch/kafka -o mountpoint=/zfs/scratch/kafka -o recordsize=1M sudo zfs create scratch/transmission -o mountpoint=/zfs/scratch/transmission -o recordsize=16k -o sync=disabled -o redundant_metadata=none +sudo zfs create scratch/uv_cache -o mountpoint=/zfs/scratch/uv_cache # storage datasets sudo zfs create storage/ollama -o recordsize=1M -o compression=zstd-19 -o sync=disabled diff --git a/systems/jeeves/snapshot_config.toml b/systems/jeeves/snapshot_config.toml index 72d9bce..cb9a3bf 100644 --- a/systems/jeeves/snapshot_config.toml +++ b/systems/jeeves/snapshot_config.toml @@ -121,3 +121,9 @@ monthly = 2 hourly = 0 daily = 0 monthly = 0 + +["scratch/uv_cache"] +15_min = 2 +hourly = 0 +daily = 0 +monthly = 0 diff --git a/systems/jeeves/vars.nix b/systems/jeeves/vars.nix index c64a0c1..a8ffbeb 100644 --- a/systems/jeeves/vars.nix +++ b/systems/jeeves/vars.nix @@ -17,5 +17,6 @@ in transmission = "${zfs_storage}/transmission"; ollama = "${zfs_storage}/ollama"; transmission_scratch = "${zfs_scratch}/transmission"; + uv_cache = "${zfs_scratch}/uv_cache"; kafka = "${zfs_scratch}/kafka"; }