|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This script installs the Nix package manager on your system by |
| 4 | +# downloading a binary distribution and running its installer script |
| 5 | +# (which in turn creates and populates /nix). |
| 6 | + |
| 7 | +{ # Prevent execution if this script was only partially downloaded |
| 8 | +oops() { |
| 9 | + echo "$0:" "$@" >&2 |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +umask 0022 |
| 14 | + |
| 15 | +tmpDir="$(mktemp -d -t nix-binary-tarball-unpack.XXXXXXXXXX || \ |
| 16 | + oops "Can't create temporary directory for downloading the Nix binary tarball")" |
| 17 | +cleanup() { |
| 18 | + rm -rf "$tmpDir" |
| 19 | +} |
| 20 | +trap cleanup EXIT INT QUIT TERM |
| 21 | + |
| 22 | +require_util() { |
| 23 | + command -v "$1" > /dev/null 2>&1 || |
| 24 | + oops "you do not have '$1' installed, which I need to $2" |
| 25 | +} |
| 26 | + |
| 27 | +case "$(uname -s).$(uname -m)" in |
| 28 | + Linux.x86_64) |
| 29 | + hash=c6d48479d50a01cdfc3669440776692ca7094ff29028b1fec6da0abeead16a01 |
| 30 | + path=sicsy40akh9hs5r8iz1rkgnh46yfns4h/nix-2.11.1-x86_64-linux.tar.xz |
| 31 | + system=x86_64-linux |
| 32 | + ;; |
| 33 | + Linux.i?86) |
| 34 | + hash=37fa1567394baf7fac2651d4d60890191b9d183626faf2069c59dbc602136ac5 |
| 35 | + path=17s133r9xnvwkg7v6var7i24w2av285g/nix-2.11.1-i686-linux.tar.xz |
| 36 | + system=i686-linux |
| 37 | + ;; |
| 38 | + Linux.aarch64) |
| 39 | + hash=b8ef85ea43d30ed89fdd176d8b044c5d1301628a77886742ea3f684cd4dc6db3 |
| 40 | + path=fhi79b7zvz6np2rhld034qzpf7pfmb67/nix-2.11.1-aarch64-linux.tar.xz |
| 41 | + system=aarch64-linux |
| 42 | + ;; |
| 43 | + Linux.armv6l_linux) |
| 44 | + hash=7181889751cb83add9b4ef7ea6bd0adb90eb0cd8c78422315cc22e6a7188dafd |
| 45 | + path=r44jpi4hki9llkznyxdl18a7f634an2p/nix-2.11.1-armv6l-linux.tar.xz |
| 46 | + system=armv6l-linux |
| 47 | + ;; |
| 48 | + Linux.armv7l_linux) |
| 49 | + hash=8550980d6001f42f5dd2e969a016304f3e659bdcd9146e04c18b02f5b63994cd |
| 50 | + path=0kmd8q1g4gyw6pr474xp3nxs8mvyigqh/nix-2.11.1-armv7l-linux.tar.xz |
| 51 | + system=armv7l-linux |
| 52 | + ;; |
| 53 | + Darwin.x86_64) |
| 54 | + hash=16dac47e397ff9026af23f355cc84465a2af7ec56b65ddb52c8b124d700556b1 |
| 55 | + path=f0zhwzkvn5vv583mzbj0dqahzcajkglx/nix-2.11.1-x86_64-darwin.tar.xz |
| 56 | + system=x86_64-darwin |
| 57 | + ;; |
| 58 | + Darwin.arm64|Darwin.aarch64) |
| 59 | + hash=ddead2fa8ef6b9b58fec4ab12b460f802a962fff68fb1c8fa47c7b8b5739bc0b |
| 60 | + path=d2gq40kvzckjmhwbbnh718w64v6zlr3m/nix-2.11.1-aarch64-darwin.tar.xz |
| 61 | + system=aarch64-darwin |
| 62 | + ;; |
| 63 | + *) oops "sorry, there is no binary distribution of Nix for your platform";; |
| 64 | +esac |
| 65 | + |
| 66 | +# Use this command-line option to fetch the tarballs using nar-serve or Cachix |
| 67 | +if [ "${1:-}" = "--tarball-url-prefix" ]; then |
| 68 | + if [ -z "${2:-}" ]; then |
| 69 | + oops "missing argument for --tarball-url-prefix" |
| 70 | + fi |
| 71 | + url=${2}/${path} |
| 72 | + shift 2 |
| 73 | +else |
| 74 | + url=https://releases.nixos.org/nix/nix-2.11.1/nix-2.11.1-$system.tar.xz |
| 75 | +fi |
| 76 | + |
| 77 | +tarball=$tmpDir/nix-2.11.1-$system.tar.xz |
| 78 | + |
| 79 | +require_util tar "unpack the binary tarball" |
| 80 | +if [ "$(uname -s)" != "Darwin" ]; then |
| 81 | + require_util xz "unpack the binary tarball" |
| 82 | +fi |
| 83 | + |
| 84 | +if command -v curl > /dev/null 2>&1; then |
| 85 | + fetch() { curl --fail -L "$1" -o "$2"; } |
| 86 | +elif command -v wget > /dev/null 2>&1; then |
| 87 | + fetch() { wget "$1" -O "$2"; } |
| 88 | +else |
| 89 | + oops "you don't have wget or curl installed, which I need to download the binary tarball" |
| 90 | +fi |
| 91 | + |
| 92 | +echo "downloading Nix 2.11.1 binary tarball for $system from '$url' to '$tmpDir'..." |
| 93 | +fetch "$url" "$tarball" || oops "failed to download '$url'" |
| 94 | + |
| 95 | +if command -v sha256sum > /dev/null 2>&1; then |
| 96 | + hash2="$(sha256sum -b "$tarball" | cut -c1-64)" |
| 97 | +elif command -v shasum > /dev/null 2>&1; then |
| 98 | + hash2="$(shasum -a 256 -b "$tarball" | cut -c1-64)" |
| 99 | +elif command -v openssl > /dev/null 2>&1; then |
| 100 | + hash2="$(openssl dgst -r -sha256 "$tarball" | cut -c1-64)" |
| 101 | +else |
| 102 | + oops "cannot verify the SHA-256 hash of '$url'; you need one of 'shasum', 'sha256sum', or 'openssl'" |
| 103 | +fi |
| 104 | + |
| 105 | +if [ "$hash" != "$hash2" ]; then |
| 106 | + oops "SHA-256 hash mismatch in '$url'; expected $hash, got $hash2" |
| 107 | +fi |
| 108 | + |
| 109 | +unpack=$tmpDir/unpack |
| 110 | +mkdir -p "$unpack" |
| 111 | +tar -xJf "$tarball" -C "$unpack" || oops "failed to unpack '$url'" |
| 112 | + |
| 113 | +script=$(echo "$unpack"/*/install) |
| 114 | + |
| 115 | +[ -e "$script" ] || oops "installation script is missing from the binary tarball!" |
| 116 | +export INVOKED_FROM_INSTALL_IN=1 |
| 117 | +"$script" "$@" |
| 118 | + |
| 119 | +} # End of wrapping |
0 commit comments