From 957cd29dbf303771a6fbef54d37a07c002cd5843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= Date: Sun, 9 Jan 2022 09:08:39 +0300 Subject: [PATCH] nix: add support for non-flake builds --- default.nix | 1 + flake.lock | 17 +++++++++++++++++ flake.nix | 9 +++++++-- packages/nix/flake-compat.nix | 9 +++++++++ packages/nix/polymc/default.nix | 24 ++++++++++++++++-------- 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 default.nix create mode 100644 packages/nix/flake-compat.nix diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..5abfc1bd5 --- /dev/null +++ b/default.nix @@ -0,0 +1 @@ +(import packages/nix/flake-compat.nix).defaultNix diff --git a/flake.lock b/flake.lock index 131a9112d..2248b4a4d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1638122382, @@ -65,6 +81,7 @@ }, "root": { "inputs": { + "flake-compat": "flake-compat", "flake-utils": "flake-utils", "libnbtplusplus": "libnbtplusplus", "nixpkgs": "nixpkgs", diff --git a/flake.nix b/flake.nix index 825f747ed..47a13ac29 100644 --- a/flake.nix +++ b/flake.nix @@ -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; @@ -17,7 +21,7 @@ pkgs = import nixpkgs { inherit system; }; - + packages = { polymc = pkgs.libsForQt5.callPackage ./packages/nix/polymc { inherit self; @@ -25,7 +29,8 @@ submoduleNbt = libnbtplusplus; }; }; - + + # 'nix flake check' fails overlay = (final: prev: rec { polymc = prev.libsForQt5.callPackage ./packages/nix/polymc { inherit self; diff --git a/packages/nix/flake-compat.nix b/packages/nix/flake-compat.nix new file mode 100644 index 000000000..bb7ee13e0 --- /dev/null +++ b/packages/nix/flake-compat.nix @@ -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 = ../..; } diff --git a/packages/nix/polymc/default.nix b/packages/nix/polymc/default.nix index 4f80ff341..15677172b 100644 --- a/packages/nix/polymc/default.nix +++ b/packages/nix/polymc/default.nix @@ -2,8 +2,6 @@ , mkDerivation , fetchFromGitHub , makeDesktopItem -, substituteAll -, fetchpatch , cmake , ninja , jdk8 @@ -15,14 +13,16 @@ , 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 @@ -30,7 +30,10 @@ let libXxf86vm libpulseaudio libGL - ]; + ]; + + # This variable will be passed to Minecraft by PolyMC + gameLibraryPath = libpath + ":/run/opengl-driver/lib"; in mkDerivation rec { @@ -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 @@ -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 ]} ''; }