From 3781696316a200a886924b136b50e6c12f845ec9 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 24 Mar 2023 16:46:31 +0100 Subject: [PATCH] working garbage collector --- hcl/builder.hcl | 32 ++++++++++++++++++++++++++++++++ hcl/pin.sh | 7 ++++++- main.go | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hcl/builder.hcl b/hcl/builder.hcl index 3b1252e..9d541a0 100644 --- a/hcl/builder.hcl +++ b/hcl/builder.hcl @@ -125,6 +125,38 @@ job "builder" { memory = 4000 } } + task "garbage-collect-cache" { + driver = "docker" + config { + image = "nixpkgs/nix:nixos-22.11" + args = [ "/tmp/gc.sh" ] + volumes = [ + "local/gc.sh:/tmp/gc.sh", + "local/nix.conf:/etc/nix/nix.conf", + "/var/cache/albatros/nix:/nix", + ] + } + + lifecycle { + hook = "poststop" + sidecar = false + } + + template { + data = file("./nix.conf") + destination = "local/nix.conf" + } + + template { + data = file("./gc.sh") + destination = "local/gc.sh" + perms = "555" + } + + restart { + attempts = 0 + } + } } } diff --git a/hcl/pin.sh b/hcl/pin.sh index eca04cb..085186f 100644 --- a/hcl/pin.sh +++ b/hcl/pin.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash set -euxo pipefail +set -f # disable globbing -echo "hook on $DRV_PATH" +mkdir -p /nix/var/nix/gcroots/albatros +DRV_NAME=$(echo $DRV_PATH | cut -d '/' -f 4) +GCROOT=/nix/var/nix/gcroots/albatros/$DRV_NAME +rm -f $GCROOT +ln -s $DRV_PATH $GCROOT diff --git a/main.go b/main.go index a0e3486..5f30691 100644 --- a/main.go +++ b/main.go @@ -413,7 +413,7 @@ func main() { http.HandleFunc("/build", build) // launch - log.Println("Listen on :8080") + log.Println("Albatros listen on :8080") if err = http.ListenAndServe(":8080", nil); err != nil { log.Fatal("Can't start HTTP server") }