forked from mirrors/nixpkgs
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 }:
|
{ lib
|
||||||
|
, stdenv
|
||||||
args@{ name, profile ? ""
|
, runCommandLocal
|
||||||
, targetPkgs ? pkgs: [], multiPkgs ? pkgs: []
|
, buildEnv
|
||||||
, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
|
, writeText
|
||||||
, extraOutputsToInstall ? []
|
, writeShellScriptBin
|
||||||
|
, pkgs
|
||||||
|
, pkgsi686Linux
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
{ name ? null
|
||||||
|
, profile ? ""
|
||||||
|
, targetPkgs ? pkgs: []
|
||||||
|
, multiPkgs ? pkgs: []
|
||||||
|
, extraBuildCommands ? ""
|
||||||
|
, extraBuildCommandsMulti ? ""
|
||||||
|
, extraOutputsToInstall ? []
|
||||||
|
} @ args:
|
||||||
|
|
||||||
# HOWTO:
|
# HOWTO:
|
||||||
# All packages (most likely programs) returned from targetPkgs will only be
|
# 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
|
# installed once--matching the host's architecture (64bit on x86_64 and 32bit on
|
||||||
|
@ -78,9 +89,7 @@ let
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Compose /etc for the chroot environment
|
# Compose /etc for the chroot environment
|
||||||
etcPkg = stdenv.mkDerivation {
|
etcPkg = runCommandLocal "${name}-chrootenv-etc" { } ''
|
||||||
name = "${name}-chrootenv-etc";
|
|
||||||
buildCommand = ''
|
|
||||||
mkdir -p $out/etc
|
mkdir -p $out/etc
|
||||||
cd $out/etc
|
cd $out/etc
|
||||||
|
|
||||||
|
@ -90,7 +99,6 @@ let
|
||||||
# symlink /etc/mtab -> /proc/mounts (compat for old userspace progs)
|
# symlink /etc/mtab -> /proc/mounts (compat for old userspace progs)
|
||||||
ln -s /proc/mounts mtab
|
ln -s /proc/mounts mtab
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
|
|
||||||
# Composes a /usr-like directory structure
|
# Composes a /usr-like directory structure
|
||||||
staticUsrProfileTarget = buildEnv {
|
staticUsrProfileTarget = buildEnv {
|
||||||
|
@ -163,7 +171,8 @@ let
|
||||||
ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
|
ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
|
||||||
'';
|
'';
|
||||||
|
|
||||||
setupLibDirs = if isTargetBuild then setupLibDirsTarget
|
setupLibDirs = if isTargetBuild
|
||||||
|
then setupLibDirsTarget
|
||||||
else setupLibDirsMulti;
|
else setupLibDirsMulti;
|
||||||
|
|
||||||
# the target profile is the actual profile that will be used for the chroot
|
# the target profile is the actual profile that will be used for the chroot
|
||||||
|
@ -203,9 +212,11 @@ let
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in stdenv.mkDerivation {
|
in runCommandLocal "${name}-fhs" {
|
||||||
name = "${name}-fhs";
|
passthru = {
|
||||||
buildCommand = ''
|
inherit args multiPaths targetPaths;
|
||||||
|
};
|
||||||
|
} ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
cd $out
|
cd $out
|
||||||
${setupTargetProfile}
|
${setupTargetProfile}
|
||||||
|
@ -213,11 +224,4 @@ in stdenv.mkDerivation {
|
||||||
${extraBuildCommands}
|
${extraBuildCommands}
|
||||||
cd $out
|
cd $out
|
||||||
${lib.optionalString isMultiBuild extraBuildCommandsMulti}
|
${lib.optionalString isMultiBuild extraBuildCommandsMulti}
|
||||||
'';
|
''
|
||||||
preferLocalBuild = true;
|
|
||||||
allowSubstitutes = false;
|
|
||||||
|
|
||||||
passthru = {
|
|
||||||
inherit args multiPaths targetPaths;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
{ lib, callPackage, runCommandLocal, writeShellScriptBin, glibc, pkgsi686Linux, coreutils, bubblewrap }:
|
{ lib
|
||||||
|
, callPackage
|
||||||
|
, runCommandLocal
|
||||||
|
, writeShellScript
|
||||||
|
, glibc
|
||||||
|
, pkgsi686Linux
|
||||||
|
, coreutils
|
||||||
|
, bubblewrap
|
||||||
|
}:
|
||||||
|
|
||||||
args @ {
|
{ name ? null
|
||||||
name
|
, pname ? null
|
||||||
, version ? null
|
, version ? null
|
||||||
, runScript ? "bash"
|
, runScript ? "bash"
|
||||||
, extraInstallCommands ? ""
|
, extraInstallCommands ? ""
|
||||||
|
@ -16,16 +24,22 @@ args @ {
|
||||||
, unshareCgroup ? true
|
, unshareCgroup ? true
|
||||||
, dieWithParent ? 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;
|
with builtins;
|
||||||
let
|
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 { };
|
buildFHSEnv = callPackage ./buildFHSEnv.nix { };
|
||||||
|
|
||||||
fhsenv = buildFHSEnv (removeAttrs args [
|
fhsenv = buildFHSEnv (removeAttrs (args // { inherit name; }) [
|
||||||
"runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent"
|
"runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent"
|
||||||
"unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc"
|
"unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc"
|
||||||
"version"
|
"pname" "version"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
etcBindEntries = let
|
etcBindEntries = let
|
||||||
|
@ -93,7 +107,7 @@ let
|
||||||
EOF
|
EOF
|
||||||
ldconfig &> /dev/null
|
ldconfig &> /dev/null
|
||||||
'';
|
'';
|
||||||
init = run: writeShellScriptBin "${name}-init" ''
|
init = run: writeShellScript "${name}-init" ''
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
${createLdConfCache}
|
${createLdConfCache}
|
||||||
exec ${run} "$@"
|
exec ${run} "$@"
|
||||||
|
@ -198,18 +212,13 @@ let
|
||||||
"''${auto_mounts[@]}"
|
"''${auto_mounts[@]}"
|
||||||
"''${x11_args[@]}"
|
"''${x11_args[@]}"
|
||||||
${concatStringsSep "\n " extraBwrapArgs}
|
${concatStringsSep "\n " extraBwrapArgs}
|
||||||
${init runScript}/bin/${name}-init ${initArgs}
|
${init runScript} ${initArgs}
|
||||||
)
|
)
|
||||||
exec "''${cmd[@]}"
|
exec "''${cmd[@]}"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
bin = writeShellScriptBin name (bwrapCmd { initArgs = ''"$@"''; });
|
bin = writeShellScript "${name}-bwrap" (bwrapCmd { initArgs = ''"$@"''; });
|
||||||
|
in runCommandLocal name {
|
||||||
versionStr = lib.optionalString (version != null) ("-" + version);
|
|
||||||
|
|
||||||
nameAndVersion = name + versionStr;
|
|
||||||
|
|
||||||
in runCommandLocal nameAndVersion {
|
|
||||||
inherit meta;
|
inherit meta;
|
||||||
|
|
||||||
passthru = passthru // {
|
passthru = passthru // {
|
||||||
|
@ -225,6 +234,7 @@ in runCommandLocal nameAndVersion {
|
||||||
};
|
};
|
||||||
} ''
|
} ''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
ln -s ${bin}/bin/${name} $out/bin/${name}
|
ln -s ${bin} $out/bin/${pname}
|
||||||
|
|
||||||
${extraInstallCommands}
|
${extraInstallCommands}
|
||||||
''
|
''
|
||||||
|
|
|
@ -51,7 +51,8 @@ let
|
||||||
passthru = { inherit sources; };
|
passthru = { inherit sources; };
|
||||||
|
|
||||||
fhsUserEnvAnki = buildFHSUserEnv (appimageTools.defaultFhsEnvArgs // {
|
fhsUserEnvAnki = buildFHSUserEnv (appimageTools.defaultFhsEnvArgs // {
|
||||||
name = "anki";
|
inherit pname version;
|
||||||
|
name = null; # Appimage sets it to "appimage-env"
|
||||||
|
|
||||||
# Dependencies of anki
|
# Dependencies of anki
|
||||||
targetPkgs = pkgs: (with pkgs; [ xorg.libxkbfile krb5 ]);
|
targetPkgs = pkgs: (with pkgs; [ xorg.libxkbfile krb5 ]);
|
||||||
|
@ -61,6 +62,8 @@ let
|
||||||
'';
|
'';
|
||||||
|
|
||||||
extraInstallCommands = ''
|
extraInstallCommands = ''
|
||||||
|
ln -s ${pname} $out/bin/anki
|
||||||
|
|
||||||
mkdir -p $out/share
|
mkdir -p $out/share
|
||||||
cp -R ${unpacked}/share/applications \
|
cp -R ${unpacked}/share/applications \
|
||||||
${unpacked}/share/man \
|
${unpacked}/share/man \
|
||||||
|
@ -70,17 +73,9 @@ let
|
||||||
|
|
||||||
inherit meta passthru;
|
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
|
in
|
||||||
|
|
||||||
if stdenv.isLinux then fhsUserEnvAnkiWithVersion
|
if stdenv.isLinux then fhsUserEnvAnki
|
||||||
else stdenv.mkDerivation {
|
else stdenv.mkDerivation {
|
||||||
inherit pname version passthru;
|
inherit pname version passthru;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue