lol
0
fork

Configure Feed

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

nix-prefetch-pijul: init

+146
+137
pkgs/build-support/fetchpijul/nix-prefetch-pijul
··· 1 + #!/bin/sh 2 + set -eu 3 + 4 + name="fetchpijul" 5 + remote= 6 + channel="main" 7 + change= 8 + state= 9 + exp_hash= 10 + 11 + usage() { 12 + echo "Usage: nix-prefetch-pijul [options] [REMOTE] [STATE [EXPECTED-HASH]]" 13 + echo 14 + echo "Options:" 15 + echo " --name <NAME> Symbolic store path name to use for the result." 16 + echo " --remote <REMOTE> URL for the Pijul repository." 17 + echo " --change <CHANGE> Clone a specific change." 18 + echo " --state <STATE> Clone a specific state." 19 + echo " --channel <CHANNEL> Channel name (default: ‘main’)." 20 + echo " --hash <HASH> Expected hash." 21 + echo " --help Show this help message." 22 + } 23 + 24 + # Argument parsing 25 + while [ $# -gt 0 ]; do 26 + case "$1" in 27 + --name) 28 + name="$2"; shift 2 ;; 29 + --remote) 30 + remote="$2"; shift 2 ;; 31 + --channel) 32 + channel="$2"; shift 2 ;; 33 + --change) 34 + change="$2"; shift 2 ;; 35 + --state) 36 + state="$2"; shift 2 ;; 37 + --hash) 38 + exp_hash="$2"; shift 2 ;; 39 + --help) 40 + usage; exit 0 ;; 41 + *) 42 + # Positional arguments 43 + if [ -z "$remote" ]; then 44 + remote="$1" 45 + shift 46 + elif [ -z "$state" ]; then 47 + state="$1" 48 + shift 49 + elif [ -z "$exp_hash" ]; then 50 + exp_hash="$1" 51 + shift 52 + else 53 + echo "Error: Too many arguments" >&2 54 + usage 55 + exit 1 56 + fi 57 + ;; 58 + esac 59 + done 60 + 61 + if [ -z "$remote" ]; then 62 + echo "Error: URL for remote is required." >&2 63 + echo >&2 64 + usage 65 + exit 1 66 + elif [ -n "$change" -a -n "$state" ]; then 67 + echo "Error: Only one of ‘change’ or ‘state’ can be set" >&2 68 + echo >&2 69 + usage 70 + exit 1 71 + fi 72 + 73 + hash= 74 + hash_algo="${NIX_HASH_ALGO:-"sha256"}" 75 + hash_format="${hashFormat:-"--base32"}" 76 + final_path= 77 + 78 + # If the hash was given, a file with that hash may already be in the 79 + # store. 80 + if [ -n "$exp_hash" ]; then 81 + final_path=$(nix-store --print-fixed-path --recursive "$hash_algo" "$exp_hash" "$name") 82 + if ! nix-store --check-validity "$final_path" 2> /dev/null; then 83 + final_path="" 84 + fi 85 + hash="$exp_hash" 86 + fi 87 + 88 + # If we don’t know the hash or a path with that hash doesn’t exist, 89 + # download the file and add it to the store. 90 + if [ -z "$final_path" ]; then 91 + tmp_clone="$(realpath "$(mktemp -d --tmpdir pijul-clone-tmp-XXXXXXXX)")" 92 + trap "rm -rf \"$tmp_clone\"" EXIT 93 + 94 + clone_args="--channel $channel" 95 + if [ -n "$change" ]; then 96 + clone_args="$clone_args --change $change" 97 + elif [ -n "$state" ]; then 98 + clone_args="$clone_args --state $state" 99 + fi 100 + 101 + cd "$tmp_clone" 102 + pijul clone $clone_args "$remote" "$name" 103 + rm -rf "$tmp_clone/$name/.pijul" 104 + 105 + hash="$(nix-hash --type "$hash_algo" "$hash_format" "$tmp_clone/$name")" 106 + final_path=$(nix-store --add-fixed --recursive "$hash_algo" "$tmp_clone/$name") 107 + 108 + if [ -n "$exp_hash" -a "$exp_hash" != "$hash" ]; then 109 + echo "Hash mismatch for “$remote” @ “$channel”" >&2 110 + echo "Expected: $exp_hash" >&2 111 + echo "Got: $hash" >&2 112 + exit 1 113 + fi 114 + fi 115 + 116 + json_escape() { 117 + printf '%s' "$1" | jq -Rs . 118 + } 119 + 120 + cat <<EOF 121 + { 122 + "remote": $(json_escape "$remote"), 123 + "channel": $(json_escape "$channel"), 124 + EOF 125 + if [ -n "$change" ]; then cat <<EOF 126 + "change": "$(json_escape "$change")", 127 + EOF 128 + elif [ -n "$state" ]; then cat <<EOF 129 + "state": "$(json_escape "$state")", 130 + EOF 131 + fi; cat <<EOF 132 + "path": "$final_path", 133 + $(json_escape "$hash_algo"): $(json_escape "$hash"), 134 + "hash": "$(nix-hash --to-sri --type "$hash_algo" "$hash")" 135 + } 136 + EOF 137 + # vim: noet ci pi sts=0
+9
pkgs/tools/package-management/nix-prefetch-scripts/default.nix
··· 5 5 buildEnv, 6 6 bash, 7 7 breezy, 8 + cacert, 8 9 coreutils, 9 10 cvs, 10 11 findutils, ··· 12 13 git, 13 14 git-lfs, 14 15 gnused, 16 + jq, 15 17 mercurial, 18 + pijul, 16 19 subversion, 17 20 }: 18 21 ··· 73 76 nix-prefetch-svn = mkPrefetchScript "svn" ../../../build-support/fetchsvn/nix-prefetch-svn [ 74 77 subversion 75 78 ]; 79 + nix-prefetch-pijul = mkPrefetchScript "pijul" ../../../build-support/fetchpijul/nix-prefetch-pijul [ 80 + pijul 81 + cacert 82 + jq 83 + ]; 76 84 77 85 nix-prefetch-scripts = buildEnv { 78 86 name = "nix-prefetch-scripts"; ··· 83 91 nix-prefetch-git 84 92 nix-prefetch-hg 85 93 nix-prefetch-svn 94 + nix-prefetch-pijul 86 95 ]; 87 96 88 97 meta = with lib; {