Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nix-portable --version #139

Open
milahu opened this issue Nov 10, 2024 · 0 comments
Open

add nix-portable --version #139

milahu opened this issue Nov 10, 2024 · 0 comments

Comments

@milahu
Copy link

milahu commented Nov 10, 2024

nix-portable --version would be useful for installer scripts

nix-portable-install.sh
#!/usr/bin/env bash

# install or update nix-portable
# https://github.com/DavHau/nix-portable

nix_portable_path="$HOME/bin/nix-portable"

bin_dir="$HOME/bin"

if [ -e "$nix_portable_path" ]; then
  if false; then
    # TODO implement
    version_a=$("$nix_portable_path" --version)
  else
    # workaround for "nix-portable --version"
    declare -A version_of_sha256
    # curl -sL https://github.com/DavHau/nix-portable/releases/download/v012/nix-portable-x86_64 | sha256sum -
    version_of_sha256[b409c55904c909ac3aeda3fb1253319f86a89ddd1ba31a5dec33d4a06414c72a]=v012
    # for v in {11..1}; do v0=$(printf %03d $v); echo $(curl -sL https://github.com/DavHau/nix-portable/releases/download/v$v0/nix-portable | sha256sum - | head -c64) v$v0; done
    version_of_sha256[b3f0c14a5756dd6ed45655aa615a074bc2aa9ff6d14f59c174af925f370d465e]=v011
    version_of_sha256[1249a329e9ef14b8564f92f1321e155baee460d23d4295a86944283b13284487]=v010
    version_of_sha256[e371dc77d8cdb4fefacdd2d8abf9b5ce013bb384a2b37def7b96e8dcb0d77790]=v009
    version_of_sha256[51938dc9a72b8aea08aea85278b90b34d65ad8bdb0e85d9e6fcbff222ca85859]=v008
    version_of_sha256[dd2bf333f906fe7f888ac71ae5bff432e8ba2ed86ef5e2de64792ffca568b07a]=v007
    version_of_sha256[5c105c29b8616d28a8625426e5b49969af4c252ac4338ea30ff1648400a14170]=v006
    version_of_sha256[836df3131f9c0a0d1aeb5b11fd8ef5f0e283c85d6443cf27c737fb31219e49d4]=v005
    version_of_sha256[2c8b37f3e785d1adcd175c966cfdcef2934b50b9d62d3c52f3a38c94ef98d175]=v004
    version_of_sha256[43754dd1be4d4f3e7be47722d87871863673c02c338a8498f7dfcdcbb16438f2]=v003
    version_of_sha256[6de46e2c31d537f1d152a4e5066f91474fa5c392490010397379edc824102e37]=v002
    version_of_sha256[ae3f9fa5ddac83c14eb96303816e8f8ea8c5718faccacd74a3ed1f6a694348d6]=v001
    sha256=$(sha256sum "$nix_portable_path" | head -c64)
    version_a="${version_of_sha256[$sha256]}"
    echo "sha256: $sha256 -> version: $version_a"
  fi
else
  version_a=
  mkdir -p "$(dirname "$nix_portable_path")"
fi

version_b=$(
  curl -s -I https://github.com/DavHau/nix-portable/releases/latest |
  grep -i "^location: " | sed 's|.*releases/tag/||' | tr -d $'\r'
)

if [ "$version_a" = "$version_b" ]; then
  echo "keeping nix-portable $version_a"
  exit
else
  echo "updating nix-portable from $version_a to $version_b"
fi

# append version to filename
nix_portable_version_path="$nix_portable_path.$version_b"

url="https://github.com/DavHau/nix-portable/releases/"
url+="download/$version_b/nix-portable-$(uname -m)"

echo "fetching $url"
echo "writing $nix_portable_version_path"

curl -L "$url" >"$nix_portable_version_path"

chmod +x "$nix_portable_version_path"

ln -s -f "$nix_portable_version_path" "$nix_portable_path"

for n in nix nix-shell nix-build; do
  ln -s -f -r "$nix_portable_version_path" "$bin_dir/$n"
done

currently this fails with

$ nix-portable --version
bwrap: execvp /home/user/.nix-portable/nix/store/j823gnvpxh1fjibycmldrspkk3pgivwp-nix-2.20.6/bin/--version: No such file or directory

draft

if [ $# != 0 ] && [ "${0##*/}" = "nix-portable" ] && [ "$1" = "--version" ]; then
  echo v012
  exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant