Skip to content

Commit

Permalink
nix: add support for non-flake builds
Browse files Browse the repository at this point in the history
  • Loading branch information
muscaln committed Jan 9, 2022
1 parent 5a09dca commit 957cd29
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import packages/nix/flake-compat.nix).defaultNix
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
description = "PolyMC flake";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
inputs.libnbtplusplus = {
url = "github:multimc/libnbtplusplus";
flake = false;
Expand All @@ -17,15 +21,16 @@
pkgs = import nixpkgs {
inherit system;
};

packages = {
polymc = pkgs.libsForQt5.callPackage ./packages/nix/polymc {
inherit self;
submoduleQuazip = quazip;
submoduleNbt = libnbtplusplus;
};
};


# 'nix flake check' fails
overlay = (final: prev: rec {
polymc = prev.libsForQt5.callPackage ./packages/nix/polymc {
inherit self;
Expand Down
9 changes: 9 additions & 0 deletions packages/nix/flake-compat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let
lock = builtins.fromJSON (builtins.readFile ../../flake.lock);
inherit (lock.nodes.flake-compat.locked) rev narHash;
flake-compat = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz";
sha256 = narHash;
};
in
import flake-compat { src = ../..; }
24 changes: 16 additions & 8 deletions packages/nix/polymc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
, mkDerivation
, fetchFromGitHub
, makeDesktopItem
, substituteAll
, fetchpatch
, cmake
, ninja
, jdk8
Expand All @@ -15,22 +13,27 @@
, libpulseaudio
, qtbase
, libGL
# submodules

# flake
, self
, submoduleNbt
, submoduleQuazip
}:

let
gameLibraryPath = with xorg; lib.makeLibraryPath [
# Libraries required to run Minecraft
libpath = with xorg; lib.makeLibraryPath [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
libpulseaudio
libGL
];
];

# This variable will be passed to Minecraft by PolyMC
gameLibraryPath = libpath + ":/run/opengl-driver/lib";
in

mkDerivation rec {
Expand All @@ -42,7 +45,10 @@ mkDerivation rec {
nativeBuildInputs = [ cmake ninja file makeWrapper ];
buildInputs = [ qtbase jdk8 zlib ];

dontWrapQtApps = true;

postUnpack = ''
# Copy submodules inputs
rm -rf source/libraries/{libnbtplusplus,quazip}
mkdir source/libraries/{libnbtplusplus,quazip}
cp -a ${submoduleNbt}/* source/libraries/libnbtplusplus
Expand All @@ -69,11 +75,13 @@ mkDerivation rec {
};

postInstall = ''
install -Dm644 ../launcher/resources/multimc/scalable/launcher.svg $out/share/pixmaps/multimc.svg
install -Dm755 ${desktopItem}/share/applications/polymc.desktop -t $out/share/applications
install -Dm644 ../launcher/resources/multimc/scalable/launcher.svg $out/share/pixmaps/polymc.svg
install -Dm644 ${desktopItem}/share/applications/polymc.desktop $out/share/applications/org.polymc.PolyMC.desktop
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
wrapProgram $out/bin/polymc \
--set GAME_LIBRARY_PATH /run/opengl-driver/lib:${gameLibraryPath} \
"''${qtWrapperArgs[@]}" \
--set GAME_LIBRARY_PATH ${gameLibraryPath} \
--prefix PATH : ${lib.makeBinPath [ xorg.xrandr jdk ]}
'';
}

0 comments on commit 957cd29

Please sign in to comment.