summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-04-11 18:01:52 +0000
committerGitHub <noreply@github.com>2023-04-11 18:01:52 +0000
commit11441791466f71520d455927191034598afe5f3e (patch)
tree84188d08d0864ba579c1764b1bcc2befcaf0aba9 /pkgs/build-support
parente199e42538b15bd382344ffdfdb11ff15c5b60bd (diff)
parent4e2c1815ed1a40825c52e30dc993bf3a3c136104 (diff)
downloadnixpkgs-11441791466f71520d455927191034598afe5f3e.tar
nixpkgs-11441791466f71520d455927191034598afe5f3e.tar.gz
nixpkgs-11441791466f71520d455927191034598afe5f3e.tar.bz2
nixpkgs-11441791466f71520d455927191034598afe5f3e.tar.lz
nixpkgs-11441791466f71520d455927191034598afe5f3e.tar.xz
nixpkgs-11441791466f71520d455927191034598afe5f3e.tar.zst
nixpkgs-11441791466f71520d455927191034598afe5f3e.zip
Merge staging-next into staging
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix70
-rw-r--r--pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix42
2 files changed, 63 insertions, 49 deletions
diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix
index 0d98c0a2bc6..78da74c8284 100644
--- a/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix
+++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix
@@ -1,10 +1,21 @@
-{ stdenv, lib, buildEnv, writeText, writeShellScriptBin, pkgs, pkgsi686Linux }:
+{ lib
+, stdenv
+, runCommandLocal
+, buildEnv
+, writeText
+, writeShellScriptBin
+, pkgs
+, pkgsi686Linux
+}:
 
-args@{ name, profile ? ""
-, targetPkgs ? pkgs: [], multiPkgs ? pkgs: []
-, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
+{ name ? null
+, profile ? ""
+, targetPkgs ? pkgs: []
+, multiPkgs ? pkgs: []
+, extraBuildCommands ? ""
+, extraBuildCommandsMulti ? ""
 , extraOutputsToInstall ? []
-}:
+} @ args:
 
 # HOWTO:
 # All packages (most likely programs) returned from targetPkgs will only be
@@ -78,19 +89,16 @@ let
   '';
 
   # Compose /etc for the chroot environment
-  etcPkg = stdenv.mkDerivation {
-    name         = "${name}-chrootenv-etc";
-    buildCommand = ''
-      mkdir -p $out/etc
-      cd $out/etc
+  etcPkg = runCommandLocal "${name}-chrootenv-etc" { } ''
+    mkdir -p $out/etc
+    cd $out/etc
 
-      # environment variables
-      ln -s ${etcProfile} profile
+    # environment variables
+    ln -s ${etcProfile} profile
 
-      # symlink /etc/mtab -> /proc/mounts (compat for old userspace progs)
-      ln -s /proc/mounts mtab
-    '';
-  };
+    # symlink /etc/mtab -> /proc/mounts (compat for old userspace progs)
+    ln -s /proc/mounts mtab
+  '';
 
   # Composes a /usr-like directory structure
   staticUsrProfileTarget = buildEnv {
@@ -163,8 +171,9 @@ let
     ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
   '';
 
-  setupLibDirs = if isTargetBuild then setupLibDirsTarget
-                                  else setupLibDirsMulti;
+  setupLibDirs = if isTargetBuild
+                 then setupLibDirsTarget
+                 else setupLibDirsMulti;
 
   # the target profile is the actual profile that will be used for the chroot
   setupTargetProfile = ''
@@ -203,21 +212,16 @@ let
     done
   '';
 
-in stdenv.mkDerivation {
-  name         = "${name}-fhs";
-  buildCommand = ''
-    mkdir -p $out
-    cd $out
-    ${setupTargetProfile}
-    cd $out
-    ${extraBuildCommands}
-    cd $out
-    ${lib.optionalString isMultiBuild extraBuildCommandsMulti}
-  '';
-  preferLocalBuild = true;
-  allowSubstitutes = false;
-
+in runCommandLocal "${name}-fhs" {
   passthru = {
     inherit args multiPaths targetPaths;
   };
-}
+} ''
+  mkdir -p $out
+  cd $out
+  ${setupTargetProfile}
+  cd $out
+  ${extraBuildCommands}
+  cd $out
+  ${lib.optionalString isMultiBuild extraBuildCommandsMulti}
+''
diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
index ce807b932a1..5d94c309fe0 100644
--- a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
+++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
@@ -1,7 +1,15 @@
-{ lib, callPackage, runCommandLocal, writeShellScriptBin, glibc, pkgsi686Linux, coreutils, bubblewrap }:
+{ lib
+, callPackage
+, runCommandLocal
+, writeShellScript
+, glibc
+, pkgsi686Linux
+, coreutils
+, bubblewrap
+}:
 
-args @ {
-  name
+{ name ? null
+, pname ? null
 , version ? null
 , runScript ? "bash"
 , extraInstallCommands ? ""
@@ -16,16 +24,22 @@ args @ {
 , unshareCgroup ? true
 , dieWithParent ? true
 , ...
-}:
+} @ args:
+
+assert (pname != null || version != null) -> (name == null && pname != null); # You must declare either a name or pname + version (preferred).
 
 with builtins;
 let
+  pname = if args.name != null then args.name else args.pname;
+  versionStr = lib.optionalString (version != null) ("-" + version);
+  name = pname + versionStr;
+
   buildFHSEnv = callPackage ./buildFHSEnv.nix { };
 
-  fhsenv = buildFHSEnv (removeAttrs args [
+  fhsenv = buildFHSEnv (removeAttrs (args // { inherit name; }) [
     "runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent"
     "unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc"
-    "version"
+    "pname" "version"
   ]);
 
   etcBindEntries = let
@@ -93,7 +107,7 @@ let
     EOF
     ldconfig &> /dev/null
   '';
-  init = run: writeShellScriptBin "${name}-init" ''
+  init = run: writeShellScript "${name}-init" ''
     source /etc/profile
     ${createLdConfCache}
     exec ${run} "$@"
@@ -198,18 +212,13 @@ let
       "''${auto_mounts[@]}"
       "''${x11_args[@]}"
       ${concatStringsSep "\n  " extraBwrapArgs}
-      ${init runScript}/bin/${name}-init ${initArgs}
+      ${init runScript} ${initArgs}
     )
     exec "''${cmd[@]}"
   '';
 
-  bin = writeShellScriptBin name (bwrapCmd { initArgs = ''"$@"''; });
-
-  versionStr = lib.optionalString (version != null) ("-" + version);
-
-  nameAndVersion = name + versionStr;
-
-in runCommandLocal nameAndVersion {
+  bin = writeShellScript "${name}-bwrap" (bwrapCmd { initArgs = ''"$@"''; });
+in runCommandLocal name {
   inherit meta;
 
   passthru = passthru // {
@@ -225,6 +234,7 @@ in runCommandLocal nameAndVersion {
   };
 } ''
   mkdir -p $out/bin
-  ln -s ${bin}/bin/${name} $out/bin/${name}
+  ln -s ${bin} $out/bin/${pname}
+
   ${extraInstallCommands}
 ''