remove s3 cache items that are already on cache.nixos.org
This commit is contained in:
parent
40136d283f
commit
f1ecfd283c
4 changed files with 41 additions and 29 deletions
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
|
@ -65,11 +65,10 @@ jobs:
|
||||||
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||||
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixcache:8KKuGz95Pk4UJ5W/Ni+pN+v+LDTkMMFV4yrGmAYgkDg= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=
|
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixcache:8KKuGz95Pk4UJ5W/Ni+pN+v+LDTkMMFV4yrGmAYgkDg= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=
|
||||||
experimental-features = nix-command flakes ca-derivations
|
experimental-features = nix-command flakes ca-derivations
|
||||||
|
post-build-hook = ${{ github.workspace }}/scripts/post-build-hook
|
||||||
substituters = https://cache.chir.rs/
|
substituters = https://cache.chir.rs/
|
||||||
- name: Download patched nix
|
- name: Download patched nix
|
||||||
run: nix build github:DarkKirb/nix-packages#nix-s3-dedup
|
run: nix build github:DarkKirb/nix-packages#nix-s3-dedup
|
||||||
- name: Setup post-build-hook
|
|
||||||
run: echo "post-build-hook = ${{ github.workspace }}/scripts/post-build-hook" | sudo tee -a /etc/nix/nix.conf
|
|
||||||
- name: Set up secrets
|
- name: Set up secrets
|
||||||
run: |
|
run: |
|
||||||
echo "$NIX_CACHE_KEY" > ~/cache.key
|
echo "$NIX_CACHE_KEY" > ~/cache.key
|
||||||
|
|
3
.github/workflows/update.yml
vendored
3
.github/workflows/update.yml
vendored
|
@ -17,11 +17,10 @@ jobs:
|
||||||
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||||
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixcache:8KKuGz95Pk4UJ5W/Ni+pN+v+LDTkMMFV4yrGmAYgkDg= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=
|
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nixcache:8KKuGz95Pk4UJ5W/Ni+pN+v+LDTkMMFV4yrGmAYgkDg= hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=
|
||||||
experimental-features = nix-command flakes ca-derivations
|
experimental-features = nix-command flakes ca-derivations
|
||||||
|
post-build-hook = ${{ github.workspace }}/scripts/post-build-hook
|
||||||
substituters = https://cache.chir.rs/
|
substituters = https://cache.chir.rs/
|
||||||
- name: Download patched nix
|
- name: Download patched nix
|
||||||
run: nix build github:DarkKirb/nix-packages#nix-s3-dedup
|
run: nix build github:DarkKirb/nix-packages#nix-s3-dedup
|
||||||
- name: Setup post-build-hook
|
|
||||||
run: echo "post-build-hook = ${{ github.workspace }}/scripts/post-build-hook" | sudo tee -a /etc/nix/nix.conf
|
|
||||||
- name: Set up secrets
|
- name: Set up secrets
|
||||||
run: |
|
run: |
|
||||||
echo "$NIX_CACHE_KEY" > ~/cache.key
|
echo "$NIX_CACHE_KEY" > ~/cache.key
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
{
|
{
|
||||||
python3,
|
python3,
|
||||||
boto3,
|
boto3,
|
||||||
|
aiohttp,
|
||||||
stdenvNoCC,
|
stdenvNoCC,
|
||||||
lib,
|
lib,
|
||||||
}: let
|
}: let
|
||||||
clean-s3-cache-env = python3.buildEnv.override {
|
clean-s3-cache-env = python3.buildEnv.override {
|
||||||
extraLibs = [boto3];
|
extraLibs = [boto3 aiohttp];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
stdenvNoCC.mkDerivation {
|
stdenvNoCC.mkDerivation {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import json
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
from botocore.response import StreamingBody
|
from botocore.response import StreamingBody
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
ENDPOINT_URL: str = "https://s3.us-west-000.backblazeb2.com"
|
ENDPOINT_URL: str = "https://s3.us-west-000.backblazeb2.com"
|
||||||
BUCKET_NAME: str = "cache-chir-rs"
|
BUCKET_NAME: str = "cache-chir-rs"
|
||||||
|
@ -143,15 +144,27 @@ def get_store_hashes() -> set[str]:
|
||||||
return hashes
|
return hashes
|
||||||
|
|
||||||
|
|
||||||
|
async def is_in_nixos_cache(client: aiohttp.ClientSession, narinfo: str) -> bool:
|
||||||
|
async with client.get(f"https://cache.nixos.org/{narinfo}"):
|
||||||
|
if response.status == 200:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
nars_to_delete = set()
|
nars_to_delete = set()
|
||||||
nars_to_keep = set()
|
nars_to_keep = set()
|
||||||
|
async with aiohttp.ClientSession() as client:
|
||||||
async for obj_key in list_cache_objects():
|
async for obj_key in list_cache_objects():
|
||||||
if obj_key.endswith(".narinfo"):
|
if obj_key.endswith(".narinfo"):
|
||||||
# check if we have the hash locally
|
# check if we have the hash locally
|
||||||
narinfo = await get_object(obj_key)
|
narinfo = await get_object(obj_key)
|
||||||
narinfo = NarInfo(narinfo)
|
narinfo = NarInfo(narinfo)
|
||||||
if not await narinfo.exists_locally():
|
# check if cache.nixos.org has the narinfo
|
||||||
|
if await is_in_nixos_cache(client, obj_key):
|
||||||
|
print(f"Found duplicated NAR for {narinfo.store_path}")
|
||||||
|
await delete_object(obj_key)
|
||||||
|
nars_to_delete.add(narinfo.url)
|
||||||
|
elif not await narinfo.exists_locally():
|
||||||
print(f"Found unused NAR for {narinfo.store_path}")
|
print(f"Found unused NAR for {narinfo.store_path}")
|
||||||
await delete_object(obj_key)
|
await delete_object(obj_key)
|
||||||
nars_to_delete.add(narinfo.url)
|
nars_to_delete.add(narinfo.url)
|
||||||
|
|
Reference in a new issue