Merge pull request #888 from Scrumplex/nix-stuff

This commit is contained in:
Sefa Eyeoglu 2023-03-14 13:52:31 +01:00 committed by GitHub
commit 84e91ec3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 258 additions and 154 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

4
.gitignore vendored
View File

@ -22,6 +22,10 @@ Debug
build build
/build-* /build-*
# direnv / Nix
.direnv/
.pre-commit-config.yaml
# Install dirs # Install dirs
install install
/install-* /install-*

View File

@ -1,53 +1,3 @@
# Build Instructions # Build Instructions
Full build instructions will be available on [the website](https://prismlauncher.org/wiki/development/build-instructions/). Full build instructions are available on [the website](https://prismlauncher.org/wiki/development/build-instructions/).
If you would like to contribute or fix an issue with the Build instructions you will be able to do so [here](https://github.com/PrismLauncher/website/blob/master/src/wiki/development/build-instructions.md).
## Getting the source
Clone the source code using git, and grab all the submodules. This is generic for all platforms you want to build on.
```
git clone --recursive https://github.com/PrismLauncher/PrismLauncher
cd PrismLauncher
```
## Linux
This guide will mostly mention dependant packages by their Debian naming and commands are done by a user in the sudoers file.
### Dependencies
- A C++ compiler capable of building C++17 code (can be found in the package `build-essential`).
- Qt Development tools 5.12 or newer (on Debian 11 or Debian-based distributions, `qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5core5a libqt5network5 libqt5gui5`).
- `cmake` 3.15 or newer.
- `extra-cmake-modules`.
- zlib (`zlib1g-dev` on Debian 11 or Debian-based distributions).
- Java Development Kit (Java JDK) (`openjdk-17-jdk` on Debian 11 or Debian-based distributions).
- Mesa GL headers (`libgl1-mesa-dev` on Debian 11 or Debian-based distributions).
- (Optional) `scdoc` to generate man pages.
In conclusion, to check if all you need is installed (including optional):
```
sudo apt install build-essential qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5core5a libqt5network5 libqt5gui5 cmake extra-cmake-modules zlib1g-dev openjdk-17-jdk libgl1-mesa-dev scdoc
```
### Compiling
#### Building and installing on the system
This is usually the suggested way to build the client.
```
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="/usr" -DENABLE_LTO=ON
cmake --build build -j$(nproc)
sudo cmake --install build
```
#### Building a portable binary
```
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install
cmake --build build -j$(nproc)
cmake --install build
cmake --install build --component portable
```

110
flake.lock generated
View File

@ -3,11 +3,11 @@
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1668681692, "lastModified": 1673956053,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra", "owner": "edolstra",
"repo": "flake-compat", "repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1", "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -16,6 +16,58 @@
"type": "github" "type": "github"
} }
}, },
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1676283394,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1660459072,
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"libnbtplusplus": { "libnbtplusplus": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -34,11 +86,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1671417167, "lastModified": 1678693419,
"narHash": "sha256-JkHam6WQOwZN1t2C2sbp1TqMv3TVRjzrdoejqfefwrM=", "narHash": "sha256-bbSv5yqZAW6dz+3f3f3pOUZbxpPN+3OgCljgn7P+nnQ=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "bb31220cca6d044baa6dc2715b07497a2a7c4bc7", "rev": "8e3fad82be64c06fbfb9fd43993aec9ef4623936",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -48,11 +100,55 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-stable": {
"locked": {
"lastModified": 1673800717,
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": [
"flake-utils"
],
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1678376203,
"narHash": "sha256-3tyYGyC8h7fBwncLZy5nCUjTJPrHbmNwp47LlNLOHSM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "1a20b9708962096ec2481eeb2ddca29ed747770a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"libnbtplusplus": "libnbtplusplus", "libnbtplusplus": "libnbtplusplus",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
} }
} }
}, },

102
flake.nix
View File

