diff --git a/.gitignore b/.gitignore index c96293a2..c100688b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,8 @@ save_state /quant.ew/ewext0.dll /quant.ew/ewext1.dll /blob_guy/blob_guy/blob_guy.dll -/blob_guy/target \ No newline at end of file +/blob_guy/target + +# Nix +/result +/result-man diff --git a/flake.nix b/flake.nix index 2a264d62..95cd1fd7 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,11 @@ in { overlays = import ./nix/overlays { inherit self lib rust-overlay; }; + packages = lib.mapAttrs (system: pkgs: { + default = self.packages.${system}.noita-proxy; + inherit (pkgs) noita-proxy; + }) pkgsFor; + devShells = lib.mapAttrs (system: pkgs: { default = pkgs.callPackage ./nix/shell.nix { }; }) pkgsFor; diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix index 43d90f12..102bf0e5 100644 --- a/nix/overlays/default.nix +++ b/nix/overlays/default.nix @@ -1,9 +1,14 @@ -{ self, lib, rust-overlay }: { +{ self, lib, rust-overlay }: +let rustPackageOverlay = import ./rust-package.nix; +in { default = lib.composeManyExtensions [ # This is to ensure that other overlays and invocations of `callPackage` # receive `rust-bin`, but without hard-coding a specific derivation. # This can be overridden by consumers. self.overlays.rust-overlay + + # Packages provided by this flake: + self.overlays.noita-proxy ]; # This flake exposes `overlays.rust-overlay` which is automatically applied @@ -11,4 +16,12 @@ # the package overlay, in the event it is not already present. rust-overlay = final: prev: if prev ? rust-bin then { } else rust-overlay.overlays.default final prev; + + # The overlay definition uses `rust-bin` to construct a `rustPlatform`, + # and `rust-bin` is not provided by this particular overlay. + # Prefer using `overlays.default`, or composing with `rust-overlay` manually. + noita-proxy = rustPackageOverlay { + packageName = "noita-proxy"; + sourceRoot = self; + }; } diff --git a/nix/overlays/rust-package.nix b/nix/overlays/rust-package.nix new file mode 100644 index 00000000..7d5c1bf5 --- /dev/null +++ b/nix/overlays/rust-package.nix @@ -0,0 +1,20 @@ +# This function is imported as `rustPackageOverlay` in `nix/overlays/default.nix`. +# +# Supplies a stable `rustPlatform` from `rust-bin` to `callPackage`. +# The `rust-overlay` must have already been composed onto the `pkgs` set. +# +# This prevents `rust-bin` from being an input of the package, which would +# make it less portable. +{ packageName, sourceRoot }: +final: _prev: +let + rust-stable = final.rust-bin.stable.latest.minimal; + rustPlatform = final.makeRustPlatform { + cargo = rust-stable; + rustc = rust-stable; + }; +in { + ${packageName} = final.callPackage "${../packages}/${packageName}.nix" { + inherit sourceRoot rustPlatform; + }; +} diff --git a/nix/packages/noita-proxy.nix b/nix/packages/noita-proxy.nix new file mode 100644 index 00000000..6969a178 --- /dev/null +++ b/nix/packages/noita-proxy.nix @@ -0,0 +1,68 @@ +{ sourceRoot, lib, runCommandNoCC, rustPlatform, pkg-config, cmake, patchelf +, openssl, libjack2, alsa-lib, libopus, wayland, libxkbcommon, libGL }: + +rustPlatform.buildRustPackage (finalAttrs: + let + inherit (finalAttrs) src pname version buildInputs steamworksRedist; + manifest = lib.importTOML "${src}/noita-proxy/Cargo.toml"; + in { + pname = "noita-entangled-worlds-proxy"; + inherit (manifest.package) version; + + # The real root of the entire project. + # This is the only place `sourceRoot` is used. + src = sourceRoot; + # The root of this particular binary crate to build. + sourceRoot = "source/noita-proxy"; + + cargoLock.lockFile = "${src}/noita-proxy/Cargo.lock"; + + strictDeps = true; + nativeBuildInputs = [ pkg-config cmake patchelf ]; + + # TODO: Add dependencies for X11 desktop environments. + buildInputs = [ + openssl + libjack2 + alsa-lib + libopus + wayland + libxkbcommon + libGL + steamworksRedist + ]; + + env = { + OPENSSL_DIR = "${lib.getDev openssl}"; + OPENSSL_LIB_DIR = "${lib.getLib openssl}/lib"; + OPENSSL_NO_VENDOR = 1; + }; + + checkFlags = [ + # Disable networked tests + "--skip bookkeeping::releases::test::release_assets" + ]; + + postFixup = '' + patchelf $out/bin/noita-proxy \ + --set-rpath ${lib.makeLibraryPath buildInputs} + ''; + + # This attribute is defined here instead of a `let` block, because in this position, + # it can be overridden with `overrideAttrs`, and shares a `src` with the top-level. + steamworksRedist = + runCommandNoCC "${pname}-steamworks-redist" { inherit src; } '' + install -Dm555 $src/redist/libsteam_api.so -t $out/lib + ''; + + meta = { + description = "Noita Entangled Worlds proxy application."; + homepage = "https://github.com/IntQuant/noita_entangled_worlds"; + changelog = + "https://github.com/IntQuant/noita_entangled_worlds/releases/tag/v${version}"; + license = with lib.licenses; [ mit asl20 ]; + platforms = [ "x86_64-linux" ]; + maintainers = with lib.maintainers; [ spikespaz ]; + mainProgram = "noita-proxy"; + }; + })