mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 07:23:20 +00:00
Merge pull request #225471 from Atemu/fhsenv-pname+version
buildFHSEnvBubblewrap: support pname + version
This commit is contained in:
commit
9f26295eaa
@ -1,11 +1,22 @@
|
||||
{ stdenv, lib, buildEnv, writeText, writeShellScriptBin, pkgs, pkgsi686Linux }:
|
||||
|
||||
args@{ name, profile ? ""
|
||||
, targetPkgs ? pkgs: [], multiPkgs ? pkgs: []
|
||||
, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
|
||||
, extraOutputsToInstall ? []
|
||||
{ lib
|
||||
, stdenv
|
||||
, runCommandLocal
|
||||
, buildEnv
|
||||
, writeText
|
||||
, writeShellScriptBin
|
||||
, pkgs
|
||||
, pkgsi686Linux
|
||||
}:
|
||||
|
||||
{ name ? null
|
||||
, profile ? ""
|
||||
, targetPkgs ? pkgs: []
|
||||
, multiPkgs ? pkgs: []
|
||||
, extraBuildCommands ? ""
|
||||
, extraBuildCommandsMulti ? ""
|
||||
, extraOutputsToInstall ? []
|
||||
} @ args:
|
||||
|
||||
# HOWTO:
|
||||
# All packages (most likely programs) returned from targetPkgs will only be
|
||||
# installed once--matching the host's architecture (64bit on x86_64 and 32bit on
|
||||
@ -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}
|
||||
''
|
||||
|
@ -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}
|
||||
''
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user