guix-install.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. #!/bin/sh
  2. # GNU Guix --- Functional package management for GNU
  3. # Copyright © 2017 sharlatan <sharlatanus@gmail.com>
  4. # Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  5. # Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
  6. # Copyright © 2019–2020, 2022 Tobias Geerinckx-Rice <me@tobias.gr>
  7. # Copyright © 2020 Morgan Smith <Morgan.J.Smith@outlook.com>
  8. # Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
  9. # Copyright © 2020 Daniel Brooks <db48x@db48x.net>
  10. # Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net>
  11. # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
  12. # Copyright © 2021, 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  13. # Copyright © 2022 Prafulla Giri <prafulla.giri@protonmail.com>
  14. # Copyright © 2023 Andrew Tropin <andrew@trop.in>
  15. #
  16. # This file is part of GNU Guix.
  17. #
  18. # GNU Guix is free software; you can redistribute it and/or modify it
  19. # under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 3 of the License, or (at
  21. # your option) any later version.
  22. #
  23. # GNU Guix is distributed in the hope that it will be useful, but
  24. # WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  30. # We require Bash but for portability we'd rather not use /bin/bash or
  31. # /usr/bin/env in the shebang, hence this hack.
  32. # Environment variables
  33. #
  34. # GUIX_BINARY_FILE_NAME
  35. #
  36. # Can be used to override the automatic download mechanism and point
  37. # to a local Guix binary archive filename like
  38. # "/tmp/guix-binary-1.4.0rc2.armhf-linux.tar.xz"
  39. #
  40. # GUIX_ALLOW_OVERWRITE
  41. #
  42. # Instead of aborting to avoid overwriting a previous installations,
  43. # allow copying over /var/guix or /gnu. This can be useful when the
  44. # installation required the user to extract Guix packs under /gnu to
  45. # satisfy its dependencies.
  46. if [ "x$BASH_VERSION" = "x" ]
  47. then
  48. exec bash "$0" "$@"
  49. fi
  50. set -eo pipefail
  51. [ "$UID" -eq 0 ] || { echo "This script must be run as root."; exit 1; }
  52. REQUIRE=(
  53. "dirname"
  54. "readlink"
  55. "wget"
  56. "gpg"
  57. "grep"
  58. "which"
  59. "sed"
  60. "sort"
  61. "getent"
  62. "mktemp"
  63. "rm"
  64. "chmod"
  65. "uname"
  66. "groupadd"
  67. "useradd"
  68. "tail"
  69. "tr"
  70. "xz"
  71. )
  72. PAS=$'[ \033[32;1mPASS\033[0m ] '
  73. ERR=$'[ \033[31;1mFAIL\033[0m ] '
  74. WAR=$'[ \033[33;1mWARN\033[0m ] '
  75. INF="[ INFO ] "
  76. DEBUG=0
  77. GNU_URL="https://ftp.gnu.org/gnu/guix/"
  78. #GNU_URL="https://alpha.gnu.org/gnu/guix/"
  79. # The following associative array holds set of GPG keys used to sign the
  80. # releases, keyed by their corresponding Savannah user ID.
  81. declare -A GPG_SIGNING_KEYS
  82. GPG_SIGNING_KEYS[15145]=3CE464558A84FDC69DB40CFB090B11993D9AEBB5 # ludo
  83. GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim
  84. # ------------------------------------------------------------------------------
  85. #+UTILITIES
  86. _err()
  87. { # All errors go to stderr.
  88. printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
  89. }
  90. _msg()
  91. { # Default message to stdout.
  92. printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
  93. }
  94. _debug()
  95. {
  96. if [ "${DEBUG}" = '1' ]; then
  97. printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
  98. fi
  99. }
  100. die()
  101. {
  102. _err "${ERR}$*"
  103. exit 1
  104. }
  105. # Return true if user answered yes, false otherwise. The prompt is
  106. # yes-biased, that is, when the user simply enter newline, it is equivalent to
  107. # answering "yes".
  108. # $1: The prompt question.
  109. prompt_yes_no() {
  110. local -l yn
  111. read -rp "$1 [Y/n]" yn
  112. [[ ! $yn || $yn = y || $yn = yes ]] || return 1
  113. }
  114. chk_require()
  115. { # Check that every required command is available.
  116. declare -a warn
  117. local c
  118. _debug "--- [ ${FUNCNAME[0]} ] ---"
  119. for c in "$@"; do
  120. command -v "$c" &>/dev/null || warn+=("$c")
  121. done
  122. [ "${#warn}" -ne 0 ] && die "Missing commands: ${warn[*]}."
  123. _msg "${PAS}verification of required commands completed"
  124. }
  125. chk_gpg_keyring()
  126. { # Check whether the Guix release signing public key is present.
  127. _debug "--- [ ${FUNCNAME[0]} ] ---"
  128. local user_id
  129. local gpg_key_id
  130. local exit_flag
  131. for user_id in "${!GPG_SIGNING_KEYS[@]}"; do
  132. gpg_key_id=${GPG_SIGNING_KEYS[$user_id]}
  133. # Without --dry-run this command will create a ~/.gnupg owned by root on
  134. # systems where gpg has never been used, causing errors and confusion.
  135. if gpg --dry-run --list-keys "$gpg_key_id" >/dev/null 2>&1; then
  136. continue
  137. fi
  138. if prompt_yes_no "${INF}The following OpenPGP public key is \
  139. required to verify the Guix binary signature: $gpg_key_id.
  140. Would you like me to fetch it for you?"; then
  141. # Use a reasonable time-out here so users don't report silent
  142. # ‘freezes’ when Savannah goes out to lunch, as has happened.
  143. if wget "https://sv.gnu.org/people/viewgpg.php?user_id=$user_id" \
  144. --timeout=30 --no-verbose -O- | gpg --import -; then
  145. continue
  146. fi
  147. fi
  148. # If we reach this point, the key is (still) missing. Report further
  149. # missing keys, if any, but then abort the installation.
  150. _err "${ERR}Missing OpenPGP public key ($gpg_key_id).
  151. Fetch it with this command:
  152. wget \"https://sv.gnu.org/people/viewgpg.php?user_id=$user_id\" -O - | \
  153. sudo -i gpg --import -"
  154. exit_flag=yes
  155. done
  156. if [ "$exit_flag" = yes ]; then
  157. exit 1
  158. fi
  159. }
  160. chk_term()
  161. { # Check for ANSI terminal for color printing.
  162. if [ -t 2 ]; then
  163. if [ "${TERM+set}" = 'set' ]; then
  164. case "$TERM" in
  165. xterm*|rxvt*|urxvt*|linux*|vt*|eterm*|screen*)
  166. ;;
  167. *)
  168. ERR="[ FAIL ] "
  169. PAS="[ PASS ] "
  170. ;;
  171. esac
  172. fi
  173. fi
  174. }
  175. chk_init_sys()
  176. { # Return init system type name.
  177. if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then
  178. _msg "${INF}init system is: upstart"
  179. INIT_SYS="upstart"
  180. return 0
  181. elif [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then
  182. _msg "${INF}init system is: systemd"
  183. INIT_SYS="systemd"
  184. return 0
  185. elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then
  186. _msg "${INF}init system is: sysv-init"
  187. INIT_SYS="sysv-init"
  188. return 0
  189. elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC\) ]]; then
  190. _msg "${INF}init system is: OpenRC"
  191. INIT_SYS="openrc"
  192. return 0
  193. else
  194. INIT_SYS="NA"
  195. _err "${ERR}Init system could not be detected."
  196. fi
  197. }
  198. chk_sys_arch()
  199. { # Check for operating system and architecture type.
  200. local os
  201. local arch
  202. os="$(uname -s)"
  203. arch="$(uname -m)"
  204. case "$arch" in
  205. i386 | i486 | i686 | i786 | x86)
  206. local arch=i686
  207. ;;
  208. x86_64 | x86-64 | x64 | amd64)
  209. local arch=x86_64
  210. ;;
  211. aarch64)
  212. local arch=aarch64
  213. ;;
  214. armv7l)
  215. local arch=armhf
  216. ;;
  217. ppc64le | powerpc64le)
  218. local arch=powerpc64le
  219. ;;
  220. *)
  221. die "Unsupported CPU type: ${arch}"
  222. esac
  223. case "$os" in
  224. Linux | linux)
  225. local os=linux
  226. ;;
  227. *)
  228. die "Your operation system (${os}) is not supported."
  229. esac
  230. ARCH_OS="${arch}-${os}"
  231. }
  232. chk_sys_nscd()
  233. { # Check if nscd is up and suggest to start it or install it
  234. if [ "$(type -P pidof)" ]; then
  235. if [ ! "$(pidof nscd)" ]; then
  236. _msg "${WAR}We recommend installing and/or starting your distribution 'nscd' service"
  237. _msg "${WAR}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
  238. fi
  239. else
  240. _msg "${INF}We cannot determine if your distribution 'nscd' service is running"
  241. _msg "${INF}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\""
  242. fi
  243. }
  244. # Configure substitute discovery according to user's preferences.
  245. # $1 is the installed service file to edit.
  246. configure_substitute_discovery() {
  247. if grep -q -- '--discover=no' "$1" && \
  248. prompt_yes_no "Would you like the Guix daemon to automatically \
  249. discover substitute servers on the local network?"; then
  250. sed -i 's/--discover=no/--discover=yes/' "$1"
  251. fi
  252. }
  253. # ------------------------------------------------------------------------------
  254. #+MAIN
  255. guix_get_bin_list()
  256. { # Scan GNU archive and save list of binaries
  257. local gnu_url="$1"
  258. local -a bin_ver_ls
  259. local latest_ver
  260. local default_ver
  261. _debug "--- [ ${FUNCNAME[0]} ] ---"
  262. # Filter only version and architecture
  263. bin_ver_ls=("$(wget "$gnu_url" --no-verbose -O- \
  264. | sed -n -e 's/.*guix-binary-\([0-9.]*[a-z0-9]*\)\..*.tar.xz.*/\1/p' \
  265. | sort -Vu)")
  266. latest_ver="$(echo "${bin_ver_ls[0]}" \
  267. | grep -oE "([0-9]{1,2}\.){2}[0-9]{1,2}[a-z0-9]*" \
  268. | tail -n1)"
  269. default_ver="guix-binary-${latest_ver}.${ARCH_OS}"
  270. if [[ "${#bin_ver_ls}" -ne "0" ]]; then
  271. _msg "${PAS}Release for your system: ${default_ver}"
  272. else
  273. die "Could not obtain list of Guix releases."
  274. fi
  275. # Use default to download according to the list and local ARCH_OS.
  276. BIN_VER="${default_ver}"
  277. }
  278. guix_get_bin()
  279. { # Download and verify binary package.
  280. local url="$1"
  281. local bin_ver="$2"
  282. local dl_path="$3"
  283. local wget_args=()
  284. _debug "--- [ ${FUNCNAME[0]} ] ---"
  285. _msg "${INF}Downloading Guix release archive"
  286. wget --help | grep -q '\--show-progress' \
  287. && wget_args=("--no-verbose" "--show-progress")
  288. if wget "${wget_args[@]}" -P "$dl_path" \
  289. "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then
  290. _msg "${PAS}download completed."
  291. else
  292. die "could not download ${url}/${bin_ver}.tar.xz."
  293. fi
  294. pushd "${dl_path}" >/dev/null
  295. if gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1; then
  296. _msg "${PAS}Signature is valid."
  297. popd >/dev/null
  298. else
  299. die "could not verify the signature."
  300. fi
  301. }
  302. sys_create_store()
  303. { # Unpack and install /gnu/store and /var/guix
  304. local pkg="$1"
  305. local tmp_path="$2"
  306. _debug "--- [ ${FUNCNAME[0]} ] ---"
  307. if [[ -e /var/guix && -e /gnu ]]; then
  308. if [ -n "$GUIX_ALLOW_OVERWRITE" ]; then
  309. _msg "${WAR}Overwriting existing installation!"
  310. else
  311. die "A previous Guix installation was found. Refusing to overwrite."
  312. fi
  313. fi
  314. cd "$tmp_path"
  315. _msg "${INF}Installing /var/guix and /gnu..."
  316. tar --extract --file "$pkg" -C /
  317. _msg "${INF}Linking the root user's profile"
  318. mkdir -p ~root/.config/guix
  319. ln -sf /var/guix/profiles/per-user/root/current-guix \
  320. ~root/.config/guix/current
  321. GUIX_PROFILE=~root/.config/guix/current
  322. # shellcheck disable=SC1090
  323. source "${GUIX_PROFILE}/etc/profile"
  324. _msg "${PAS}activated root profile at ${GUIX_PROFILE}"
  325. }
  326. sys_create_build_user()
  327. { # Create the group and user accounts for build users.
  328. _debug "--- [ ${FUNCNAME[0]} ] ---"
  329. if getent group guixbuild > /dev/null; then
  330. _msg "${INF}group guixbuild exists"
  331. else
  332. groupadd --system guixbuild
  333. _msg "${PAS}group <guixbuild> created"
  334. fi
  335. if getent group kvm > /dev/null; then
  336. _msg "${INF}group kvm exists and build users will be added to it"
  337. local KVMGROUP=,kvm
  338. fi
  339. for i in $(seq -w 1 10); do
  340. if id "guixbuilder${i}" &>/dev/null; then
  341. _msg "${INF}user is already in the system, reset"
  342. usermod -g guixbuild -G guixbuild${KVMGROUP} \
  343. -d /var/empty -s "$(which nologin)" \
  344. -c "Guix build user $i" \
  345. "guixbuilder${i}";
  346. else
  347. useradd -g guixbuild -G guixbuild${KVMGROUP} \
  348. -d /var/empty -s "$(which nologin)" \
  349. -c "Guix build user $i" --system \
  350. "guixbuilder${i}";
  351. _msg "${PAS}user added <guixbuilder${i}>"
  352. fi
  353. done
  354. }
  355. sys_enable_guix_daemon()
  356. { # Run the daemon, and set it to automatically start on boot.
  357. local info_path
  358. local local_bin
  359. local var_guix
  360. _debug "--- [ ${FUNCNAME[0]} ] ---"
  361. info_path="/usr/local/share/info"
  362. local_bin="/usr/local/bin"
  363. var_guix="/var/guix/profiles/per-user/root/current-guix"
  364. case "$INIT_SYS" in
  365. upstart)
  366. { initctl reload-configuration;
  367. cp ~root/.config/guix/current/lib/upstart/system/guix-daemon.conf \
  368. /etc/init/ &&
  369. configure_substitute_discovery /etc/init/guix-daemon.conf &&
  370. start guix-daemon; } &&
  371. _msg "${PAS}enabled Guix daemon via upstart"
  372. ;;
  373. systemd)
  374. { # systemd .mount units must be named after the target directory.
  375. # Here we assume a hard-coded name of /gnu/store.
  376. # XXX Work around <https://issues.guix.gnu.org/41356> until next release.
  377. if [ -f ~root/.config/guix/current/lib/systemd/system/gnu-store.mount ]; then
  378. cp ~root/.config/guix/current/lib/systemd/system/gnu-store.mount \
  379. /etc/systemd/system/;
  380. chmod 664 /etc/systemd/system/gnu-store.mount;
  381. systemctl daemon-reload &&
  382. systemctl enable gnu-store.mount;
  383. fi
  384. cp ~root/.config/guix/current/lib/systemd/system/guix-daemon.service \
  385. /etc/systemd/system/;
  386. chmod 664 /etc/systemd/system/guix-daemon.service;
  387. # Work around <https://bugs.gnu.org/36074>, present in 1.0.1.
  388. sed -i /etc/systemd/system/guix-daemon.service \
  389. -e "s/GUIX_LOCPATH='/'GUIX_LOCPATH=/";
  390. # Work around <https://bugs.gnu.org/35671>, present in 1.0.1.
  391. if ! grep en_US /etc/systemd/system/guix-daemon.service >/dev/null;
  392. then sed -i /etc/systemd/system/guix-daemon.service \
  393. -e 's/^Environment=\(.*\)$/Environment=\1 LC_ALL=en_US.UTF-8';
  394. fi;
  395. configure_substitute_discovery \
  396. /etc/systemd/system/guix-daemon.service
  397. systemctl daemon-reload &&
  398. systemctl enable guix-daemon &&
  399. systemctl start guix-daemon; } &&
  400. _msg "${PAS}enabled Guix daemon via systemd"
  401. ;;
  402. sysv-init)
  403. { mkdir -p /etc/init.d;
  404. cp ~root/.config/guix/current/etc/init.d/guix-daemon \
  405. /etc/init.d/guix-daemon;
  406. chmod 775 /etc/init.d/guix-daemon;
  407. configure_substitute_discovery /etc/init.d/guix-daemon
  408. update-rc.d guix-daemon defaults &&
  409. update-rc.d guix-daemon enable &&
  410. service guix-daemon start; } &&
  411. _msg "${PAS}enabled Guix daemon via sysv"
  412. ;;
  413. openrc)
  414. { mkdir -p /etc/init.d;
  415. cp ~root/.config/guix/current/etc/openrc/guix-daemon \
  416. /etc/init.d/guix-daemon;
  417. chmod 775 /etc/init.d/guix-daemon;
  418. configure_substitute_discovery /etc/init.d/guix-daemon
  419. rc-update add guix-daemon default &&
  420. rc-service guix-daemon start; } &&
  421. _msg "${PAS}enabled Guix daemon via OpenRC"
  422. ;;
  423. NA|*)
  424. _msg "${ERR}unsupported init system; run the daemon manually:"
  425. echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
  426. ;;
  427. esac
  428. _msg "${INF}making the guix command available to other users"
  429. [ -e "$local_bin" ] || mkdir -p "$local_bin"
  430. ln -sf "${var_guix}/bin/guix" "$local_bin"
  431. [ -e "$info_path" ] || mkdir -p "$info_path"
  432. for i in "${var_guix}"/share/info/*; do
  433. ln -sf "$i" "$info_path"
  434. done
  435. }
  436. sys_authorize_build_farms()
  437. { # authorize the public key(s) of the build farm(s)
  438. local hosts=(
  439. ci.guix.gnu.org
  440. bordeaux.guix.gnu.org
  441. )
  442. if prompt_yes_no "Permit downloading pre-built package binaries from the \
  443. project's build farms?"; then
  444. for host in "${hosts[@]}"; do
  445. local key=~root/.config/guix/current/share/guix/$host.pub
  446. [ -f "$key" ] \
  447. && guix archive --authorize < "$key" \
  448. && _msg "${PAS}Authorized public key for $host"
  449. done
  450. else
  451. _msg "${INF}Skipped authorizing build farm public keys"
  452. fi
  453. }
  454. sys_create_init_profile()
  455. { # Define for better desktop integration
  456. # This will not take effect until the next shell or desktop session!
  457. [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case
  458. cat <<"EOF" > /etc/profile.d/zzz-guix.sh
  459. # Explicitly initialize XDG base directory variables to ease compatibility
  460. # with Guix System: see <https://issues.guix.gnu.org/56050#3>.
  461. export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
  462. export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  463. export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
  464. export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
  465. export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
  466. export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  467. # no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)
  468. # _GUIX_PROFILE: `guix pull` profile
  469. _GUIX_PROFILE="$HOME/.config/guix/current"
  470. export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
  471. # Export INFOPATH so that the updated info pages can be found
  472. # and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info
  473. # When INFOPATH is unset, add a trailing colon so that Emacs
  474. # searches 'Info-default-directory-list'.
  475. export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"
  476. # GUIX_PROFILE: User's default profile and home profile
  477. GUIX_PROFILE="$HOME/.guix-profile"
  478. [ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
  479. [ -L "$GUIX_PROFILE" ] || \
  480. GUIX_LOCPATH="$GUIX_PROFILE/lib/locale:${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
  481. GUIX_PROFILE="$HOME/.guix-home/profile"
  482. [ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
  483. [ -L "$GUIX_PROFILE" ] || \
  484. GUIX_LOCPATH="$GUIX_PROFILE/lib/locale:${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
  485. export GUIX_LOCPATH
  486. EOF
  487. }
  488. sys_create_shell_completion()
  489. { # Symlink supported shell completions system-wide
  490. var_guix=/var/guix/profiles/per-user/root/current-guix
  491. bash_completion=/etc/bash_completion.d
  492. zsh_completion=/usr/share/zsh/site-functions
  493. fish_completion=/usr/share/fish/vendor_completions.d
  494. { # Just in case
  495. for dir_shell in $bash_completion $zsh_completion $fish_completion; do
  496. [ -d "$dir_shell" ] || mkdir -p $dir_shell
  497. done;
  498. ln -sf ${var_guix}/etc/bash_completion.d/* "$bash_completion";
  499. ln -sf ${var_guix}/share/zsh/site-functions/* "$zsh_completion";
  500. ln -sf ${var_guix}/share/fish/vendor_completions.d/* "$fish_completion"; } &&
  501. _msg "${PAS}installed shell completion"
  502. }
  503. sys_customize_bashrc()
  504. {
  505. prompt_yes_no "Customize users Bash shell prompt for Guix?" || return
  506. for bashrc in /home/*/.bashrc /root/.bashrc; do
  507. test -f "$bashrc" || continue
  508. grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
  509. cp "${bashrc}" "${bashrc}.bak"
  510. echo '
  511. # Automatically added by the Guix install script.
  512. if [ -n "$GUIX_ENVIRONMENT" ]; then
  513. if [[ $PS1 =~ (.*)"\\$" ]]; then
  514. PS1="${BASH_REMATCH[1]} [env]\\\$ "
  515. fi
  516. fi
  517. ' >> "$bashrc"
  518. done
  519. _msg "${PAS}Bash shell prompt successfully customized for Guix"
  520. }
  521. sys_maybe_setup_selinux()
  522. {
  523. if [ -f /sys/fs/selinux/policy ]
  524. then
  525. prompt_yes_no "Install SELinux policy required to run guix-daemon?" \
  526. || return
  527. local var_guix=/var/guix/profiles/per-user/root/current-guix
  528. semodule -i "${var_guix}/share/selinux/guix-daemon.cil"
  529. restorecon -R /gnu /var/guix
  530. fi
  531. }
  532. welcome()
  533. {
  534. local char
  535. cat<<"EOF"
  536. ░░░ ░░░
  537. ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
  538. ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
  539. ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
  540. ░▒▒▒▒░ ░░░░░░
  541. ▒▒▒▒▒ ░░░░░░
  542. ▒▒▒▒▒ ░░░░░
  543. ░▒▒▒▒▒ ░░░░░
  544. ▒▒▒▒▒ ░░░░░
  545. ▒▒▒▒▒ ░░░░░
  546. ░▒▒▒▒▒░░░░░
  547. ▒▒▒▒▒▒░░░
  548. ▒▒▒▒▒▒░
  549. _____ _ _ _ _ _____ _
  550. / ____| \ | | | | | / ____| (_)
  551. | | __| \| | | | | | | __ _ _ ___ __
  552. | | |_ | . ' | | | | | | |_ | | | | \ \/ /
  553. | |__| | |\ | |__| | | |__| | |_| | |> <
  554. \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
  555. This script installs GNU Guix on your system
  556. https://www.gnu.org/software/guix/
  557. EOF
  558. # Don't use ‘read -p’ here! It won't display when run non-interactively.
  559. echo -n "Press return to continue..."$'\r'
  560. if ! read -r char; then
  561. echo
  562. die "Can't read standard input. Hint: don't pipe scripts into a shell."
  563. fi
  564. if [ "$char" ]; then
  565. echo
  566. echo "...that ($char) was not a return!"
  567. _msg "${WAR}Use newlines to automate installation, e.g.: yes '' | ${0##*/}"
  568. _msg "${WAR}Any other method is unsupported and likely to break in future."
  569. fi
  570. }
  571. main()
  572. {
  573. local tmp_path
  574. welcome
  575. _msg "Starting installation ($(date))"
  576. chk_term
  577. chk_require "${REQUIRE[@]}"
  578. chk_gpg_keyring
  579. chk_init_sys
  580. chk_sys_arch
  581. chk_sys_nscd
  582. _msg "${INF}system is ${ARCH_OS}"
  583. umask 0022
  584. tmp_path="$(mktemp -t -d guix.XXXXXX)"
  585. if [ -z "${GUIX_BINARY_FILE_NAME}" ]; then
  586. guix_get_bin_list "${GNU_URL}"
  587. guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
  588. GUIX_BINARY_FILE_NAME=${BIN_VER}.tar.xz
  589. else
  590. if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then
  591. _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting"
  592. fi
  593. _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}"
  594. GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME")
  595. fi
  596. sys_create_store "${GUIX_BINARY_FILE_NAME}" "${tmp_path}"
  597. sys_create_build_user
  598. sys_maybe_setup_selinux
  599. sys_enable_guix_daemon
  600. sys_authorize_build_farms
  601. sys_create_init_profile
  602. sys_create_shell_completion
  603. sys_customize_bashrc
  604. _msg "${INF}cleaning up ${tmp_path}"
  605. rm -r "${tmp_path}"
  606. _msg "${PAS}Guix has successfully been installed!"
  607. _msg "${INF}Run 'info guix' to read the manual."
  608. # Required to source /etc/profile in desktop environments.
  609. _msg "${INF}Please log out and back in to complete the installation."
  610. }
  611. main "$@"