@ -3,35 +3,89 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; flake-utils.url = "github:numtide/flake-utils";
libnbtplusplus = { url = "github:PrismLauncher/libnbtplusplus"; flake = false; }; pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
libnbtplusplus = {
url = "github:PrismLauncher/libnbtplusplus";
flake = false;
};
}; };
outputs = { self, nixpkgs, libnbtplusplus, ... }: outputs = {
let self,
# User-friendly version number. nixpkgs,
version = builtins.substring 0 8 self.lastModifiedDate; flake-utils,
pre-commit-hooks,
libnbtplusplus,
...
}: let
# User-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
# Supported systems (qtbase is currently broken for "aarch64-darwin") # Supported systems (qtbase is currently broken for "aarch64-darwin")
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ]; supportedSystems = with flake-utils.lib.system; [
x86_64-linux
x86_64-darwin
aarch64-linux
];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. packagesFn = pkgs: {
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; prismlauncher-qt5 = pkgs.libsForQt5.callPackage ./nix {
inherit version self libnbtplusplus;
# Nixpkgs instantiated for supported systems.
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
packagesFn = pkgs: rec {
prismlauncher-qt5 = pkgs.libsForQt5.callPackage ./nix { inherit version self libnbtplusplus; };
prismlauncher = pkgs.qt6Packages.callPackage ./nix { inherit version self libnbtplusplus; };
}; };
in prismlauncher = pkgs.qt6Packages.callPackage ./nix {
{ inherit version self libnbtplusplus;
packages = forAllSystems (system: };
let packages = packagesFn pkgs.${system}; in };
packages // { default = packages.prismlauncher; } in
); flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
markdownlint.enable = true;
overlay = final: packagesFn; alejandra.enable = true;
deadnix.enable = true;
clang-format = {
enable =
false; # As most of the codebase is **not** formatted, we don't want clang-format yet
types_or = ["c" "c++"];
};
};
};
};
packages = let
packages = packagesFn pkgs;
in
packages // {default = packages.prismlauncher;};
devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
packages = with pkgs; [
nodePackages.markdownlint-cli
alejandra
deadnix
clang-tools
];
inputsFrom = [self.packages.${system}.default];
buildInputs = with pkgs; [ccache ninja];
};
})
// {
overlays.default = final: _: (packagesFn final);
}; };
} }

View File

@ -8,10 +8,10 @@
> Redistribution and use in source and binary forms, with or without > Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are met: > modification, are permitted provided that the following conditions are met:
> >
> * Redistributions of source code must retain the above copyright notice, this > * Redistributions of source code must retain the above copyright notice, this
> list of conditions and the following disclaimer. > list of conditions and the following disclaimer.
> >
> * Redistributions in binary form must reproduce the above copyright notice, > * Redistributions in binary form must reproduce the above copyright notice,
> this list of conditions and the following disclaimer in the documentation > this list of conditions and the following disclaimer in the documentation
> and/or other materials provided with the distribution. > and/or other materials provided with the distribution.
> >
@ -36,12 +36,12 @@ Cryptographic methods for Qt.
> Redistribution and use in source and binary forms, with or without > Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are met: > modification, are permitted provided that the following conditions are met:
> >
> * Redistributions of source code must retain the above copyright > * Redistributions of source code must retain the above copyright
> notice, this list of conditions and the following disclaimer. > notice, this list of conditions and the following disclaimer.
> * Redistributions in binary form must reproduce the above copyright > * Redistributions in binary form must reproduce the above copyright
> notice, this list of conditions and the following disclaimer in the > notice, this list of conditions and the following disclaimer in the
> documentation and/or other materials provided with the distribution. > documentation and/or other materials provided with the distribution.
> * Neither the name of the Rathenau Instituut, Andre Somers nor the > * Neither the name of the Rathenau Instituut, Andre Somers nor the
> names of its contributors may be used to endorse or promote products > names of its contributors may be used to endorse or promote products
> derived from this software without specific prior written permission. > derived from this software without specific prior written permission.
> >
@ -62,7 +62,7 @@ Configurable settings storage, Twitter XAuth specialization, new demos, cleanups
> "Hi Akos, > "Hi Akos,
> >
> I'm writing this mail to confirm that my contributions to the O2 library, available here https://github.com/pipacs/o2, can be freely distributed according to the project's license (as shown in the LICENSE file). > I'm writing this mail to confirm that my contributions to the O2 library, available here <https://github.com/pipacs/o2>, can be freely distributed according to the project's license (as shown in the LICENSE file).
> >
> Regards, > Regards,
> -mandeep" > -mandeep"

View File

