|
23 | 23 |
|
24 | 24 | detect_user USERNAME
|
25 | 25 |
|
26 |
| -if [ -e "/nix" ]; then |
27 |
| - echo "(!) Nix is already installed! Skipping installation." |
28 |
| -else |
29 |
| - if [ "${USERNAME}" = "root" ] && [ "${MULTIUSER}" != "true" ]; then |
30 |
| - echo "(!) A single user install is not allowed for root. Add a non-root user to your image or set multiUser to true in your feature configuration." |
31 |
| - exit 1 |
32 |
| - fi |
| 26 | +if [ "${USERNAME}" = "root" ] && [ "${MULTIUSER}" != "true" ]; then |
| 27 | + echo "(!) A single user install is not allowed for root. Add a non-root user to your image or set multiUser to true in your feature configuration." |
| 28 | + exit 1 |
| 29 | +fi |
33 | 30 |
|
34 |
| - # Verify dependencies |
35 |
| - apt_get_update_if_exists |
36 |
| - check_command curl "curl ca-certificates" "curl ca-certificates" "curl ca-certificates" |
37 |
| - check_command gpg2 gnupg2 gnupg gnupg2 |
38 |
| - check_command dirmngr dirmngr dirmngr dirmngr |
39 |
| - check_command xz xz-utils xz xz |
40 |
| - check_command git git git git |
41 |
| - check_command xargs findutils findutils findutils |
| 31 | +# Verify dependencies |
| 32 | +apt_get_update_if_exists |
| 33 | +check_command curl "curl ca-certificates" "curl ca-certificates" "curl ca-certificates" |
| 34 | +check_command gpg2 gnupg2 gnupg gnupg2 |
| 35 | +check_command dirmngr dirmngr dirmngr dirmngr |
| 36 | +check_command xz xz-utils xz xz |
| 37 | +check_command git git git git |
| 38 | +check_command xargs findutils findutils findutils |
42 | 39 |
|
43 |
| - # Determine version |
44 |
| - find_version_from_git_tags VERSION https://github.com/NixOS/nix "tags/" |
| 40 | +# Determine version |
| 41 | +find_version_from_git_tags VERSION https://github.com/NixOS/nix "tags/" |
45 | 42 |
|
46 |
| - # Download and verify install per https://nixos.org/download.html#nix-verify-installation |
47 |
| - tmpdir="$(mktemp -d)" |
48 |
| - echo "(*) Downloading Nix installer..." |
49 |
| - set +e |
| 43 | +# Download and verify install per https://nixos.org/download.html#nix-verify-installation |
| 44 | +tmpdir="$(mktemp -d)" |
| 45 | +echo "(*) Downloading Nix installer..." |
| 46 | +set +e |
| 47 | +curl -sSLf -o "${tmpdir}/install-nix" https://releases.nixos.org/nix/nix-${VERSION}/install |
| 48 | +exit_code=$? |
| 49 | +set -e |
| 50 | +if [ "$exit_code" != "0" ]; then |
| 51 | + # Handle situation where git tags are ahead of what was is available to actually download |
| 52 | + echo "(!) Nix version ${VERSION} failed to download. Attempting to fall back one version to retry..." |
| 53 | + find_prev_version_from_git_tags VERSION https://github.com/NixOS/nix "tags/" |
50 | 54 | curl -sSLf -o "${tmpdir}/install-nix" https://releases.nixos.org/nix/nix-${VERSION}/install
|
51 |
| - exit_code=$? |
52 |
| - set -e |
53 |
| - if [ "$exit_code" != "0" ]; then |
54 |
| - # Handle situation where git tags are ahead of what was is available to actually download |
55 |
| - echo "(!) Nix version ${VERSION} failed to download. Attempting to fall back one version to retry..." |
56 |
| - find_prev_version_from_git_tags VERSION https://github.com/NixOS/nix "tags/" |
57 |
| - curl -sSLf -o "${tmpdir}/install-nix" https://releases.nixos.org/nix/nix-${VERSION}/install |
58 |
| - fi |
59 |
| - cd "${FEATURE_DIR}" |
| 55 | +fi |
| 56 | +cd "${FEATURE_DIR}" |
60 | 57 |
|
61 |
| - # Do a multi or single-user setup based on feature config |
62 |
| - if [ "${MULTIUSER}" = "true" ]; then |
63 |
| - echo "(*) Performing multi-user install..." |
64 |
| - sh "${tmpdir}/install-nix" --daemon |
65 |
| - else |
66 |
| - home_dir="$(eval echo ~${USERNAME})" |
67 |
| - if [ ! -e "${home_dir}" ]; then |
68 |
| - echo "(!) Home directory ${home_dir} does not exist for ${USERNAME}. Nix install will fail." |
69 |
| - exit 1 |
70 |
| - fi |
71 |
| - echo "(*) Performing single-user install..." |
72 |
| - echo -e "\n**NOTE: Nix will only work for user ${USERNAME} on Linux if the host machine user's UID is $(id -u ${USERNAME}). You will need to chown /nix otherwise.**\n" |
73 |
| - # Install per https://nixos.org/manual/nix/stable/installation/installing-binary.html#single-user-installation |
74 |
| - mkdir -p /nix |
75 |
| - chown ${USERNAME} /nix ${tmpdir} |
76 |
| - su ${USERNAME} -c "sh \"${tmpdir}/install-nix\" --no-daemon --no-modify-profile" |
77 |
| - # nix installer does not update ~/.bashrc, and USER may or may not be defined, so update rc/profile files directly to handle that |
78 |
| - snippet=' |
79 |
| - if [ "${PATH#*$HOME/.nix-profile/bin}" = "${PATH}" ]; then if [ -z "$USER" ]; then USER=$(whoami); fi; . $HOME/.nix-profile/etc/profile.d/nix.sh; fi |
80 |
| - ' |
81 |
| - update_rc_file "$home_dir/.bashrc" "${snippet}" |
82 |
| - update_rc_file "$home_dir/.zshenv" "${snippet}" |
83 |
| - update_rc_file "$home_dir/.profile" "${snippet}" |
| 58 | +# Do a multi or single-user setup based on feature config |
| 59 | +if [ "${MULTIUSER}" = "true" ]; then |
| 60 | + echo "(*) Performing multi-user install..." |
| 61 | + sh "${tmpdir}/install-nix" --daemon |
| 62 | +else |
| 63 | + home_dir="$(eval echo ~${USERNAME})" |
| 64 | + if [ ! -e "${home_dir}" ]; then |
| 65 | + echo "(!) Home directory ${home_dir} does not exist for ${USERNAME}. Nix install will fail." |
| 66 | + exit 1 |
84 | 67 | fi
|
85 |
| - rm -rf "${tmpdir}" "/tmp/tmp-gnupg" |
| 68 | + echo "(*) Performing single-user install..." |
| 69 | + echo -e "\n**NOTE: Nix will only work for user ${USERNAME} on Linux if the host machine user's UID is $(id -u ${USERNAME}). You will need to chown /nix otherwise.**\n" |
| 70 | + # Install per https://nixos.org/manual/nix/stable/installation/installing-binary.html#single-user-installation |
| 71 | + mkdir -p /nix |
| 72 | + chown ${USERNAME} /nix ${tmpdir} |
| 73 | + su ${USERNAME} -c "sh \"${tmpdir}/install-nix\" --no-daemon --no-modify-profile" |
| 74 | + # nix installer does not update ~/.bashrc, and USER may or may not be defined, so update rc/profile files directly to handle that |
| 75 | + snippet=' |
| 76 | + if [ "${PATH#*$HOME/.nix-profile/bin}" = "${PATH}" ]; then if [ -z "$USER" ]; then USER=$(whoami); fi; . $HOME/.nix-profile/etc/profile.d/nix.sh; fi |
| 77 | + ' |
| 78 | + update_rc_file "$home_dir/.bashrc" "${snippet}" |
| 79 | + update_rc_file "$home_dir/.zshenv" "${snippet}" |
| 80 | + update_rc_file "$home_dir/.profile" "${snippet}" |
86 | 81 | fi
|
| 82 | +rm -rf "${tmpdir}" "/tmp/tmp-gnupg" |
87 | 83 |
|
88 | 84 | # Set nix config
|
89 | 85 | mkdir -p /etc/nix
|
|
0 commit comments