about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2015-03-09 17:13:27 +0300
committerNikolay Amiantov <ab@fmap.me>2015-03-09 17:29:43 +0300
commit4aba7639c898f66e91ee71f8ed6df1df14f2419d (patch)
tree002e79bca542296ee73850a6618ddeb1ba3612c5 /pkgs/build-support
parent95cd118d4f52aef3c0ef46e8f6e71e8e2daa84be (diff)
downloadnixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar.gz
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar.bz2
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar.lz
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar.xz
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.tar.zst
nixlib-4aba7639c898f66e91ee71f8ed6df1df14f2419d.zip
chroot-env: build /etc
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/env.nix37
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/init.sh.in29
-rwxr-xr-xpkgs/build-support/build-fhs-userenv/chroot-user.rb20
3 files changed, 37 insertions, 49 deletions
diff --git a/pkgs/build-support/build-fhs-chrootenv/env.nix b/pkgs/build-support/build-fhs-chrootenv/env.nix
index ee18f86893bb..19be38d1a01c 100644
--- a/pkgs/build-support/build-fhs-chrootenv/env.nix
+++ b/pkgs/build-support/build-fhs-chrootenv/env.nix
@@ -89,7 +89,7 @@ let
   };
 
   linkProfile = profile: ''
-    for i in ${profile}/{etc,bin,sbin,share,var}; do
+    for i in ${profile}/{bin,sbin,share,var}; do
         if [ -x "$i" ]
         then
             ln -s "$i"
@@ -158,6 +158,40 @@ 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
+
+    # 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
+
+    # symlink ALSA stuff
+    ln -s /host-etc/asound.conf etc/asound.conf
+  '';
+
 in nixpkgs.stdenv.mkDerivation {
   name         = "${name}-fhs";
   buildCommand = ''
@@ -165,6 +199,7 @@ in nixpkgs.stdenv.mkDerivation {
     cd $out
     ${setupTargetProfile}
     ${setupMultiProfile}
+    ${setupEtc}
     cd $out
     ${extraBuildCommands}
     cd $out
diff --git a/pkgs/build-support/build-fhs-chrootenv/init.sh.in b/pkgs/build-support/build-fhs-chrootenv/init.sh.in
index f3bdad85fa74..9078a31fe46a 100644
--- a/pkgs/build-support/build-fhs-chrootenv/init.sh.in
+++ b/pkgs/build-support/build-fhs-chrootenv/init.sh.in
@@ -8,39 +8,12 @@ mkdir -p $chrootenvDest/{nix/store,dev,proc,sys,host-etc,home,var,run}
 # Symlink the software that should be part of the chroot system profile
 for i in @chrootEnv@/*
 do
-    if [ "$i" != "@chrootEnv@/etc" ] && [ "$i" != "@chrootEnv@/var" ]
+    if [ "$i" != "@chrootEnv@/var" ]
     then
         ln -s "$i" "$chrootenvDest"
     fi
 done
 
-# Symlink the contents of the chroot software's /etc
-
-mkdir $chrootenvDest/etc
-
-for i in @chrootEnv@/etc/*
-do
-    ln -s "$i" $chrootenvDest/etc
-done
-
-# Symlink some NSS stuff
-ln -s ../host-etc/passwd $chrootenvDest/etc/passwd
-ln -s ../host-etc/group $chrootenvDest/etc/group
-ln -s ../host-etc/shadow $chrootenvDest/etc/shadow
-ln -s ../host-etc/hosts $chrootenvDest/etc/hosts
-ln -s ../host-etc/resolv.conf $chrootenvDest/etc/resolv.conf
-ln -s ../host-etc/nsswitch.conf $chrootenvDest/etc/nsswitch.conf
-
-# Symlink PAM stuff
-rm $chrootenvDest/etc/pam.d
-ln -s ../host-etc/static/pam.d $chrootenvDest/etc/pam.d
-
-# Symlink Font stuff
-mkdir -p $chrootenvDest/etc/fonts
-ln -s ../../host-etc/static/fonts/fonts.conf $chrootenvDest/etc/fonts
-mkdir -p $chrootenvDest/etc/fonts/conf.d
-ln -s ../../../host-etc/static/fonts/conf.d/00-nixos.conf $chrootenvDest/etc/fonts/conf.d
-
 # Create root folder
 mkdir $chrootenvDest/root
 
diff --git a/pkgs/build-support/build-fhs-userenv/chroot-user.rb b/pkgs/build-support/build-fhs-userenv/chroot-user.rb
index 857ccd58cd7f..7a066f1bc84f 100755
--- a/pkgs/build-support/build-fhs-userenv/chroot-user.rb
+++ b/pkgs/build-support/build-fhs-userenv/chroot-user.rb
@@ -17,20 +17,6 @@ mounts = [ ['/nix/store', nil],
 mkdirs = ['tmp',
          ]
 
-# Symlinks: [from, to (dir)]
-symlinks =
-  # /etc symlinks: [file name, prefix in host-etc]
-  [ ['passwd', ''],
-    ['group', ''],
-    ['shadow', ''],
-    ['hosts', ''],
-    ['resolv.conf', ''],
-    ['nsswitch.conf', ''],
-    ['pam.d', 'static'],
-    ['fonts/fonts.conf', 'static'],
-    ['fonts/conf.d/00-nixos.conf', 'static'],
-  ].map! { |x| [ "host-etc/#{x[1]}/#{x[0]}", "etc/#{File.dirname x[0]}" ] }
-
 require 'tmpdir'
 require 'fileutils'
 require 'pathname'
@@ -111,12 +97,6 @@ if $cpid == 0
   Dir.chroot root
   Dir.chdir '/'
 
-  # Do symlinks
-  symlinks.each do |x|
-    FileUtils.mkdir_p x[1]
-    FileUtils.ln_s x[0], x[1]
-  end
-
   # Symlink swdir hierarchy
   mount_dirs = Set.new mounts.map { |x| Pathname.new x[1] }
   link_swdir = lambda do |swdir, prefix|