mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 02:00:13 +01:00
feat: improve caching
This commit is contained in:
parent
a2a7f7c4ed
commit
78e6c5e278
4 changed files with 149 additions and 47 deletions
46
flake.nix
46
flake.nix
|
|
@ -53,7 +53,10 @@
|
|||
# wait an hour so the image builds
|
||||
when = "delayed";
|
||||
start_in = "1 hour";
|
||||
deps = [pkgs.hello pkgs.curl];
|
||||
nix = {
|
||||
deps = [pkgs.hello pkgs.curl];
|
||||
disable-cache = false;
|
||||
};
|
||||
variables = {
|
||||
TEST = "test";
|
||||
TEST_WITH_DERIVATION = "${pkgs.hello}/test";
|
||||
|
|
@ -65,7 +68,7 @@
|
|||
];
|
||||
};
|
||||
"test-non-nix" = {
|
||||
nix = false;
|
||||
nix.enable = false;
|
||||
stage = "test";
|
||||
image = "alpine:latest";
|
||||
script = [
|
||||
|
|
@ -80,12 +83,18 @@
|
|||
pkgs.writeShellScriptBin "setup_nix_ci" ''
|
||||
echo -e "\\e[0Ksection_start:`date +%s`:nix_setup[collapsed=true]\\r\\e[0KSetting up Nix CI"
|
||||
nix path-info --all > /tmp/nix-store-before
|
||||
${extra_setup}
|
||||
export NIX_CONF="
|
||||
extra-trusted-public-keys = $NIX_PUBLIC_KEYS \n
|
||||
extra-trusted-substituters = $NIX_SUBSTITUTERS \n
|
||||
extra-substituters = $NIX_SUBSTITUTERS \n
|
||||
$NIX_EXTRA_CONF
|
||||
|
||||
if [ -z "$NIX_CI_DISABLE_CACHE" ]; then
|
||||
${extra_setup}
|
||||
else
|
||||
echo "Caching disabled (NIX_CI_DISABLE_CACHE), skipping cache configuration"
|
||||
fi
|
||||
|
||||
export NIX_CONFIG="
|
||||
extra-trusted-public-keys = $NIX_PUBLIC_KEYS
|
||||
extra-trusted-substituters = $NIX_SUBSTITUTERS
|
||||
extra-substituters = $NIX_SUBSTITUTERS
|
||||
$NIX_EXTRA_CONFIG
|
||||
"
|
||||
echo -e "\\e[0Ksection_end:`date +%s`:nix_setup\\r\\e[0K"
|
||||
${
|
||||
|
|
@ -104,7 +113,14 @@
|
|||
nix path-info --all > /tmp/nix-store-after
|
||||
${pkgs.diffutils}/bin/diff --new-line-format="%L" \
|
||||
--old-line-format="" --unchanged-line-format="" \
|
||||
/tmp/nix-store-before /tmp/nix-store-after | ${push_command}
|
||||
/tmp/nix-store-before /tmp/nix-store-after \
|
||||
| {
|
||||
if [ -z "$NIX_CI_DISABLE_CACHE" ]; then
|
||||
${push_command}
|
||||
else
|
||||
${pkgs.busybox}/bin/wc -l | { read count; echo "Caching disabled, not uploading $count new store entries..."; }
|
||||
fi
|
||||
}
|
||||
echo -e "\\e[0Ksection_end:`date +%s`:cache_push\\r\\e[0K"
|
||||
'';
|
||||
mkImage = extraPackages:
|
||||
|
|
@ -129,13 +145,19 @@
|
|||
};
|
||||
};
|
||||
in {
|
||||
setup-script = setupScript "# extra_setup";
|
||||
setup-script = setupScript "true # extra_setup";
|
||||
finalize-script = finalizeScript "true # push_command";
|
||||
image = mkImage [
|
||||
(setupScript ''
|
||||
echo "No caching configured, to enable caching use the respective container image tag"
|
||||
cachedir="$(pwd)/.nix-cache"
|
||||
echo "Configuring caching with the Runner Cache in $cachedir..."
|
||||
export NIX_SUBSTITUTERS="$NIX_SUBSTITUTERS file://$cachedir?priority=10&trusted=true"
|
||||
'')
|
||||
(finalizeScript ''
|
||||
while read entry; do
|
||||
nix copy --quiet --to "file://$(pwd)/.nix-cache" $entry || true
|
||||
done
|
||||
'')
|
||||
(finalizeScript ''${pkgs.busybox}/bin/wc -l | { read count; echo "No caching configured, not uploading $count new store entries..."; }'')
|
||||
];
|
||||
image-cachix = mkImage [
|
||||
(setupScript ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue