summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2015-02-05 18:12:14 +0300
committerNikolay Amiantov <ab@fmap.me>2015-02-05 19:46:00 +0300
commitb3ee378f5038886d08b2a17eb4ab5130ba7f77b8 (patch)
tree0916415746b35cca8090261c3855554304c79e93 /pkgs/build-support
parentb58dc94899aa26674f0a5c85ed5f302ae7825493 (diff)
downloadnixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar.gz
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar.bz2
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar.lz
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar.xz
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.tar.zst
nixpkgs-b3ee378f5038886d08b2a17eb4ab5130ba7f77b8.zip
buildFHSChrootEnv: split environment and chroot scripts
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/default.nix185
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/destroy.sh.in4
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/env.nix176
-rw-r--r--pkgs/build-support/build-fhs-chrootenv/init.sh.in6
4 files changed, 187 insertions, 184 deletions
diff --git a/pkgs/build-support/build-fhs-chrootenv/default.nix b/pkgs/build-support/build-fhs-chrootenv/default.nix
index a4ba456d7a5..8f24ab5e63c 100644
--- a/pkgs/build-support/build-fhs-chrootenv/default.nix
+++ b/pkgs/build-support/build-fhs-chrootenv/default.nix
@@ -1,97 +1,6 @@
-{ buildEnv, nixpkgs, nixpkgs_i686, system
-, stdenv, glibc, glibc_multi, glibcLocales
-, bashInteractive, coreutils, less, shadow, su
-, gawk, gcc, gcc_multi, diffutils, findutils, gnused, gnugrep
-, gnutar, gzip, bzip2, xz
-} :
-{ name, pkgs ? [], profile ? ""
-, targetPkgs ? null, multiPkgs ? null
-, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
-}:
-
-assert pkgs       != []   -> targetPkgs == null && multiPkgs == null;
-assert targetPkgs != null -> multiPkgs  != null;
-assert multiPkgs  != null -> targetPkgs != null;
-assert targetPkgs != null -> pkgs       == [];
-
-
-# HOWTO:
-# If pkgs is defined buildFHSChrootEnv will run in legacy mode. This means
-# it will build all pkgs contained in pkgs and basePkgs and then just merge
-# all of their contents together via buildEnv.
-#
-# The new way is to define both targetPkgs and multiPkgs. These two are
-# functions which get a pkgs environment supplied and should then return a list
-# of packages based this environment.
-# For example: targetPkgs = pkgs: [ pkgs.nmap ];
-#
-# All packages (most likeley programs) placed in targetPkgs will only be
-# installed once--matching the hosts architecture (64bit on x86_64 and 32bit on
-# x86). These packages will populate the chroot directory tree.
-#
-# Packages (most likeley libraries) defined in multiPkgs will be installed once
-# on x86 systems and twice on x86_64 systems.
-# On x86 they will just be merge with the packages defined in targetPkgs.
-# On x86_64 they will be added to targetPkgs and in addition their 32bit
-# versions will also be installed. The final directory should look as follows:
-# /lib will include 32bit libraries from multiPkgs
-# /lib32 will link to /lib
-# /lib64 will include 64bit libraries from multiPkgs and targetPkgs
-# /x86 will contain a complete 32bit environment composed by multiPkgs
+{ stdenv } : { env } :
 
 let
