From 95913748383812ef6c47900ace3ac1d14b001f35 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 24 Mar 2023 17:04:19 +0100 Subject: [PATCH] refactor --- README.md | 21 +++++++-------------- {example => consul}/albatros.json | 0 {example => consul}/gitea.json | 0 hcl/{ => nixcache}/builder.hcl | 0 hcl/{ => nixcache}/gc.sh | 0 hcl/{ => nixcache}/nix.conf | 0 hcl/{ => nixcache}/pin.sh | 0 hcl/{ => nixcache}/user.sh | 0 hcl/{ => nixcache}/warmup.sh | 0 9 files changed, 7 insertions(+), 14 deletions(-) rename {example => consul}/albatros.json (100%) rename {example => consul}/gitea.json (100%) rename hcl/{ => nixcache}/builder.hcl (100%) rename hcl/{ => nixcache}/gc.sh (100%) rename hcl/{ => nixcache}/nix.conf (100%) rename hcl/{ => nixcache}/pin.sh (100%) rename hcl/{ => nixcache}/user.sh (100%) rename hcl/{ => nixcache}/warmup.sh (100%) diff --git a/README.md b/README.md index 0ebe834..19e415c 100644 --- a/README.md +++ b/README.md @@ -59,20 +59,13 @@ And... that's basically all you need. ### A NixOS builder with local cache -The nix builder will create a local cache on your node agent at `/var/cache/albatros`. -It will create two folders: `/var/cache/albatros/nix` that contains a nix store, -and `/var/cache/albatros/cacheroot` that contains nix roots, ie. the builds we must keep. - -Caching is handled thanks to these roots: roots that are older than 7 days will be removed, -then a garbage collection will be triggered, and their associate content will be deleted. - -To keep your cache between builds, you must put your outlink in `/mnt/cacheroot` with a unique name. -The git commit is a good candidate: - -```bash -# create an output link at a persisted path -nix build --out-link $GCROOT -``` +In the `hcl/` folder, you will find the definition of a builder named `nixcache`. +This builder has the following features: + - It creates a persisted nix store at `/var/cache/albatros` on your host if it does not exist yet. + - The nix store is mounted read-only during the build + - A nix daemon is run in a separate container, you can interact with it though its unix socket (everything is already setup for you). Simply run `nix build`. + - All your builds are automatically added as a nix gcroots by the nix daemon, `keep_derivation` is activated so your build dependencies are kept locally. + - At the end, all gcroots older than 7 days are deleted, and then the `nix store gc` is called effectively wiping data that were previously attached to old gcroots. ## Register a build diff --git a/example/albatros.json b/consul/albatros.json similarity index 100% rename from example/albatros.json rename to consul/albatros.json diff --git a/example/gitea.json b/consul/gitea.json similarity index 100% rename from example/gitea.json rename to consul/gitea.json diff --git a/hcl/builder.hcl b/hcl/nixcache/builder.hcl similarity index 100% rename from hcl/builder.hcl rename to hcl/nixcache/builder.hcl diff --git a/hcl/gc.sh b/hcl/nixcache/gc.sh similarity index 100% rename from hcl/gc.sh rename to hcl/nixcache/gc.sh diff --git a/hcl/nix.conf b/hcl/nixcache/nix.conf similarity index 100% rename from hcl/nix.conf rename to hcl/nixcache/nix.conf diff --git a/hcl/pin.sh b/hcl/nixcache/pin.sh similarity index 100% rename from hcl/pin.sh rename to hcl/nixcache/pin.sh diff --git a/hcl/user.sh b/hcl/nixcache/user.sh similarity index 100% rename from hcl/user.sh rename to hcl/nixcache/user.sh diff --git a/hcl/warmup.sh b/hcl/nixcache/warmup.sh similarity index 100% rename from hcl/warmup.sh rename to hcl/nixcache/warmup.sh