Unverified Commit 72b15f17 authored by K900's avatar K900 Committed by GitHub
Browse files

treewide: rework Steam-shaped fhsenv building (#428815)

parents 0ea51b6a 6cc44487
Loading
Loading
Loading
Loading
+31 −31
Original line number Diff line number Diff line
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4

[[package]]
name = "anyhow"
version = "1.0.91"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"

[[package]]
name = "goblin"
version = "0.9.2"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53ab3f32d1d77146981dea5d6b1e8fe31eedcb7013e5e00d6ccd1259a4b4d923"
checksum = "0e961b33649994dcf69303af6b3a332c1228549e604d455d61ec5d2ab5e68d3a"
dependencies = [
 "log",
 "plain",
@@ -21,21 +21,21 @@ dependencies = [

[[package]]
name = "itoa"
version = "1.0.11"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"

[[package]]
name = "log"
version = "0.4.22"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"

[[package]]
name = "memchr"
version = "2.7.4"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"

[[package]]
name = "plain"
@@ -45,18 +45,18 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"

[[package]]
name = "proc-macro2"
version = "1.0.89"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.37"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
 "proc-macro2",
]
@@ -74,9 +74,9 @@ dependencies = [

[[package]]
name = "ryu"
version = "1.0.18"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"

[[package]]
name = "same-file"
@@ -89,18 +89,18 @@ dependencies = [

[[package]]
name = "scroll"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6"
checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add"
dependencies = [
 "scroll_derive",
]

[[package]]
name = "scroll_derive"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932"
checksum = "22fc4f90c27b57691bbaf11d8ecc7cfbfe98a4da6dbe60226115d322aa80c06e"
dependencies = [
 "proc-macro2",
 "quote",
@@ -109,18 +109,18 @@ dependencies = [

[[package]]
name = "serde"
version = "1.0.213"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.213"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
 "proc-macro2",
 "quote",
@@ -129,9 +129,9 @@ dependencies = [

[[package]]
name = "serde_json"
version = "1.0.132"
version = "1.0.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03"
checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
dependencies = [
 "itoa",
 "memchr",
@@ -141,9 +141,9 @@ dependencies = [

[[package]]
name = "syn"
version = "2.0.85"
version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [
 "proc-macro2",
 "quote",
@@ -152,9 +152,9 @@ dependencies = [

[[package]]
name = "unicode-ident"
version = "1.0.13"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"

[[package]]
name = "walkdir"
+29 −6
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ struct PriorityKey {
    root_index: usize,
}

const FHSENV_MARKER_FILE: &str = "nix-support/is-fhsenv";

fn build_reference_map(refs: Vec<RefGraphNode>) -> HashMap<PathBuf, Vec<PathBuf>> {
    refs.into_iter()
        .map(|mut gn| {
@@ -119,6 +121,11 @@ fn collect_candidate_paths(
    let mut candidates: HashMap<_, Vec<_>> = HashMap::new();

    for (path, priority) in paths {
        if path.join(FHSENV_MARKER_FILE).exists() {
            // is another fhsenv, skip it
            continue;
        }

        for entry in WalkDir::new(&path).follow_links(true) {
            let entry: PathBuf = match entry {
                Ok(ent) => {
@@ -134,7 +141,7 @@ fn collect_candidate_paths(
                        // could be a broken symlink, that's fine, we still want to handle those
                        Some(_) => e
                            .path()
                            .ok_or_else(|| anyhow!("I/O error when walking {path:?}"))?
                            .ok_or_else(|| anyhow!("I/O error when walking {}", path.display()))?
                            .into(),
                        None => {
                            // symlink loop
@@ -256,14 +263,30 @@ fn build_env(out: &Path, plan: HashMap<PathBuf, PathBuf>) -> anyhow::Result<()>
            .parent()
            .ok_or(anyhow!("destination directory is root"))
            .with_context(|| {
                format!("When trying to determine destination directory for {full_dest:?}")
                format!(
                    "When trying to determine destination directory for {}",
                    full_dest.display()
                )
            })?;
        fs::create_dir_all(dest_dir)
            .with_context(|| format!("When trying to create directory {dest_dir:?}"))?;
        ufs::symlink(&src, &full_dest)
            .with_context(|| format!("When symlinking {src:?} to {full_dest:?}"))?;
            .with_context(|| format!("When trying to create directory {}", dest_dir.display()))?;
        ufs::symlink(&src, &full_dest).with_context(|| {
            format!(
                "When symlinking {} to {}",
                src.display(),
                full_dest.display()
            )
        })?;
    }

    let marker = out.join(FHSENV_MARKER_FILE);
    fs::create_dir_all(
        marker
            .parent()
            .ok_or(anyhow!("marker file is in root, this should never happen"))?,
    )?;
    fs::write(marker, [])?;

    Ok(())
}

@@ -283,7 +306,7 @@ fn main() -> anyhow::Result<()> {

        paths = extend_to_closure(paths, &refs)?;
        paths32 = extend_to_closure(paths32, &refs)?;
    };
    }

    let plan = build_plan(paths, paths32)?;

+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
  legendary-heroic,
  nile,
  comet-gog,
  umu-launcher,
}:

let
@@ -90,6 +91,7 @@ stdenv.mkDerivation (finalAttrs: {
    makeWrapper "${electron}/bin/electron" "$out/bin/heroic" \
      --inherit-argv0 \
      --set ELECTRON_FORCE_IS_PACKAGED 1 \
      --suffix PATH ":" "${umu-launcher}/bin" \
      --add-flags --disable-gpu-compositing \
      --add-flags $out/opt/heroic/resources/app.asar \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
+5 −143
Original line number Diff line number Diff line
{
  buildFHSEnv,
  steam,
  heroic-unwrapped,
  extraPkgs ? pkgs: [ ],
  extraLibraries ? pkgs: [ ],
}:

buildFHSEnv {
steam.buildRuntimeEnv {
  pname = "heroic";
  inherit (heroic-unwrapped) version;
  inherit (heroic-unwrapped) version meta;

  runScript = "heroic";

  # Many Wine and native games need 32-bit libraries.
  multiArch = true;

  # required by Electron
  unshareIpc = false;

  targetPkgs =
    pkgs:
    with pkgs;
    [
      heroic-unwrapped
      gamemode
      curl
      gawk
      zenity
      kdePackages.kdialog
      mangohud
      net-tools
      opencl-headers
      p7zip
      pciutils
      perl
      psmisc
      python3
      umu-launcher
      unzip
      which
      xorg.xrandr
      zstd
    ]
    ++ extraPkgs pkgs;

  multiPkgs =
    let
      xorgDeps =
        pkgs: with pkgs.xorg; [
          libICE
          libpthreadstubs
          libSM
          libX11
          libXaw
          libxcb
          libXcomposite
          libXcursor
          libXdmcp
          libXext
          libXfixes
          libXi
          libXinerama
          libXmu
          libXrandr
          libXrender
          libXScrnSaver
          libXt
          libXtst
          libXv
          libXxf86vm
        ];
      gstreamerDeps =
        pkgs: with pkgs.gst_all_1; [
          gstreamer
          gst-plugins-base
          gst-plugins-good
          gst-plugins-ugly
          gst-plugins-bad
          gst-libav
        ];
    in
    pkgs:
    with pkgs;
    [
      alsa-lib
      alsa-plugins
      bash
      cabextract
      cairo
      coreutils
      cups
      dbus
      freealut
      freetype
      fribidi
      giflib
      glib
      gnutls
      gtk3
      icu
      lcms2
      libevdev
      libgcrypt
      libGLU
      libglvnd
      libgpg-error
      libgudev
      libjpeg
      libkrb5
      libmpeg2
      libogg
      libopus
      libpng
      libpulseaudio
      libselinux
      libsndfile
      libtheora
      libtiff
      libunwind
      libusb1
      libv4l
      libva
      libvdpau
      libvorbis
      libvpx
      libwebp
      libxkbcommon
      libxml2
      mpg123
      ncurses
      ocl-icd
      openal
      openldap
      openssl
      pango
      pipewire
      samba4
      sane-backends
      SDL2
      speex
      sqlite
      udev
      unixODBC
      util-linux
      vulkan-loader
      wayland
      zlib
    ]
    ++ xorgDeps pkgs
    ++ gstreamerDeps pkgs
    ++ extraLibraries pkgs;
  extraPkgs = pkgs: [ heroic-unwrapped ] ++ extraPkgs pkgs;
  inherit extraLibraries;

  extraInstallCommands = ''
    mkdir -p $out/share
    ln -s ${heroic-unwrapped}/share/applications $out/share
    ln -s ${heroic-unwrapped}/share/icons $out/share
  '';

  meta = heroic-unwrapped.meta;
}
+174 −144
Original line number Diff line number Diff line
@@ -13,21 +13,28 @@
  privateTmp ? true, # if the steam bubblewrap should isolate /tmp
}:
let
  steamEnv =
  buildRuntimeEnv =
    {
      name,
      runScript,
      passthru ? { },
      meta ? { },
    }:
    buildFHSEnv {
      inherit
        name
        runScript
        passthru
        meta
        privateTmp
        ;
      extraPkgs ? pkgs: [ ],
      extraLibraries ? pkgs: [ ],
      extraProfile ? "",
      extraPreBwrapCmds ? "",
      extraBwrapArgs ? [ ],
      extraEnv ? { },
      ...
    }@args:
    buildFHSEnv (
      (builtins.removeAttrs args [
        "extraPkgs"
        "extraLibraries"
        "extraProfile"
        "extraPreBwrapCmds"
        "extraBwrapArgs"
        "extraArgs"
        "extraEnv"
      ])
      // {
        inherit privateTmp;

        multiArch = true;
        includeClosures = true;
@@ -37,8 +44,6 @@ let
          pkgs:
          with pkgs;
          [
          steam-unwrapped

            bash
            coreutils
            file
@@ -86,10 +91,6 @@ let
          ]
          ++ extraLibraries pkgs;

      extraInstallCommands = lib.optionalString (steam-unwrapped != null) ''
        ln -s ${steam-unwrapped}/share $out/share
      '';

        profile = ''
          # prevents log spam from SteamRT GTK trying to load host GIO modules
          unset GIO_EXTRA_MODULES
@@ -135,18 +136,47 @@ let
          "--bind-try /tmp/dumps /tmp/dumps"
        ]
        ++ extraBwrapArgs;
    };
      }
    );
in
steamEnv {
  name = "steam";
buildRuntimeEnv {
  pname = "steam";
  inherit (steam-unwrapped) version meta;

  extraPkgs = pkgs: [ steam-unwrapped ] ++ extraPkgs pkgs;
  inherit
    extraLibraries
    extraProfile
    extraPreBwrapCmds
    extraBwrapArgs
    extraEnv
    ;

  runScript = writeShellScript "steam-wrapped" ''
    exec steam ${extraArgs} "$@"
  '';

  passthru.run = steamEnv {
  extraInstallCommands = ''
    ln -s ${steam-unwrapped}/share $out/share
  '';

  passthru =
    let
      makeSteamRun =
        package:
        buildRuntimeEnv {
          name = "steam-run";

          extraPkgs = pkgs: package ++ extraPkgs pkgs;

          inherit
            extraLibraries
            extraProfile
            extraPreBwrapCmds
            extraBwrapArgs
            extraEnv
            ;

          runScript = writeShellScript "steam-run" ''
            if [ $# -eq 0 ]; then
              echo "Usage: steam-run command-to-run args..." >&2
@@ -156,18 +186,18 @@ steamEnv {
            exec "$@"
          '';

    meta = (steam-unwrapped.meta or { }) // {
          meta = {
            description = "Run commands in the same FHS environment that is used for Steam";
            mainProgram = "steam-run";
            name = "steam-run";
      # steam-run itself is just a script that lives in nixpkgs (which is licensed under MIT).
      # steam is a dependency and already unfree, so normal steam-run will not install without
      # allowing unfree packages or appropriate `allowUnfreePredicate` rules.
            license = lib.licenses.mit;
          };
        };
    in
    {
      inherit buildRuntimeEnv;

  meta = (steam-unwrapped.meta or { }) // {
    description = "Steam dependencies (dummy package, do not use)";
      run = makeSteamRun [ steam-unwrapped ];
      run-free = makeSteamRun [ ];
    };
}
Loading