nix: add support for non-flake builds

This commit is contained in:
Mustafa Çalışkan 2022-01-09 09:08:39 +03:00
parent 5a09dcae68
commit 957cd29dbf
5 changed files with 50 additions and 10 deletions

1
default.nix Normal file
View File

@ -0,0 +1 @@
(import packages/nix/flake-compat.nix).defaultNix

17
flake.lock generated
View File

@ -1,5 +1,21 @@
{ {
"nodes": { "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": { "flake-utils": {
"locked": { "locked": {
"lastModified": 1638122382, "lastModified": 1638122382,
@ -65,6 +81,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"libnbtplusplus": "libnbtplusplus", "libnbtplusplus": "libnbtplusplus",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",

View File

@ -2,6 +2,10 @@
description = "PolyMC flake"; description = "PolyMC flake";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
inputs.libnbtplusplus = { inputs.libnbtplusplus = {
url = "github:multimc/libnbtplusplus"; url = "github:multimc/libnbtplusplus";
flake = false; flake = false;
@ -17,7 +21,7 @@
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
packages = { packages = {
polymc = pkgs.libsForQt5.callPackage ./packages/nix/polymc { polymc = pkgs.libsForQt5.callPackage ./packages/nix/polymc {
inherit self; inherit self;
@ -25,7 +29,8 @@
submoduleNbt = libnbtplusplus; submoduleNbt = libnbtplusplus;
}; };
}; };
# 'nix flake check' fails
overlay = (final: prev: rec { overlay = (final: prev: rec {
polymc = prev.libsForQt5.callPackage ./packages/nix/polymc { polymc = prev.libsForQt5.callPackage ./packages/nix/polymc {
inherit self; inherit self;

View File

@ -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 = ../..; }

View File

@ -2,8 +2,6 @@
, mkDerivation , mkDerivation
, fetchFromGitHub , fetchFromGitHub
, makeDesktopItem , makeDesktopItem
, substituteAll
, fetchpatch
, cmake , cmake
, ninja , ninja
, jdk8 , jdk8
@ -15,14 +13,16 @@
, libpulseaudio , libpulseaudio
, qtbase , qtbase
, libGL , libGL
# submodules
# flake
, self , self
, submoduleNbt , submoduleNbt
, submoduleQuazip , submoduleQuazip
}: }:
let let
gameLibraryPath = with xorg; lib.makeLibraryPath [ # Libraries required to run Minecraft
libpath = with xorg; lib.makeLibraryPath [
libX11 libX11
libXext libXext
libXcursor libXcursor
@ -30,7 +30,10 @@ let
libXxf86vm libXxf86vm
libpulseaudio libpulseaudio
libGL libGL
]; ];
# This variable will be passed to Minecraft by PolyMC
gameLibraryPath = libpath + ":/run/opengl-driver/lib";
in in
mkDerivation rec { mkDerivation rec {
@ -42,7 +45,10 @@ mkDerivation rec {
nativeBuildInputs = [ cmake ninja file makeWrapper ]; nativeBuildInputs = [ cmake ninja file makeWrapper ];
buildInputs = [ qtbase jdk8 zlib ]; buildInputs = [ qtbase jdk8 zlib ];
dontWrapQtApps = true;
postUnpack = '' postUnpack = ''
# Copy submodules inputs
rm -rf source/libraries/{libnbtplusplus,quazip} rm -rf source/libraries/{libnbtplusplus,quazip}
mkdir source/libraries/{libnbtplusplus,quazip} mkdir source/libraries/{libnbtplusplus,quazip}
cp -a ${submoduleNbt}/* source/libraries/libnbtplusplus cp -a ${submoduleNbt}/* source/libraries/libnbtplusplus
@ -69,11 +75,13 @@ mkDerivation rec {
}; };
postInstall = '' postInstall = ''
install -Dm644 ../launcher/resources/multimc/scalable/launcher.svg $out/share/pixmaps/multimc.svg install -Dm644 ../launcher/resources/multimc/scalable/launcher.svg $out/share/pixmaps/polymc.svg
install -Dm755 ${desktopItem}/share/applications/polymc.desktop -t $out/share/applications 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 # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
wrapProgram $out/bin/polymc \ 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 ]} --prefix PATH : ${lib.makeBinPath [ xorg.xrandr jdk ]}
''; '';
} }