about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorArtturi <Artturin@artturin.com>2021-10-30 19:27:29 +0300
committerGitHub <noreply@github.com>2021-10-30 19:27:29 +0300
commit564ea1b19a8f44c4a57c7f02681d3911c623f3e5 (patch)
treecfc5921ff443b68409526ad8ef3f649bdb6350e8 /nixos
parent8a4bee574dbbb75eb9474e01f3b2c2f3f02811e8 (diff)
parent9145f833cc4050876fd8d0b93a37ca5114ea381c (diff)
downloadnixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar.gz
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar.bz2
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar.lz
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar.xz
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.tar.zst
nixlib-564ea1b19a8f44c4a57c7f02681d3911c623f3e5.zip
Merge pull request #137677 from Artturin/nixosenterresolv
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-enter.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/nixos/modules/installer/tools/nixos-enter.sh b/nixos/modules/installer/tools/nixos-enter.sh
index e57296b38e47..00883205e8b5 100644
--- a/nixos/modules/installer/tools/nixos-enter.sh
+++ b/nixos/modules/installer/tools/nixos-enter.sh
@@ -60,6 +60,35 @@ chmod 0755 "$mountPoint/dev" "$mountPoint/sys"
 mount --rbind /dev "$mountPoint/dev"
 mount --rbind /sys "$mountPoint/sys"
 
+# modified from https://github.com/archlinux/arch-install-scripts/blob/bb04ab435a5a89cd5e5ee821783477bc80db797f/arch-chroot.in#L26-L52
+chroot_add_resolv_conf() {
+    local chrootdir=$1 resolv_conf=$1/etc/resolv.conf
+
+    [[ -e /etc/resolv.conf ]] || return 0
+
+    # Handle resolv.conf as a symlink to somewhere else.
+    if [[ -L $chrootdir/etc/resolv.conf ]]; then
+      # readlink(1) should always give us *something* since we know at this point
+      # it's a symlink. For simplicity, ignore the case of nested symlinks.
+      # We also ignore the possibility if `../`s escaping the root.
+      resolv_conf=$(readlink "$chrootdir/etc/resolv.conf")
+      if [[ $resolv_conf = /* ]]; then
+        resolv_conf=$chrootdir$resolv_conf
+      else
+        resolv_conf=$chrootdir/etc/$resolv_conf
+      fi
+    fi
+
+    # ensure file exists to bind mount over
+    if [[ ! -f $resolv_conf ]]; then
+      install -Dm644 /dev/null "$resolv_conf" || return 1
+    fi
+
+    mount --bind /etc/resolv.conf "$resolv_conf"
+}
+
+chroot_add_resolv_conf "$mountPoint" || print "ERROR: failed to set up resolv.conf"
+
 (
     # If silent, write both stdout and stderr of activation script to /dev/null
     # otherwise, write both streams to stderr of this process