-  is64Bit       = system == "x86_64-linux";
-  # enable multi builds on x86_64 hosts if pakgs_target/multi are defined
-  isMultiBuild  = is64Bit && targetPkgs != null;
-  isTargetBuild = !isMultiBuild;
-
-  # list of packages (usually programs) which will only be installed for the
-  # hosts architecture
-  targetPaths = if targetPkgs == null
-                  then pkgs
-                  else targetPkgs nixpkgs ++ multiPkgs nixpkgs;
-
-  # list of pckages which should be build for both x86 and x86_64 on x86_64
-  # systems
-  multiPaths = if isMultiBuild
-                  then multiPkgs nixpkgs_i686
-                  else [];
-
-  # base packages of the chroot
-  # these match the hosts architecture, gcc/glibc_multi will be choosen
-  # on multi builds
-  choosenGcc = if isMultiBuild then gcc_multi else gcc;
-  basePkgs =
-    [ (if isMultiBuild then glibc_multi else glibc)
-      choosenGcc
-      bashInteractive coreutils less shadow su
-      gawk diffutils findutils gnused gnugrep
-      gnutar gzip bzip2 xz
-    ];
-
-  # Compose a global profile for the chroot environment
-  profilePkg = nixpkgs.stdenv.mkDerivation {
-    name         = "${name}-chrootenv-profile";
-    buildCommand = ''
-      mkdir -p $out/etc
-      cat >> $out/etc/profile << "EOF"
-      export PS1='${name}-chrootenv:\u@\h:\w\$ '
-      ${profile}
-      EOF
-    '';
-  };
-
-  # Composes a /usr like directory structure
-  staticUsrProfileTarget = buildEnv {
-    name = "system-profile-target";
-    paths = basePkgs ++ [ profilePkg ] ++ targetPaths;
-  };
-
-  staticUsrProfileMulti = buildEnv {
-    name = "system-profile-multi";
-    paths = multiPaths;
-  };
-
   # References to shell scripts that set up or tear down the environment
   initSh    = ./init.sh.in;
   mountSh   = ./mount.sh.in;
@@ -99,89 +8,15 @@ let
   umountSh  = ./umount.sh.in;
   destroySh = ./destroy.sh.in;
 
