lol

nix-prefetch-darcs: init (#439865)

authored by philiptaron.tngl.sh and committed by

GitHub 3576a325 2eb7334f

+193 -2
+2 -2
pkgs/build-support/fetchdarcs/builder.sh
··· 12 12 tagflags="--context=$context" 13 13 fi 14 14 15 - echo "getting $url $partial ${tagtext} into $out" 15 + echo "Cloning $url $partial ${tagtext} into $out" 16 16 17 - darcs get --lazy $tagflags "$url" "$out" 17 + darcs clone --lazy $tagflags "$url" "$out" 18 18 # remove metadata, because it can change 19 19 rm -rf "$out/_darcs"
+184
pkgs/build-support/fetchdarcs/nix-prefetch-darcs
··· 1 + #!/bin/sh 2 + set -eu 3 + 4 + quiet= 5 + name="fetchdarcs" 6 + repository= 7 + tag= 8 + context= 9 + darcs_hash= 10 + exp_hash= 11 + 12 + usage() { 13 + echo "Usage: nix-prefetch-darcs [options] [REPOSITORY] [FILENAME [EXPECTED-HASH]]" 14 + echo 15 + echo "Options:" 16 + echo " --quiet Suppress most error messages." 17 + echo " --name <NAME> Symbolic store path name to use for the result." 18 + echo " --repo <REPOSITORY> URL for the Darcs repository." 19 + echo " --tag <REGEXP> Clone specified by tag matching a regular expression." 20 + echo " --context <FILENAME> Clone specified by context file." 21 + echo " --darcs-hash <HASH> Clone specified by hash. WARN: hash order is fickle by design." 22 + echo " --hash <HASH> Expected hash." 23 + echo " --help Show this help message." 24 + } 25 + 26 + # Argument parsing 27 + while [ $# -gt 0 ]; do 28 + case "$1" in 29 + --quiet) 30 + quiet=1; shift 1 ;; 31 + --name) 32 + name="$2"; shift 2 ;; 33 + --repository) 34 + repository="$2"; shift 2 ;; 35 + --tag) 36 + tag="$2"; shift 2 ;; 37 + --context) 38 + context="$2"; shift 2 ;; 39 + --darcs-hash) 40 + darcs_hash="$2"; shift 2 ;; 41 + --hash) 42 + exp_hash="$2"; shift 2 ;; 43 + --help) 44 + usage; exit 0 ;; 45 + *) 46 + # Positional arguments 47 + if [ -z "$repository" ]; then 48 + repository="$1" 49 + shift 50 + elif [ -z "$context" ]; then 51 + context="$1" 52 + shift 53 + elif [ -z "$exp_hash" ]; then 54 + exp_hash="$1" 55 + shift 56 + else 57 + echo "Error: Too many arguments" >&2 58 + usage 59 + exit 1 60 + fi 61 + ;; 62 + esac 63 + done 64 + 65 + if [ -z "$repository" ]; then 66 + echo "Error: URL for repository is required." >&2 67 + echo >&2 68 + usage 69 + exit 1 70 + fi 71 + 72 + state_flag_count=0 73 + [ -n "$tag" ] && state_flag_count=$(( state_flag_count + 1 )) 74 + [ -n "$context" ] && state_flag_count=$(( state_flag_count + 1 )) 75 + [ -n "$darcs_hash" ] && state_flag_count=$(( state_flag_count + 1 )) 76 + 77 + if [ "$state_flag_count" -gt 1 ]; then 78 + echo "Error: no more than 1 of --tag, --context, --darcs-hash flags can be set. $state_flag_count were set." >&2 79 + echo >&2 80 + usage 81 + exit 1 82 + elif [ -n "$context" ]; then 83 + if [ ! -s "$context" ]; then 84 + echo "Error: context file must be readable & non-empty @ “$context”" >&2 85 + echo >&2 86 + usage 87 + exit 1 88 + else 89 + context="$(realpath "$context")" 90 + fi 91 + fi 92 + 93 + weak_hash= 94 + hash= 95 + hash_algo="${NIX_HASH_ALGO:-"sha256"}" 96 + hash_format="${hashFormat:-"--base32"}" 97 + final_path= 98 + final_context= 99 + 100 + # If the hash was given, a file with that hash may already be in the 101 + # store. 102 + if [ -n "$exp_hash" ]; then 103 + final_path=$(nix-store --print-fixed-path --recursive "$hash_algo" "$exp_hash" "$name") 104 + if ! nix-store --check-validity "$final_path" 2> /dev/null; then 105 + final_path="" 106 + fi 107 + hash="$exp_hash" 108 + fi 109 + 110 + # If we don’t know the hash or a path with that hash doesn’t exist, 111 + # download the file and add it to the store. 112 + if [ -z "$final_path" ]; then 113 + tmp_clone="$(realpath ${quiet:+--quiet} "$(mktemp ${quiet:+--quiet} -d --tmpdir darcs-clone-tmp-XXXXXXXX)")" 114 + trap "rm -rf \"$tmp_clone\"" EXIT 115 + 116 + clone_args="--lazy" 117 + if [ -n "$quiet" ]; then 118 + clone_args="$clone_args --quiet" 119 + fi 120 + if [ -n "$tag" ]; then 121 + clone_args="$clone_args --tag=$tag" 122 + elif [ -n "$context" ]; then 123 + clone_args="$clone_args --context=$context" 124 + elif [ -n "$darcs_hash" ]; then 125 + clone_args="$clone_args --to-hash=$darcs_hash" 126 + fi 127 + 128 + cd "$tmp_clone" 129 + # Do not print Darcs progress to stdout (else stdout isn’t parsable JSON) 130 + if [ -t 1 ]; then 131 + darcs clone $clone_args "$repository" "$name" >/dev/tty 132 + else 133 + darcs clone $clone_args "$repository" "$name" >/dev/null 134 + fi 135 + cd "$tmp_clone/$name" 136 + # Will put the current Darcs context into the store. 137 + new_context="$tmp_clone/${name}-context.txt" 138 + darcs log --context > "$new_context" 139 + final_context="$(nix-store --add-fixed "$hash_algo" "$new_context")" 140 + # Darcs has a weak hash using the XOR of the patch hashes which is useful 141 + # for other scripts 142 + # https://darcs.net/Internals/Hashes 143 + weak_hash="$(darcs show repo | grep '^ *Weak Hash:' | cut -d: -f2- | tr -d "[:space:]")" 144 + cd - >/dev/null 145 + rm -rf "$tmp_clone/$name/_darcs" 146 + 147 + hash="$(nix-hash --type "$hash_algo" "$hash_format" "$tmp_clone/$name")" 148 + final_path=$(nix-store --add-fixed --recursive "$hash_algo" "$tmp_clone/$name") 149 + 150 + if [ -n "$exp_hash" ] && [ "$exp_hash" != "$hash" ]; then 151 + echo "Hash mismatch for “$repository”" >&2 152 + echo "Expected: $exp_hash" >&2 153 + echo "Got: $hash" >&2 154 + exit 1 155 + fi 156 + fi 157 + 158 + json_escape() { 159 + printf '%s' "$1" | jq -Rs . 160 + } 161 + 162 + cat <<EOF 163 + { 164 + "repository": $(json_escape "$repository"), 165 + EOF 166 + if [ -n "$tag" ]; then cat <<EOF 167 + "tag": "$(json_escape "$tag")", 168 + EOF 169 + elif [ -n "$darcs_hash" ]; then cat <<EOF 170 + "darcs-hash": $(json_escape "$darcs_hash"), 171 + EOF 172 + fi; if [ -n "$weak_hash" ]; then cat <<EOF 173 + "weak-hash": $(json_escape "$weak_hash"), 174 + EOF 175 + fi; if [ -s "$final_context" ]; then cat <<EOF 176 + "context": $(json_escape "$final_context"), 177 + EOF 178 + fi; cat <<EOF 179 + "path": "$final_path", 180 + $(json_escape "$hash_algo"): $(json_escape "$hash"), 181 + "hash": "$(nix-hash --to-sri --type "$hash_algo" "$hash")" 182 + } 183 + EOF 184 + # vim: noet ci pi sts=0
+7
pkgs/tools/package-management/nix-prefetch-scripts/default.nix
··· 8 8 cacert, 9 9 coreutils, 10 10 cvs, 11 + darcs, 11 12 findutils, 12 13 gawk, 13 14 git, ··· 64 65 breezy 65 66 ]; 66 67 nix-prefetch-cvs = mkPrefetchScript "cvs" ../../../build-support/fetchcvs/nix-prefetch-cvs [ cvs ]; 68 + nix-prefetch-darcs = mkPrefetchScript "darcs" ../../../build-support/fetchdarcs/nix-prefetch-darcs [ 69 + darcs 70 + cacert 71 + jq 72 + ]; 67 73 nix-prefetch-git = mkPrefetchScript "git" ../../../build-support/fetchgit/nix-prefetch-git [ 68 74 findutils 69 75 gawk ··· 88 94 paths = [ 89 95 nix-prefetch-bzr 90 96 nix-prefetch-cvs 97 + nix-prefetch-darcs 91 98 nix-prefetch-git 92 99 nix-prefetch-hg 93 100 nix-prefetch-svn