Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS support #252

Open
ValdemarGr opened this issue Dec 3, 2024 · 6 comments
Open

NixOS support #252

ValdemarGr opened this issue Dec 3, 2024 · 6 comments

Comments

@ValdemarGr
Copy link

ValdemarGr commented Dec 3, 2024

Nix's default steam package comes with a default steam-run launcher that ensures all needed dependencies are present to run steam-related applications, such as v2_entry-point.

There are some possible solutions I have thought of:

  1. Add documentation note to the README about steam-run for nix users.
  2. Do the nix detection in the game-launcher part, however this requires that the ELF header is patched in the binary (noita_proxy) and as such is best served as a third-party nix derivation.

The first one is significantly simpler if you're okay with adding a sub-section to the README. I can do a PR.

@IntQuant
Copy link
Owner

IntQuant commented Dec 3, 2024

Would it be possible to do Nix detection in a different way, like compiling with a specific env variable set, and then adjusting the start command automatically?

@ValdemarGr
Copy link
Author

Yes, however the released package would have to be released as a nix flake, not a compiled binary.

Why does it have to be a nix package instead of a binary?

For instance, on a normal nixos system this is the case:
image

That is, dynamic libraries are disallowed. Most tools for building nix packages patch these parts of the binary to point to the exact library version and so on, such that the binary runs with the same libraries for all machines. So if you want a binary compiled specifically for nix, it needs to be declared in nix so it also ensures the right libraries will be present on the right paths.

Solution proposal

I have already created a "nix package" that compiles and patches the binary (although patching the binary distributed on github might be enough). So if the code can be adjusted to account for running in a "nix environment" then I suppose such a solution could also work. Wouldn't be easier if the nix package came with it's own --launch-cmd instead of modifying the code?

/nix/store/321dcba-noita-proxy-launcher:

/nix/store/abcd123-noita-proxy/noita_proxy --launch-cmd "$CUSTOM_NIX_LAUNCHER" $@

@bgkillas
Copy link
Collaborator

bgkillas commented Dec 4, 2024

this sounds like a reasonable thing, so we don't need to do anything our side if i understand correctly?

@ValdemarGr
Copy link
Author

this sounds like a reasonable thing, so we don't need to do anything our side if i understand correctly?

Yes. And maybe also adding some reference to such a nix package for nix users that visit the project.

@bgkillas
Copy link
Collaborator

bgkillas commented Dec 7, 2024

whats the link to the nix package?

@YellowOnion
Copy link

YellowOnion commented Dec 20, 2024

Nix binaries aren't compatible with FHS Linux distros so you can't patch the one supplied here without breaking it for everyone else.

I'm not sure what the actual problem described here is, so not sure why you need --launch-cmd "$CUSTOM_NIX_LAUNCHER".

I had a quick look at the code, and it only searches for Steam / proton, those playing via GOG could also be using wine or a launcher for wine like lutris, so maybe that would be a use case for a flag like this.

With that being said, steam-run does work fine here, and it's basically expected for your average nix user to know about using steam-run for non-nix packaged binaries.

Something worth noting is that the app seems to save data in the same directory as the binary[1], this won't work for packaging as most linux distros install apps in read-only directories.

Something like this should build the package:

{ lib, fetchFromGitHub, rustPlatform, python3, wayland, xorg, libxkbcommon, libGL }:

rustPlatform.buildRustPackage rec {
  pname = "noita_entangled_worlds";
  version = "v0.32.6";

  src = fetchFromGitHub {
    owner = "IntQuant";
    repo = pname;
    rev = version;
    hash = "sha256-fpj4vBhMws3o3Gs/hq94+ITd4AtuKoVHnAlt/PWwLIU=";
  };

  sourceRoot = "source/noita-proxy";
  cargoHash = "sha256-AMnI0mvSuEDRPolcBgR6aCXaiRgMn1qpWjlksLjhvwQ=";

  # tests fail due to no internet
  doCheck = false;

  nativeBuildInputs = [ python3 ];
  buildInputs = [
            libxkbcommon
            libGL

            # WINIT_UNIX_BACKEND=wayland
            wayland

            # WINIT_UNIX_BACKEND=x11
            xorg.libXcursor
            xorg.libXrandr
            xorg.libXi
            xorg.libX11
  ];

  postInstall = ''
    mkdir -p $out/lib
    cp $src/redist/libsteam_api.so $out/lib/libsteam_api.so
  '';

  postFixup = ''
    patchelf --add-rpath "${lib.makeLibraryPath buildInputs}" $out/bin/noita-proxy
  '';
  meta = {
    description = "Noita Co-op multiplayer mod";
    homepage = "https://github.com/IntQuant/noita_entangled_worlds";
    license = lib.licenses.mit;
    maintainers = [ ];
  };
}

Error log:

2024-12-20T12:13:35.938413Z ERROR noita_proxy::bookkeeping::save_state: Error while creating directories: Read-only file system (os error 30)
2024-12-20T12:13:35.938421Z  INFO noita_proxy::bookkeeping::save_state: Will save to: /nix/store/dixdcfs7qqyhd8pp58qxqhp29vy92ssc-noita_entangled_worlds-v0.32.6/bin/save_state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants