Skip to content

Instantly share code, notes, and snippets.

@Lillecarl
Created August 12, 2024 05:26
Show Gist options
  • Save Lillecarl/0101538c00bf9328cf04927a20f50db7 to your computer and use it in GitHub Desktop.
Save Lillecarl/0101538c00bf9328cf04927a20f50db7 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
# We need $FLAKE for our impurity
export FLAKE=$PWD
# Save $FLAKE to a file
echo "\"$FLAKE\"" > "$FLAKE/.flakepath"
dotenv_if_exists /run/user/1000/agenix/cloudflare
watch_file .nix
PATH_add "$FLAKE/bin"
# Cache PATH from nix develop for one hour
if ! has fd || ! fd --type l --no-ignore --max-depth 1 --hidden --quiet --changed-within 1h .nix
then
if ! systemctl \
is-active \
--user \
--quiet \
repofarm
then
echo "Building repoenv"
export DIRENV_FINISHED="n"
systemd-run \
--user \
--quiet \
"--setenv=FISH_PID=$FISH_PID" \
--unit repofarm \
"$FLAKE/bin/build-repofarm"
fi
else
export DIRENV_FINISHED="y"
echo "Using cached repoenv"
fi
PATH_add "$FLAKE/.nix/bin"
#! /usr/bin/env bash
nix \
build \
"$FLAKE#repofarm" \
--out-link "$FLAKE/.nix" || exit 1
echo "Sending SIGUSR1 to fish shell ($FISH_PID) to reload direnv"
kill -USR1 "$FISH_PID"
nix flake archive "$FLAKE"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment