From 828a7c22bd4b1ccba370aa67cd908bca28364854 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Mon, 20 May 2024 14:21:13 +0200 Subject: [PATCH] loki: Add post-build-hook to automatically upload matching packages --- machines/loki/configuration.nix | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/machines/loki/configuration.nix b/machines/loki/configuration.nix index 72c4f45..1921d2b 100644 --- a/machines/loki/configuration.nix +++ b/machines/loki/configuration.nix @@ -1,4 +1,9 @@ -{ nixos-hardware, nix-ld-rs, ... }: +{ + nixos-hardware, + nix-ld-rs, + attic, + ... +}: { pkgs, config, ... }: { imports = [ @@ -488,19 +493,24 @@ ]; }; - # nix.settings.post-build-hook = - # let - # inherit (attic.packages.${pkgs.system}) attic-client; - # in - # pkgs.writeScript "upload-to-cache" '' - # set -eu - # set -f - # export IFS=' ' + nix.settings.post-build-hook = + let + inherit (attic.packages.${pkgs.system}) attic-client; + cachedPackagePatterns = builtins.concatStringsSep "|" [ "mongodb" ]; + in + pkgs.writeScript "upload-to-cache" '' + set -eu + set -f + export IFS=' ' - # OUT_PATHS=$(echo -n ''${OUT_PATHS} | ${pkgs.gawk}/bin/awk 'BEGIN { RS = " "; ORS = " "; } $0 !~ /horus_vcpkg/ { print $0 }') - # echo "Uploading paths to cache " ''${OUT_PATHS} - # exec ${attic-client}/bin/attic push main ''${OUT_PATHS} - # ''; + OUT_PATHS=$(echo -n ''${OUT_PATHS} | ${pkgs.gawk}/bin/awk 'BEGIN { RS = " "; ORS = " "; } $0 ~ /(${cachedPackagePatterns})/ { print $0 }') + if [[ -z "''${OUT_PATHS}" ]]; then + echo "No matching packages to upload" + exit 0 + fi + echo "Uploading paths to cache " ''${OUT_PATHS} + exec ${attic-client}/bin/attic push main ''${OUT_PATHS} + ''; sops.defaultSopsFile = ./secrets.yaml; sops.secrets = {