Configuration for my NixOS based systems and Home Manager
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add scripts to automatically update overlays

+393
+112
overlays/scripts/lib/update-overlay-common.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + usage_common() { 4 + local script_name="$1" 5 + cat <<EOF 6 + Usage: $script_name [--check] [--dry-run] 7 + 8 + Options: 9 + --check Report whether an update is available without prefetching hashes. 10 + Exits 1 when the overlay is outdated. 11 + --dry-run Prefetch hashes and print what would change without editing files. 12 + -h, --help Show this help. 13 + EOF 14 + } 15 + 16 + init_overlay_update() { 17 + repo_root="$(cd "$(dirname "${BASH_SOURCE[1]}")/.." && pwd)" 18 + cd "$repo_root" 19 + 20 + mode=update 21 + while (($#)); do 22 + case "$1" in 23 + --check) 24 + mode=check 25 + ;; 26 + --dry-run) 27 + mode=dry-run 28 + ;; 29 + -h | --help) 30 + usage_common "$(basename "${BASH_SOURCE[1]}")" 31 + exit 0 32 + ;; 33 + *) 34 + echo "error: unknown argument: $1" >&2 35 + usage_common "$(basename "${BASH_SOURCE[1]}")" >&2 36 + exit 2 37 + ;; 38 + esac 39 + shift 40 + done 41 + } 42 + 43 + require() { 44 + local cmd="$1" 45 + command -v "$cmd" >/dev/null 2>&1 || { 46 + echo "error: required command not found: $cmd" >&2 47 + exit 127 48 + } 49 + } 50 + 51 + version_gt() { 52 + local newest 53 + newest="$(printf '%s\n%s\n' "$1" "$2" | sort -V | tail -n1)" 54 + [[ "$newest" == "$1" && "$1" != "$2" ]] 55 + } 56 + 57 + replace_literal() { 58 + local file="$1" 59 + local old="$2" 60 + local new="$3" 61 + 62 + if [[ "$mode" == dry-run ]]; then 63 + echo " would replace: $old" 64 + echo " with: $new" 65 + return 0 66 + fi 67 + 68 + OLD="$old" NEW="$new" perl -0pi -e 's/\Q$ENV{OLD}\E/$ENV{NEW}/g' "$file" 69 + } 70 + 71 + prefetch_url_hash() { 72 + local url="$1" 73 + local unpack="${2:-false}" 74 + local hash 75 + 76 + if [[ "$unpack" == true ]]; then 77 + hash="$(nix-prefetch-url --unpack "$url")" 78 + else 79 + hash="$(nix-prefetch-url "$url")" 80 + fi 81 + 82 + nix hash convert --hash-algo sha256 --to sri "$hash" 83 + } 84 + 85 + github_latest_stable_version() { 86 + local owner="$1" 87 + local repo="$2" 88 + local prefix="$3" 89 + 90 + curl -fsSL "https://api.github.com/repos/$owner/$repo/tags?per_page=100" \ 91 + | jq -r '.[].name' \ 92 + | sed -nE "s/^${prefix}([0-9]+(\.[0-9]+)+)$/\\1/p" \ 93 + | sort -V \ 94 + | tail -n1 95 + } 96 + 97 + finish_overlay_update() { 98 + local name="$1" 99 + local outdated="$2" 100 + 101 + if [[ "$mode" == check && "$outdated" -eq 1 ]]; then 102 + exit 1 103 + fi 104 + 105 + if [[ "$outdated" -eq 0 ]]; then 106 + echo "$name: current" 107 + elif [[ "$mode" == dry-run ]]; then 108 + echo "$name: dry run complete; no files changed." 109 + else 110 + echo "$name: update complete." 111 + fi 112 + }
+79
overlays/scripts/update-codex-overlay
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/update-overlay-common.sh" 5 + init_overlay_update "$@" 6 + 7 + require curl 8 + require jq 9 + require nix 10 + require nix-prefetch-url 11 + require perl 12 + require sed 13 + require sort 14 + 15 + name=codex 16 + file=overlays/codex.nix 17 + current="$(sed -nE 's/^[[:space:]]*version = "([^"]+)";/\1/p' "$file")" 18 + latest="$(github_latest_stable_version openai codex rust-v)" 19 + 20 + if [[ -z "$latest" ]]; then 21 + echo "$name: could not determine latest version" >&2 22 + exit 1 23 + fi 24 + 25 + if ! version_gt "$latest" "$current"; then 26 + finish_overlay_update "$name" 0 27 + exit 0 28 + fi 29 + 30 + echo "$name: $current -> $latest" 31 + if [[ "$mode" == check ]]; then 32 + finish_overlay_update "$name" 1 33 + exit 1 34 + fi 35 + 36 + old_src_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file" | sed -n '1p')" 37 + old_cargo_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file" | sed -n '2p')" 38 + new_src_hash="$(prefetch_url_hash "https://github.com/openai/codex/archive/refs/tags/rust-v$latest.tar.gz" true)" 39 + 40 + expr=$(cat <<EOF 41 + let 42 + flake = builtins.getFlake (toString ./.); 43 + system = builtins.currentSystem; 44 + pkgs = import flake.inputs.nixpkgs-unstable { inherit system; }; 45 + src = pkgs.fetchFromGitHub { 46 + owner = "openai"; 47 + repo = "codex"; 48 + tag = "rust-v$latest"; 49 + hash = "$new_src_hash"; 50 + }; 51 + in 52 + pkgs.rustPlatform.fetchCargoVendor { 53 + inherit src; 54 + sourceRoot = "\${src.name}/codex-rs"; 55 + hash = pkgs.lib.fakeHash; 56 + } 57 + EOF 58 + ) 59 + 60 + set +e 61 + output="$(nix build --no-link --impure --expr "$expr" 2>&1)" 62 + status=$? 63 + set -e 64 + 65 + if [[ $status -eq 0 ]]; then 66 + echo "$name: cargo vendor prefetch unexpectedly succeeded with a fake hash" >&2 67 + exit 1 68 + fi 69 + 70 + new_cargo_hash="$(sed -nE 's/.*got:[[:space:]]*(sha256-[^[:space:]]+).*/\1/p' <<<"$output" | tail -n1)" 71 + if [[ -z "$new_cargo_hash" ]]; then 72 + echo "$name: could not prefetch cargo vendor hash" >&2 73 + exit 1 74 + fi 75 + 76 + replace_literal "$file" "version = \"$current\";" "version = \"$latest\";" 77 + replace_literal "$file" "$old_src_hash" "$new_src_hash" 78 + replace_literal "$file" "$old_cargo_hash" "$new_cargo_hash" 79 + finish_overlay_update "$name" 1
+44
overlays/scripts/update-inetutils-overlay
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/update-overlay-common.sh" 5 + init_overlay_update "$@" 6 + 7 + require curl 8 + require nix 9 + require nix-prefetch-url 10 + require perl 11 + require sed 12 + require sort 13 + 14 + name=inetutils 15 + file=overlays/inetutils.nix 16 + current="$(sed -nE 's/^[[:space:]]*version = "([^"]+)";/\1/p' "$file")" 17 + latest="$(curl -fsSL https://ftp.gnu.org/gnu/inetutils/ \ 18 + | grep -oE 'inetutils-[0-9][0-9.]*\.tar\.xz' \ 19 + | sed -E 's/inetutils-([0-9.]+)\.tar\.xz/\1/' \ 20 + | sort -V \ 21 + | tail -n1)" 22 + 23 + if [[ -z "$latest" ]]; then 24 + echo "$name: could not determine latest version" >&2 25 + exit 1 26 + fi 27 + 28 + if ! version_gt "$latest" "$current"; then 29 + finish_overlay_update "$name" 0 30 + exit 0 31 + fi 32 + 33 + echo "$name: $current -> $latest" 34 + if [[ "$mode" == check ]]; then 35 + finish_overlay_update "$name" 1 36 + exit 1 37 + fi 38 + 39 + old_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file")" 40 + new_hash="$(prefetch_url_hash "https://ftp.gnu.org/gnu/inetutils/inetutils-$latest.tar.xz")" 41 + 42 + replace_literal "$file" "version = \"$current\";" "version = \"$latest\";" 43 + replace_literal "$file" "$old_hash" "$new_hash" 44 + finish_overlay_update "$name" 1
+51
overlays/scripts/update-lmstudio-overlay
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/update-overlay-common.sh" 5 + init_overlay_update "$@" 6 + 7 + require curl 8 + require nix 9 + require nix-prefetch-url 10 + require perl 11 + require sed 12 + require sort 13 + 14 + name=lmstudio 15 + file=overlays/lmstudio.nix 16 + current="$(sed -nE 's/.*lmstudioVersion \? "([^"]+)".*/\1/p' "$file")" 17 + page="$(curl -fsSL 'https://lmstudio.ai/downloads?os=linux')" 18 + latest_data="$(PAGE="$page" perl -e ' 19 + my $page = $ENV{PAGE}; 20 + if ($page =~ /"linux":\{"x64":\{"version":"([^"]+)","build":"([^"]+)"/s) { 21 + print "$1 $2\n"; 22 + } elsif ($page =~ /\\"linux\\":\{\\"x64\\":\{\\"version\\":\\"([^"\\]+)\\",\\"build\\":\\"([^"\\]+)\\"/s) { 23 + print "$1 $2\n"; 24 + } 25 + ')" 26 + read -r latest_version latest_build <<<"$latest_data" 27 + 28 + if [[ -z "$latest_version" || -z "$latest_build" ]]; then 29 + echo "$name: could not determine latest version" >&2 30 + exit 1 31 + fi 32 + 33 + latest="$latest_version-$latest_build" 34 + if ! version_gt "$latest" "$current"; then 35 + finish_overlay_update "$name" 0 36 + exit 0 37 + fi 38 + 39 + echo "$name: $current -> $latest" 40 + if [[ "$mode" == check ]]; then 41 + finish_overlay_update "$name" 1 42 + exit 1 43 + fi 44 + 45 + old_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file")" 46 + url="https://installers.lmstudio.ai/linux/x64/$latest/LM-Studio-$latest-x64.AppImage" 47 + new_hash="$(prefetch_url_hash "$url")" 48 + 49 + replace_literal "$file" "lmstudioVersion ? \"$current\"" "lmstudioVersion ? \"$latest\"" 50 + replace_literal "$file" "$old_hash" "$new_hash" 51 + finish_overlay_update "$name" 1
+41
overlays/scripts/update-neovim-overlay
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/update-overlay-common.sh" 5 + init_overlay_update "$@" 6 + 7 + require curl 8 + require jq 9 + require nix 10 + require nix-prefetch-url 11 + require perl 12 + require sed 13 + require sort 14 + 15 + name=neovim 16 + file=overlays/neovim.nix 17 + current="$(sed -nE 's/^[[:space:]]*version = "([^"]+)";/\1/p' "$file")" 18 + latest="$(github_latest_stable_version neovim neovim v)" 19 + 20 + if [[ -z "$latest" ]]; then 21 + echo "$name: could not determine latest version" >&2 22 + exit 1 23 + fi 24 + 25 + if ! version_gt "$latest" "$current"; then 26 + finish_overlay_update "$name" 0 27 + exit 0 28 + fi 29 + 30 + echo "$name: $current -> $latest" 31 + if [[ "$mode" == check ]]; then 32 + finish_overlay_update "$name" 1 33 + exit 1 34 + fi 35 + 36 + old_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file")" 37 + new_hash="$(prefetch_url_hash "https://github.com/neovim/neovim/archive/refs/tags/v$latest.tar.gz" true)" 38 + 39 + replace_literal "$file" "version = \"$current\";" "version = \"$latest\";" 40 + replace_literal "$file" "$old_hash" "$new_hash" 41 + finish_overlay_update "$name" 1
+66
overlays/scripts/update-nixery-overlay
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/update-overlay-common.sh" 5 + init_overlay_update "$@" 6 + 7 + require git 8 + require nix 9 + require perl 10 + require sed 11 + 12 + name=nixery 13 + file=overlays/nixery.nix 14 + current="$(sed -nE 's/^[[:space:]]*rev = "([^"]+)";/\1/p' "$file")" 15 + latest="$(git ls-remote https://code.tvl.fyi/depot.git HEAD | sed -nE 's/^([0-9a-f]+)[[:space:]]+HEAD$/\1/p')" 16 + 17 + if [[ -z "$latest" ]]; then 18 + echo "$name: could not determine latest revision" >&2 19 + exit 1 20 + fi 21 + 22 + if [[ "$latest" == "$current" ]]; then 23 + finish_overlay_update "$name" 0 24 + exit 0 25 + fi 26 + 27 + echo "$name: ${current:0:12} -> ${latest:0:12}" 28 + if [[ "$mode" == check ]]; then 29 + finish_overlay_update "$name" 1 30 + exit 1 31 + fi 32 + 33 + old_hash="$(sed -nE 's/^[[:space:]]*hash = "([^"]+)";/\1/p' "$file")" 34 + expr=$(cat <<EOF 35 + let 36 + flake = builtins.getFlake (toString ./.); 37 + system = builtins.currentSystem; 38 + pkgs = import flake.inputs.nixpkgs { inherit system; }; 39 + in 40 + pkgs.fetchgit { 41 + url = "https://code.tvl.fyi/depot.git:/tools/nixery.git"; 42 + rev = "$latest"; 43 + hash = pkgs.lib.fakeHash; 44 + } 45 + EOF 46 + ) 47 + 48 + set +e 49 + output="$(nix build --no-link --impure --expr "$expr" 2>&1)" 50 + status=$? 51 + set -e 52 + 53 + if [[ $status -eq 0 ]]; then 54 + echo "$name: fetchgit prefetch unexpectedly succeeded with a fake hash" >&2 55 + exit 1 56 + fi 57 + 58 + new_hash="$(sed -nE 's/.*got:[[:space:]]*(sha256-[^[:space:]]+).*/\1/p' <<<"$output" | tail -n1)" 59 + if [[ -z "$new_hash" ]]; then 60 + echo "$name: could not prefetch new hash" >&2 61 + exit 1 62 + fi 63 + 64 + replace_literal "$file" "rev = \"$current\";" "rev = \"$latest\";" 65 + replace_literal "$file" "$old_hash" "$new_hash" 66 + finish_overlay_update "$name" 1