diff options
author | Atemu <atemu.main@gmail.com> | 2023-04-11 15:35:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 15:35:43 +0200 |
commit | 9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0 (patch) | |
tree | 86f30ae6ce1e83e4814f8d7abe8a80cccb0048d9 | |
parent | 3fb8eedc450286d5092e4953118212fa21091b3b (diff) | |
parent | 7a1de48994dadc3ce94f06f9a3a0f41775751f81 (diff) | |
download | nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar.gz nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar.bz2 nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar.lz nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar.xz nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.tar.zst nixpkgs-9f26295eaa6763f1da4fa7f4f54fb8fb78ed9ec0.zip |
Merge pull request #225471 from Atemu/fhsenv-pname+version
buildFHSEnvBubblewrap: support pname + version
-rw-r--r-- | pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix | 70 | ||||
-rw-r--r-- | pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix | 42 | ||||
-rw-r--r-- | pkgs/games/anki/bin.nix | 15 |
3 files changed, 68 insertions, 59 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} '' diff --git a/pkgs/games/anki/bin.nix b/pkgs/games/anki/bin.nix index 552581a8084..39b10bcb15c 100644 --- a/pkgs/games/anki/bin.nix +++ b/pkgs/games/anki/bin.nix @@ -51,7 +51,8 @@ let passthru = { inherit sources; }; fhsUserEnvAnki = buildFHSUserEnv (appimageTools.defaultFhsEnvArgs // { - name = "anki"; + inherit pname version; + name = null; # Appimage sets it to "appimage-env" # Dependencies of anki targetPkgs = pkgs: (with pkgs; [ xorg.libxkbfile krb5 ]); @@ -61,6 +62,8 @@ let ''; extraInstallCommands = '' + ln -s ${pname} $out/bin/anki + mkdir -p $out/share cp -R ${unpacked}/share/applications \ ${unpacked}/share/man \ @@ -70,17 +73,9 @@ let inherit meta passthru; }); - - fhsUserEnvAnkiWithVersion = fhsUserEnvAnki.overrideAttrs (oldAttrs: { - # buildFHSUserEnv doesn't have an easy way to set the version of the - # resulting derivation, so we manually override it here. This makes - # it clear to end users the version of anki-bin. Without this, users - # might assume anki-bin is an old version of Anki. - name = "${pname}-${version}"; - }); in -if stdenv.isLinux then fhsUserEnvAnkiWithVersion +if stdenv.isLinux then fhsUserEnvAnki else stdenv.mkDerivation { inherit pname version passthru; |