From 460c0d608f40f54776bb401c601ff96b9ec426d0 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Sun, 14 Jun 2020 20:04:41 -0700 Subject: [PATCH] nixos-install: error out if $mountPoint has bad permissions The nix store more-or-less requires o+rx on all parent directories. This is primarily because nix runs builders in a uid/gid mapped user-namespace, and those builders have to be able to operate on the nix store. This check is especially helpful because nix does not produce a helpful error on its own (rather, creating directories and such works, it's not until 'mount --bind' that it gets an EACCES). Helps users who run into this opaque error, such as in #67465. Possibly fixes that issue if bad permissions were the only cause. --- nixos/modules/installer/tools/nixos-install.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh index 1bccbbfaf24..0b62bca8367 100644 --- a/nixos/modules/installer/tools/nixos-install.sh +++ b/nixos/modules/installer/tools/nixos-install.sh @@ -71,6 +71,17 @@ if ! test -e "$mountPoint"; then exit 1 fi +# Verify permissions are okay-enough +checkPath="$(realpath "$mountPoint")" +while [[ "$checkPath" != "/" ]]; do + mode="$(stat -c '%a' "$checkPath")" + if [[ "${mode: -1}" -lt "5" ]]; then + echo "path $checkPath should have permissions 755, but had permissions $mode. Consider running 'chmod o+rx $checkPath'." + exit 1 + fi + checkPath="$(dirname "$checkPath")" +done + # Get the path of the NixOS configuration file. if [[ -z $NIXOS_CONFIG ]]; then NIXOS_CONFIG=$mountPoint/etc/nixos/configuration.nix