guix-install.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. # Strip (skip) the leading ‘.’ component, which fails on read-only ‘/’.
  317. tar --extract --strip-components=1 --file "$pkg" -C /
  318. _msg "${INF}Linking the root user's profile"
  319. mkdir -p ~root/.config/guix
  320. ln -sf /var/guix/profiles/per-user/root/current-guix \
  321. ~root/.config/guix/current
  322. GUIX_PROFILE=~root/.config/guix/current
  323. # shellcheck disable=SC1090
  324. source "${GUIX_PROFILE}/etc/profile"
  325. _msg "${PAS}activated root profile at ${GUIX_PROFILE}"
  326. }
  327. sys_create_build_user()
  328. { # Create the group and user accounts for build users.
  329. _debug "--- [ ${FUNCNAME[0]} ] ---"
  330. if getent group guixbuild > /dev/null; then
  331. _msg "${INF}group guixbuild exists"
  332. else
  333. groupadd --system guixbuild
  334. _msg "${PAS}group <guixbuild> created"
  335. fi
  336. if getent group kvm > /dev/null; then
  337. _msg "${INF}group kvm exists and build users will be added to it"
  338. local KVMGROUP=,kvm
  339. fi
  340. for i in $(seq -w 1 10); do
  341. if id "guixbuilder${i}" &>/dev/null; then
  342. _msg "${INF}user is already in the system, reset"
  343. usermod -g guixbuild -G guixbuild${KVMGROUP} \
  344. -d /var/empty -s "$(which nologin)" \
  345. -c "Guix build user $i" \
  346. "guixbuilder${i}";
  347. else
  348. useradd -g guixbuild -G guixbuild${KVMGROUP} \
  349. -d /var/empty -s "$(which nologin)" \
  350. -c "Guix build user $i" --system \
  351. "guixbuilder${i}";
  352. _msg "${PAS}user added <guixbuilder${i}>"
  353. fi
  354. done
  355. }
  356. sys_enable_guix_daemon()
  357. { # Run the daemon, and set it to automatically start on boot.
  358. local info_path
  359. local local_bin
  360. local var_guix
  361. _debug "--- [ ${FUNCNAME[0]} ] ---"
  362. info_path="/usr/local/share/info"
  363. local_bin="/usr/local/bin"
  364. var_guix="/var/guix/profiles/per-user/root/current-guix"
  365. case "$INIT_SYS" in
  366. upstart)
  367. { initctl reload-configuration;
  368. cp ~root/.config/guix/current/lib/upstart/system/guix-daemon.conf \
  369. /etc/init/ &&
  370. configure_substitute_discovery /etc/init/guix-daemon.conf &&
  371. start guix-daemon; } &&
  372. _msg "${PAS}enabled Guix daemon via upstart"
  373. ;;
  374. systemd)
  375. { install_unit()
  376. {
  377. local dest="/etc/systemd/system/$1"
  378. rm -f "$dest"
  379. cp ~root/.config/guix/current/lib/systemd/system/"$1" "$dest"
  380. chmod 664 "$dest"
  381. systemctl daemon-reload
  382. systemctl enable "$1"
  383. }
  384. install_unit guix-daemon.service
  385. configure_substitute_discovery \
  386. /etc/systemd/system/guix-daemon.service
  387. # Install after guix-daemon.service to avoid a harmless warning.
  388. # systemd .mount units must be named after the target directory.
  389. # Here we assume a hard-coded name of /gnu/store.
  390. install_unit gnu-store.mount
  391. systemctl daemon-reload &&
  392. systemctl start guix-daemon; } &&
  393. _msg "${PAS}enabled Guix daemon via systemd"
  394. ;;
  395. sysv-init)
  396. { mkdir -p /etc/init.d;
  397. cp ~root/.config/guix/current/etc/init.d/guix-daemon \
  398. /etc/init.d/guix-daemon;
  399. chmod 775 /etc/init.d/guix-daemon;
  400. configure_substitute_discovery /etc/init.d/guix-daemon
  401. update-rc.d guix-daemon defaults &&
  402. update-rc.d guix-daemon enable &&
  403. service guix-daemon start; } &&
  404. _msg "${PAS}enabled Guix daemon via sysv"
  405. ;;
  406. openrc)
  407. { mkdir -p /etc/init.d;
  408. cp ~root/.config/guix/current/etc/openrc/guix-daemon \
  409. /etc/init.d/guix-daemon;
  410. chmod 775 /etc/init.d/guix-daemon;
  411. configure_substitute_discovery /etc/init.d/guix-daemon
  412. rc-update add guix-daemon default &&
  413. rc-service guix-daemon start; } &&
  414. _msg "${PAS}enabled Guix daemon via OpenRC"
  415. ;;
  416. NA|*)
  417. _msg "${ERR}unsupported init system; run the daemon manually:"
  418. echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
  419. ;;
  420. esac
  421. _msg "${INF}making the guix command available to other users"
  422. [ -e "$local_bin" ] || mkdir -p "$local_bin"
  423. ln -sf "${var_guix}/bin/guix" "$local_bin"
  424. [ -e "$info_path" ] || mkdir -p "$info_path"
  425. for i in "${var_guix}"/share/info/*; do
  426. ln -sf "$i" "$info_path"
  427. done
  428. }
  429. sys_authorize_build_farms()
  430. { # authorize the public key(s) of the build farm(s)
  431. local hosts=(
  432. ci.guix.gnu.org
  433. bordeaux.guix.gnu.org
  434. )
  435. if prompt_yes_no "Permit downloading pre-built package binaries from the \
  436. project's build farms?"; then
  437. for host in "${hosts[@]}"; do
  438. local key=~root/.config/guix/current/share/guix/$host.pub
  439. [ -f "$key" ] \
  440. && guix archive --authorize < "$key" \
  441. && _msg "${PAS}Authorized public key for $host"
  442. done
  443. else
  444. _msg "${INF}Skipped authorizing build farm public keys"
  445. fi
  446. }
  447. sys_create_init_profile()
  448. { # Define for better desktop integration
  449. # This will not take effect until the next shell or desktop session!
  450. [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case
  451. cat <<"EOF" > /etc/profile.d/zzz-guix.sh
  452. # Explicitly initialize XDG base directory variables to ease compatibility
  453. # with Guix System: see <https://issues.guix.gnu.org/56050#3>.
  454. export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
  455. export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  456. export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
  457. export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
  458. export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
  459. export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  460. # no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)
  461. # _GUIX_PROFILE: `guix pull` profile
  462. _GUIX_PROFILE="$HOME/.config/guix/current"
  463. export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
  464. # Export INFOPATH so that the updated info pages can be found
  465. # and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info
  466. # When INFOPATH is unset, add a trailing colon so that Emacs
  467. # searches 'Info-default-directory-list'.
  468. export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"
  469. # GUIX_PROFILE: User's default profile and home profile
  470. GUIX_PROFILE="$HOME/.guix-profile"
  471. [ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
  472. [ -L "$GUIX_PROFILE" ] || \
  473. GUIX_LOCPATH="$GUIX_PROFILE/lib/locale:${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
  474. GUIX_PROFILE="$HOME/.guix-home/profile"
  475. [ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"
  476. [ -L "$GUIX_PROFILE" ] || \
  477. GUIX_LOCPATH="$GUIX_PROFILE/lib/locale:${GUIX_LOCPATH:+:}$GUIX_LOCPATH"
  478. export GUIX_LOCPATH
  479. EOF
  480. }
  481. sys_create_shell_completion()
  482. { # Symlink supported shell completions system-wide
  483. var_guix=/var/guix/profiles/per-user/root/current-guix
  484. bash_completion=/etc/bash_completion.d
  485. zsh_completion=/usr/share/zsh/site-functions
  486. fish_completion=/usr/share/fish/vendor_completions.d
  487. { # Just in case
  488. for dir_shell in $bash_completion $zsh_completion $fish_completion; do
  489. [ -d "$dir_shell" ] || mkdir -p $dir_shell
  490. done;
  491. ln -sf ${var_guix}/etc/bash_completion.d/* "$bash_completion";
  492. ln -sf ${var_guix}/share/zsh/site-functions/* "$zsh_completion";
  493. ln -sf ${var_guix}/share/fish/vendor_completions.d/* "$fish_completion"; } &&
  494. _msg "${PAS}installed shell completion"
  495. }
  496. sys_customize_bashrc()
  497. {
  498. prompt_yes_no "Customize users Bash shell prompt for Guix?" || return 0
  499. for bashrc in /home/*/.bashrc /root/.bashrc; do
  500. test -f "$bashrc" || continue
  501. grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
  502. cp "${bashrc}" "${bashrc}.bak"
  503. echo '
  504. # Automatically added by the Guix install script.
  505. if [ -n "$GUIX_ENVIRONMENT" ]; then
  506. if [[ $PS1 =~ (.*)"\\$" ]]; then
  507. PS1="${BASH_REMATCH[1]} [env]\\\$ "
  508. fi
  509. fi
  510. ' >> "$bashrc"
  511. done
  512. _msg "${PAS}Bash shell prompt successfully customized for Guix"
  513. }
  514. sys_maybe_setup_selinux()
  515. {
  516. if ! [ -f /sys/fs/selinux/policy ]
  517. then
  518. return
  519. fi
  520. local c
  521. for c in semodule restorecon
  522. do
  523. if ! command -v "$c" &>/dev/null
  524. then
  525. return
  526. fi
  527. done
  528. prompt_yes_no "Install SELinux policy that might be required to run guix-daemon?" \
  529. || return 0
  530. local var_guix=/var/guix/profiles/per-user/root/current-guix
  531. semodule -i "${var_guix}/share/selinux/guix-daemon.cil"
  532. restorecon -R /gnu /var/guix
  533. }
  534. welcome()
  535. {
  536. local char
  537. cat<<"EOF"
  538. ░░░ ░░░
  539. ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
  540. ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
  541. ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
  542. ░▒▒▒▒░ ░░░░░░
  543. ▒▒▒▒▒ ░░░░░░
  544. ▒▒▒▒▒ ░░░░░
  545. ░▒▒▒▒▒ ░░░░░
  546. ▒▒▒▒▒ ░░░░░
  547. ▒▒▒▒▒ ░░░░░
  548. ░▒▒▒▒▒░░░░░
  549. ▒▒▒▒▒▒░░░
  550. ▒▒▒▒▒▒░
  551. _____ _ _ _ _ _____ _
  552. / ____| \ | | | | | / ____| (_)
  553. | | __| \| | | | | | | __ _ _ ___ __
  554. | | |_ | . ' | | | | | | |_ | | | | \ \/ /
  555. | |__| | |\ | |__| | | |__| | |_| | |> <
  556. \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
  557. This script installs GNU Guix on your system
  558. https://www.gnu.org/software/guix/
  559. EOF
  560. # Don't use ‘read -p’ here! It won't display when run non-interactively.
  561. echo -n "Press return to continue..."$'\r'
  562. if ! read -r char; then
  563. echo
  564. die "Can't read standard input. Hint: don't pipe scripts into a shell."
  565. fi
  566. if [ "$char" ]; then
  567. echo
  568. echo "...that ($char) was not a return!"
  569. _msg "${WAR}Use newlines to automate installation, e.g.: yes '' | ${0##*/}"
  570. _msg "${WAR}Any other method is unsupported and likely to break in future."
  571. fi
  572. }
  573. main()
  574. {
  575. local tmp_path
  576. welcome
  577. _msg "Starting installation ($(date))"
  578. chk_term
  579. chk_require "${REQUIRE[@]}"
  580. chk_gpg_keyring
  581. chk_init_sys
  582. chk_sys_arch
  583. chk_sys_nscd
  584. _msg "${INF}system is ${ARCH_OS}"
  585. umask 0022
  586. tmp_path="$(mktemp -t -d guix.XXXXXX)"
  587. if [ -z "${GUIX_BINARY_FILE_NAME}" ]; then
  588. guix_get_bin_list "${GNU_URL}"
  589. guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
  590. GUIX_BINARY_FILE_NAME=${BIN_VER}.tar.xz
  591. else
  592. if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then
  593. _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting"
  594. fi
  595. _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}"
  596. GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME")
  597. fi
  598. sys_create_store "${GUIX_BINARY_FILE_NAME}" "${tmp_path}"
  599. sys_create_build_user
  600. sys_maybe_setup_selinux
  601. sys_enable_guix_daemon
  602. sys_authorize_build_farms
  603. sys_create_init_profile
  604. sys_create_shell_completion
  605. sys_customize_bashrc
  606. _msg "${INF}cleaning up ${tmp_path}"
  607. rm -r "${tmp_path}"
  608. _msg "${PAS}Guix has successfully been installed!"
  609. _msg "${INF}Run 'info guix' to read the manual."
  610. # Required to source /etc/profile in desktop environments.
  611. _msg "${INF}Please log out and back in to complete the installation."
  612. }
  613. main "$@"