From 8e5263b5d5895956978dcc343c26eaba4eae7b01 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Wed, 23 Apr 2025 12:14:27 +0200 Subject: [PATCH] lkjasd --- .envrc | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/.envrc b/.envrc index 27c5929..fb22990 100644 --- a/.envrc +++ b/.envrc @@ -45,30 +45,32 @@ if [[ ! -s .direnv/pull-date || "$now" != "$(cat .direnv/pull-date)" ]]; then direnv allow # :3 # nix flake update - declare -a update_args=() - readarray -td $'\n' update_args < <( - nix eval --file flake.nix --apply 'x: builtins.attrNames x.inputs' --json \ - | jq .[] -r \ - | grep -v '^nixpkgs-expensive$' + ! declare -F update_flake >&/dev/null || ! echo >&2 "ERROR: update_flake() already declared!" + update_flake() ( + set -euo pipefail + declare -a update_args=() + readarray -td $'\n' update_args <<<"$( + nix eval --file flake.nix --apply 'x: builtins.attrNames x.inputs' --json | + jq '.[]' -r | + grep -v '^nixpkgs-expensive$' + )" + # update_args+=(--output-lock-file "$tmp"/new-flake.lock) + set -x + nix flake update "${update_args[@]}" || + nix flake update "${update_args[@]}" --option access-tokens "" ) - # update_args+=(--output-lock-file "$tmp"/new-flake.lock) if command -v pueue >/dev/null && pueue status >&/dev/null; then - nix flake update "${update_args[@]}" + # update and build shell in background + echo >&2 "+ pueue add --immediate nix flake update ..." + pueue add --immediate "$(declare -f update_flake); update_flake \"\$@\"; set -x; nix print-dev-env \"$flake_shell\" >/dev/null" else - ( - echo >&2 "+ pueue add --escape --immediate nix flake update ..." - task_id=$( - pueue add --print-task-id --escape --immediate nix flake update "${update_args[@]}" \ - | tee >(xargs -d'\n' printf >&2 "New task added (id %s).\n") - ) - (set -x - pueue add --after="$task_id" --escape nix print-dev-env "$flake_shell" - ) - ) + # update while blocking + update_flake fi - unset update_args + unset -f update_flake - printf "%s\n" "$now" > .direnv/pull-date + # TODO: move to pueue job? + printf "%s\n" "$now" >.direnv/pull-date fi # source env