@ -1,52 +1,54 @@
{ lib {
, stdenv lib,
, cmake stdenv,
, jdk8 cmake,
, jdk17 jdk8,
, zlib jdk17,
, file zlib,
, wrapQtAppsHook file,
, xorg wrapQtAppsHook,
, libpulseaudio xorg,
, qtbase libpulseaudio,
, qtsvg qtbase,
, qtwayland qtsvg,
, libGL qtwayland,
, quazip libGL,
, glfw quazip,
, openal glfw,
, extra-cmake-modules openal,
, tomlplusplus extra-cmake-modules,
, ghc_filesystem tomlplusplus,
, cmark ghc_filesystem,
, msaClientID ? "" cmark,
, jdks ? [ jdk17 jdk8 ] msaClientID ? "",
jdks ? [jdk17 jdk8],
# flake # flake
, self self,
, version version,
, libnbtplusplus libnbtplusplus,
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "prismlauncher"; pname = "prismlauncher";
inherit version; inherit version;
src = lib.cleanSource self; src = lib.cleanSource self;
nativeBuildInputs = [ extra-cmake-modules cmake file jdk17 wrapQtAppsHook ]; nativeBuildInputs = [extra-cmake-modules cmake file jdk17 wrapQtAppsHook];
buildInputs = [ buildInputs =
qtbase [
qtsvg qtbase
zlib qtsvg
quazip zlib
ghc_filesystem quazip
tomlplusplus ghc_filesystem
cmark tomlplusplus
] ++ lib.optional (lib.versionAtLeast qtbase.version "6") qtwayland; cmark
]
++ lib.optional (lib.versionAtLeast qtbase.version "6") qtwayland;
cmakeFlags = lib.optionals (msaClientID != "") [ "-DLauncher_MSA_CLIENT_ID=${msaClientID}" ] cmakeFlags =
++ lib.optionals (lib.versionOlder qtbase.version "6") [ "-DLauncher_QT_VERSION_MAJOR=5" ]; lib.optionals (msaClientID != "") ["-DLauncher_MSA_CLIENT_ID=${msaClientID}"]
++ lib.optionals (lib.versionOlder qtbase.version "6") ["-DLauncher_QT_VERSION_MAJOR=5"];
dontWrapQtApps = true; dontWrapQtApps = true;
postUnpack = '' postUnpack = ''
@ -57,30 +59,27 @@ stdenv.mkDerivation rec {
chown -R $USER: source/libraries/libnbtplusplus chown -R $USER: source/libraries/libnbtplusplus
''; '';
postInstall = postInstall = let
let libpath = with xorg;
libpath = with xorg; lib.makeLibraryPath [
lib.makeLibraryPath [ libX11
libX11 libXext
libXext libXcursor
libXcursor libXrandr
libXrandr libXxf86vm
libXxf86vm libpulseaudio
libpulseaudio libGL
libGL glfw
glfw openal
openal stdenv.cc.cc.lib
stdenv.cc.cc.lib ];
]; in ''
in # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
'' wrapQtApp $out/bin/prismlauncher \
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 --set LD_LIBRARY_PATH /run/opengl-driver/lib:${libpath} \
wrapQtApp $out/bin/prismlauncher \ --prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks} \
--set LD_LIBRARY_PATH /run/opengl-driver/lib:${libpath} \ --prefix PATH : ${lib.makeBinPath [xorg.xrandr]}
--prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks} \ '';
--prefix PATH : ${lib.makeBinPath [xorg.xrandr]}
'';
meta = with lib; { meta = with lib; {
homepage = "https://prismlauncher.org/"; homepage = "https://prismlauncher.org/";
@ -93,6 +92,6 @@ stdenv.mkDerivation rec {
platforms = platforms.linux; platforms = platforms.linux;
changelog = "https://github.com/PrismLauncher/PrismLauncher/releases/tag/${version}"; changelog = "https://github.com/PrismLauncher/PrismLauncher/releases/tag/${version}";
license = licenses.gpl3Only; license = licenses.gpl3Only;
maintainers = with maintainers; [ minion3665 Scrumplex ]; maintainers = with maintainers; [minion3665 Scrumplex];
}; };
} }

View File

@ -6,4 +6,4 @@ let
sha256 = narHash; sha256 = narHash;
}; };
in in
import flake-compat { src = ../.; } import flake-compat {src = ../.;}