Unverified Commit 9f26295e authored by Atemu's avatar Atemu Committed by GitHub
Browse files

Merge pull request #225471 from Atemu/fhsenv-pname+version

buildFHSEnvBubblewrap: support pname + version
parents 3fb8eedc 7a1de489
Loading
Loading
Loading
Loading
+37 −33
Original line number Diff line number Diff line
{ 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,9 +89,7 @@ let
  '';

  # Compose /etc for the chroot environment
  etcPkg = stdenv.mkDerivation {
    name         = "${name}-chrootenv-etc";
    buildCommand = ''
  etcPkg = runCommandLocal "${name}-chrootenv-etc" { } ''
    mkdir -p $out/etc
    cd $out/etc

@@ -90,7 +99,6 @@ let
    # symlink /etc/mtab -> /proc/mounts (compat for old userspace progs)
    ln -s /proc/mounts mtab
  '';
  };

  # Composes a /usr-like directory structure
  staticUsrProfileTarget = buildEnv {
@@ -163,7 +171,8 @@ let
    ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
  '';

  setupLibDirs = if isTargetBuild then setupLibDirsTarget
  setupLibDirs = if isTargetBuild
                 then setupLibDirsTarget
                 else setupLibDirsMulti;

  # the target profile is the actual profile that will be used for the chroot
@@ -203,9 +212,11 @@ let
    done
  '';

in stdenv.mkDerivation {
  name         = "${name}-fhs";
  buildCommand = ''
in runCommandLocal "${name}-fhs" {
  passthru = {
    inherit args multiPaths targetPaths;
  };
} ''
  mkdir -p $out
  cd $out
  ${setupTargetProfile}
@@ -213,11 +224,4 @@ in stdenv.mkDerivation {
  ${extraBuildCommands}
  cd $out
  ${lib.optionalString isMultiBuild extraBuildCommandsMulti}
  '';
  preferLocalBuild = true;
  allowSubstitutes = false;

  passthru = {
    inherit args multiPaths targetPaths;
  };
}
''
+26 −16
Original line number Diff line number Diff line
{ 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}
''
+5 −10
Original line number Diff line number Diff line
@@ -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;