-  linkProfile = profile: ''
-    for i in ${profile}/{etc,bin,sbin,share,var}; do
-        if [ -x "$i" ]
-        then
-            ln -s "$i"
-        fi
-    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
-  # /lib64       -> links to 64bit binaries
-  # /usr/lib*    -> same as above
-  setupMultiProfile = if isTargetBuild then "" else ''
-    mkdir -m0755 x86
-    cd x86
-    ${linkProfile staticUsrProfileMulti}
-    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/
-  '';
-
-  # setup /lib, /lib32 and /lib64
-  setupLibDirs_multi = ''
-    mkdir -m0755 lib
-    mkdir -m0755 lib64
-    ln -s lib lib32
-
-    # copy glibc stuff
-    cp -rsf ${staticUsrProfileTarget}/lib/32/* lib/
-
-    # copy content of multiPaths (32bit libs)
-    cp -rsf ${staticUsrProfileMulti}/lib/* lib/
-
-    # copy content of targetPaths (64bit libs)
-    cp -rsf ${staticUsrProfileTarget}/lib/* lib64/
-
-    # most 64bit only libs put their stuff into /lib
-    # some pkgs (like gcc_multi) put 32bit libs into and /lib 64bit libs into /lib64
-    # by overwriting these we will hopefully catch all these cases
-    # in the end /lib should only contain 32bit and /lib64 only 64bit libs
-    cp -rsf ${staticUsrProfileTarget}/lib64/* lib64/
-
-    # copy gcc libs (and may overwrite exitsting wrongly placed libs)
-    cp -rsf ${choosenGcc.cc}/lib/*   lib/
-    cp -rsf ${choosenGcc.cc}/lib64/* lib64/
-  '';
+  name = env.pname;
 
 in stdenv.mkDerivation {
   name         = "${name}-chrootenv";
   buildCommand = ''
-    mkdir -p "$out/sw"
-    cd "$out/sw"
-    ${setupTargetProfile}
-    ${setupMultiProfile}
-    cd ..
+    mkdir -p $out/bin
+    cd $out/bin
 
-    mkdir -p bin
-    cd bin
-
-    sed -e "s|@chrootEnv@|$out|g" \
+    sed -e "s|@chrootEnv@|${env}|g" \
         -e "s|@name@|${name}|g" \
         -e "s|@shell@|${stdenv.shell}|g" \
         ${initSh} > init-${name}-chrootenv
@@ -202,18 +37,10 @@ in stdenv.mkDerivation {
         ${umountSh} > umount-${name}-chrootenv
     chmod +x umount-${name}-chrootenv
 
-    sed -e "s|@chrootEnv@|$out|g" \
+    sed -e "s|@chrootEnv@|${env}|g" \
         -e "s|@shell@|${stdenv.shell}|g" \
         -e "s|@name@|${name}|g" \
         ${destroySh} > destroy-${name}-chrootenv
     chmod +x destroy-${name}-chrootenv
-
-    cd ..
-
-    cd "$out/sw"
-    ${extraBuildCommands}
-    cd "$out/sw"
-    ${if isMultiBuild then extraBuildCommandsMulti else ""}
-    cd ..
   '';
 }
diff --git a/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in b/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in
index 8ddf350913e..015f742d85a 100644
--- a/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in
+++ b/pkgs/build-support/build-fhs-chrootenv/destroy.sh.in
@@ -6,9 +6,9 @@ chrootenvDest=/run/chrootenv/@name@
 rmdir $chrootenvDest/{dev,nix/store,nix,proc,sys,host-etc,home,var,run,tmp}
 
 # Remove symlinks to the software that should be part of the chroot system profile
-for i in @chrootEnv@/sw/*
+for i in @chrootEnv@/*
 do
-    if [ "$i" != "@chrootEnv@/sw/etc" ] && [ "$i" != "@chrootEnv@/sw/var" ]
+    if [ "$i" != "@chrootEnv@/etc" ] && [ "$i" != "@chrootEnv@/var" ]
     then
         rm $chrootenvDest/$(basename $i)
     fi
diff --git a/pkgs/build-support/build-fhs-chrootenv/env.nix b/pkgs/build-support/build-fhs-chrootenv/env.nix
new file mode 100644
index 00000000000..12c0fff7510
--- /dev/null
+++ b/pkgs/build-support/build-fhs-chrootenv/env.nix
@@ -0,0 +1,176 @@
+{ nixpkgs, nixpkgs_i686, system
+} :
+{ name, pkgs ? [], profile ? ""
+, targetPkgs ? null, multiPkgs ? null
+, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
+}:
+
+assert pkgs       != []   -> targetPkgs == null && multiPkgs == null;
+assert targetPkgs != null -> multiPkgs  != null;
+assert multiPkgs  != null -> targetPkgs != null;
+assert targetPkgs != null -> pkgs       == [];
+
+
+# HOWTO:
+# If pkgs is defined buildFHSEnv will run in legacy mode. This means
+# it will build all pkgs contained in pkgs and basePkgs and then just merge
+# all of their contents together via buildEnv.
+#
+# The new way is to define both targetPkgs and multiPkgs. These two are
+# functions which get a pkgs environment supplied and should then return a list
+# of packages based this environment.
+# For example: targetPkgs = pkgs: [ pkgs.nmap ];
+#
+# All packages (most likely programs) placed in targetPkgs will only be
+# installed once--matching the hosts architecture (64bit on x86_64 and 32bit on
+# x86). These packages will populate the chroot directory tree.
+#
+# Packages (most likeley libraries) defined in multiPkgs will be installed once
+# on x86 systems and twice on x86_64 systems.
+# On x86 they will just be merge with the packages defined in targetPkgs.
+# On x86_64 they will be added to targetPkgs and in addition their 32bit
+# versions will also be installed. The final directory should look as follows:
+# /lib will include 32bit libraries from multiPkgs
+# /lib32 will link to /lib
+# /lib64 will include 64bit libraries from multiPkgs and targetPkgs
+# /x86 will contain a complete 32bit environment composed by multiPkgs
+
+let
+  is64Bit       = system == "x86_64-linux";
+  # enable multi builds on x86_64 hosts if pakgs_target/multi are defined
+  isMultiBuild  = is64Bit && targetPkgs != null;
+  isTargetBuild = !isMultiBuild;
+
+  # list of packages (usually programs) which will only be installed for the
+  # hosts architecture
+  targetPaths = if targetPkgs == null
+                  then pkgs
+                  else targetPkgs nixpkgs ++ multiPkgs nixpkgs;
+
+  # list of pckages which should be build for both x86 and x86_64 on x86_64
+  # systems
+  multiPaths = if isMultiBuild
+                  then multiPkgs nixpkgs_i686
+                  else [];
+
+  # base packages of the chroot
+  # these match the hosts architecture, gcc/glibc_multi will be choosen
+  # on multi builds
+  chosenGcc = if isMultiBuild then nixpkgs.gcc_multi else nixpkgs.gcc;
+  basePkgs = with nixpkgs;
+    [ (if isMultiBuild then glibc_multi else glibc)
+      chosenGcc
+      bashInteractive coreutils less shadow su
+      gawk diffutils findutils gnused gnugrep
+      gnutar gzip bzip2 xz
+    ];
+
+  # Compose a global profile for the chroot environment
+  profilePkg = nixpkgs.stdenv.mkDerivation {
+    name         = "${name}-chrootenv-profile";
+    buildCommand = ''
+      mkdir -p $out/etc
+      cat >> $out/etc/profile << "EOF"
+      export PS1='${name}-chrootenv:\u@\h:\w\$ '
+      ${profile}
+      EOF
+    '';
+  };
+
+  # Composes a /usr like directory structure
+  staticUsrProfileTarget = nixpkgs.buildEnv {
+    name = "system-profile-target";
+    paths = basePkgs ++ [ profilePkg ] ++ targetPaths;
+  };
+
+  staticUsrProfileMulti = nixpkgs.buildEnv {
+    name = "system-profile-multi";
+    paths = multiPaths;
+  };
+
+  linkProfile = profile: ''
+    for i in ${profile}/{etc,bin,sbin,share,var}; do
+        if [ -x "$i" ]
+        then
+            ln -s "$i"
+        fi
+    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
+  # /lib64       -> links to 64bit binaries
+  # /usr/lib*    -> same as above
+  setupMultiProfile = if isTargetBuild then "" else ''
+    mkdir -m0755 x86
+    cd x86
+    ${linkProfile staticUsrProfileMulti}
+    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/
+  '';
+
+  # setup /lib, /lib32 and /lib64
+  setupLibDirs_multi = ''
+    mkdir -m0755 lib
+    mkdir -m0755 lib64
+    ln -s lib lib32
+
+    # copy glibc stuff
+    cp -rsf ${staticUsrProfileTarget}/lib/32/* lib/
+
+    # copy content of multiPaths (32bit libs)
+    cp -rsf ${staticUsrProfileMulti}/lib/* lib/
+
+    # copy content of targetPaths (64bit libs)
+    cp -rsf ${staticUsrProfileTarget}/lib/* lib64/
+
+    # most 64bit only libs put their stuff into /lib
+    # some pkgs (like gcc_multi) put 32bit libs into and /lib 64bit libs into /lib64
+    # by overwriting these we will hopefully catch all these cases
+    # in the end /lib should only contain 32bit and /lib64 only 64bit libs
+    cp -rsf ${staticUsrProfileTarget}/lib64/* lib64/
+
+    # copy gcc libs (and may overwrite exitsting wrongly placed libs)
+    cp -rsf ${chosenGcc.cc}/lib/*   lib/
+    cp -rsf ${chosenGcc.cc}/lib64/* lib64/
+  '';
+
+in nixpkgs.stdenv.mkDerivation {
+  name         = "${name}-fhs";
+  buildCommand = ''
+    mkdir -p $out
+    cd $out
+    ${setupTargetProfile}
+    ${setupMultiProfile}
+    cd $out
+    ${extraBuildCommands}
+    cd $out
+    ${if isMultiBuild then extraBuildCommandsMulti else ""}
+  '';
+  passthru = {
+    pname = name;
+  };
+}
diff --git a/pkgs/build-support/build-fhs-chrootenv/init.sh.in b/pkgs/build-support/build-fhs-chrootenv/init.sh.in
index 079ec09d60f..f3bdad85fa7 100644
--- a/pkgs/build-support/build-fhs-chrootenv/init.sh.in
+++ b/pkgs/build-support/build-fhs-chrootenv/init.sh.in
@@ -6,9 +6,9 @@ chrootenvDest=/run/chrootenv/@name@
 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@/sw/*
+for i in @chrootEnv@/*
 do
-    if [ "$i" != "@chrootEnv@/sw/etc" ] && [ "$i" != "@chrootEnv@/sw/var" ]
+    if [ "$i" != "@chrootEnv@/etc" ] && [ "$i" != "@chrootEnv@/var" ]
     then
         ln -s "$i" "$chrootenvDest"
     fi
@@ -18,7 +18,7 @@ done
 
 mkdir $chrootenvDest/etc
 
-for i in @chrootEnv@/sw/etc/*
+for i in @chrootEnv@/etc/*
 do
     ln -s "$i" $chrootenvDest/etc
 done