summary refs log tree commit diff
path: root/pkgs/build-support/build-fhs-chrootenv/env.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/build-fhs-chrootenv/env.nix')
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/env.nix106
1 files changed, 52 insertions, 54 deletions
diff --git a/pkgs/build-support/build-fhs-chrootenv/env.nix b/pkgs/build-support/build-fhs-chrootenv/env.nix
index d80e2869e5e..b659655f74b 100644
--- a/pkgs/build-support/build-fhs-chrootenv/env.nix
+++ b/pkgs/build-support/build-fhs-chrootenv/env.nix
@@ -65,25 +65,56 @@ let
       gnutar gzip bzip2 xz glibcLocales
     ];
 
-  # Compose a global profile for the chroot environment
-  profilePkg = nixpkgs.stdenv.mkDerivation {
-    name         = "${name}-chrootenv-profile";
+  # Compose /etc for the chroot environment
+  etcPkg = nixpkgs.stdenv.mkDerivation {
+    name         = "${name}-chrootenv-etc";
     buildCommand = ''
       mkdir -p $out/etc
-      cat >> $out/etc/profile << "EOF"
+      cd $out/etc
+
+      # environment variables
+      cat >> profile << "EOF"
       export PS1='${name}-chrootenv:\u@\h:\w\$ '
       export LOCALE_ARCHIVE='/usr/lib${if is64Bit then "64" else ""}/locale/locale-archive'
       export LD_LIBRARY_PATH=/run/opengl-driver/lib:/run/opengl-driver-32/lib:/lib:/lib32:/lib64
       export PATH='/bin:/sbin'
       ${profile}
       EOF
+
+      # compatibility with NixOS
+      ln -s /host-etc/static static
+
+      # symlink some NSS stuff
+      ln -s /host-etc/passwd passwd
+      ln -s /host-etc/group group
+      ln -s /host-etc/shadow shadow
+      ln -s /host-etc/hosts hosts
+      ln -s /host-etc/resolv.conf resolv.conf
+      ln -s /host-etc/nsswitch.conf nsswitch.conf
+
+      # symlink other core stuff
+      ln -s /host-etc/localtime localtime
+      ln -s /host-etc/machine-id machine-id
+
+      # symlink PAM stuff
+      ln -s /host-etc/pam.d pam.d
+
+      # symlink fonts stuff
+      ln -s /host-etc/fonts fonts
+
+      # symlink ALSA stuff
+      ln -s /host-etc/asound.conf asound.conf
+
+      # symlink SSL certs
+      mkdir -p ssl
+      ln -s /host-etc/ssl/certs ssl/certs
     '';
   };
 
   # Composes a /usr like directory structure
   staticUsrProfileTarget = nixpkgs.buildEnv {
-    name = "system-profile-target";
-    paths = basePkgs ++ [ profilePkg ] ++ targetPaths;
+    name = "${name}-usr-target";
+    paths = [ etcPkg ] ++ basePkgs ++ targetPaths;
     ignoreCollisions = true;
   };
 
@@ -94,7 +125,7 @@ let
   };
 
   linkProfile = profile: ''
-    for i in ${profile}/{bin,sbin,share,var}; do
+    for i in ${profile}/{bin,sbin,share,var,etc}; do
         if [ -x "$i" ]
         then
             ln -s "$i"
@@ -102,18 +133,6 @@ let
     done
   '';
 
-  # the target profile is the actual profile that will be used for the chroot
-  setupTargetProfile = ''
-    ${linkProfile staticUsrProfileTarget}
-    ${setupLibDirs}
-
-    mkdir -m0755 usr
-    cd usr
-    ${linkProfile staticUsrProfileTarget}
-    ${setupLibDirs}
-    cd ..
-  '';
-
   # this will happen on x86_64 host:
   # /x86         -> links to the whole profile defined by multiPaths
   # /lib, /lib32 -> links to 32bit binaries
@@ -126,15 +145,12 @@ let
     cd ..
   '';
 
-  setupLibDirs = if isTargetBuild then setupLibDirs_target
-                                  else setupLibDirs_multi;
-
   # setup library paths only for the targeted architecture
   setupLibDirs_target = ''
     mkdir -m0755 lib
 
     # copy content of targetPaths
-    cp -rsf ${staticUsrProfileTarget}/lib/* lib/ && chmod u+w -R lib/
+    cp -rsf ${staticUsrProfileTarget}/lib/* lib/
   '';
 
   # setup /lib, /lib32 and /lib64
@@ -144,7 +160,7 @@ let
     ln -s lib lib32
 
     # copy glibc stuff
-    cp -rsf ${staticUsrProfileTarget}/lib/32/* lib/
+    cp -rsf ${staticUsrProfileTarget}/lib/32/* lib/ && chmod u+w -R lib/
 
     # copy content of multiPaths (32bit libs)
     [ -d ${staticUsrProfileMulti}/lib ] && cp -rsf ${staticUsrProfileMulti}/lib/* lib/ && chmod u+w -R lib/
@@ -163,38 +179,21 @@ let
     cp -rsf ${chosenGcc.cc}/lib64/* lib64/
   '';
 
-  setupEtc = ''
-    mkdir -m0755 etc
-
-    # copy profile content
-    cp -rsf ${staticUsrProfileTarget}/etc/* etc/ && chmod u+w -R etc/
-    [ -d ${staticUsrProfileMulti}/etc ] && cp -rsf ${staticUsrProfileMulti}/etc/* etc/ && chmod u+w -R etc/
-
-    # compatibility with NixOS
-    ln -s /host-etc/static etc/static
-
-    # symlink some NSS stuff
-    ln -s /host-etc/passwd etc/passwd
-    ln -s /host-etc/group etc/group
-    ln -s /host-etc/shadow etc/shadow
-    ln -s /host-etc/hosts etc/hosts
-    ln -s /host-etc/resolv.conf etc/resolv.conf
-    ln -s /host-etc/nsswitch.conf etc/nsswitch.conf
-
-    # symlink other core stuff
-    ln -s /host-etc/localtime etc/localtime
-    ln -s /host-etc/machine-id etc/machine-id
+  setupLibDirs = if isTargetBuild then setupLibDirs_target
+                                  else setupLibDirs_multi;
 
-    # symlink PAM stuff
-    rm -rf etc/pam.d
-    ln -s /host-etc/pam.d etc/pam.d
 
-    # symlink fonts stuff
-    rm -rf etc/fonts
-    ln -s /host-etc/fonts etc/fonts
+  # the target profile is the actual profile that will be used for the chroot
+  setupTargetProfile = ''
+    ${linkProfile staticUsrProfileTarget}
+    ${setupLibDirs}
 
-    # symlink ALSA stuff
-    ln -s /host-etc/asound.conf etc/asound.conf
+    mkdir -m0755 usr
+    cd usr
+    ${linkProfile staticUsrProfileTarget}
+    ${setupLibDirs}
+    cd ..
+    rm -rf usr/etc usr/var
   '';
 
 in nixpkgs.stdenv.mkDerivation {
@@ -204,7 +203,6 @@ in nixpkgs.stdenv.mkDerivation {
     cd $out
     ${setupTargetProfile}
     ${setupMultiProfile}
-    ${setupEtc}
     cd $out
     ${extraBuildCommands}
     cd $out