Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Nix Flake #1093

Merged
merged 6 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
(import nix/flake-compat.nix).defaultNix
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
.defaultNix
62 changes: 34 additions & 28 deletions flake.lock

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

78 changes: 7 additions & 71 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-parts.url = "github:hercules-ci/flake-parts";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs-stable.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
};
flake-compat = {
url = "github:edolstra/flake-compat";
Expand All @@ -19,73 +20,8 @@
};
};

outputs = {
self,
nixpkgs,
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")
supportedSystems = with flake-utils.lib.system; [
x86_64-linux
x86_64-darwin
aarch64-linux
];

packagesFn = pkgs: {
prismlauncher-qt5 = pkgs.libsForQt5.callPackage ./nix {
inherit version self libnbtplusplus;
};
prismlauncher = pkgs.qt6Packages.callPackage ./nix {
inherit version self libnbtplusplus;
};
};
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;

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);
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake
{inherit inputs;}
{imports = [./nix];};
}
118 changes: 25 additions & 93 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,100 +1,32 @@
{
lib,
stdenv,
cmake,
ninja,
jdk8,
jdk17,
zlib,
file,
wrapQtAppsHook,
xorg,
libpulseaudio,
qtbase,
qtsvg,
qtwayland,
libGL,
quazip,
glfw,
openal,
extra-cmake-modules,
tomlplusplus,
ghc_filesystem,
cmark,
msaClientID ? "",
jdks ? [jdk17 jdk8],
gamemodeSupport ? true,
gamemode,
# flake
inputs,
self,
version,
libnbtplusplus,
}:
stdenv.mkDerivation rec {
pname = "prismlauncher";
inherit version;

src = lib.cleanSource self;

nativeBuildInputs = [extra-cmake-modules cmake file jdk17 ninja wrapQtAppsHook];
buildInputs =
[
qtbase
qtsvg
zlib
quazip
ghc_filesystem
tomlplusplus
cmark
]
++ lib.optional (lib.versionAtLeast qtbase.version "6") qtwayland
++ lib.optional gamemodeSupport gamemode.dev;
...
}: {
imports = [
./dev.nix
./distribution.nix
];

cmakeFlags =
lib.optionals (msaClientID != "") ["-DLauncher_MSA_CLIENT_ID=${msaClientID}"]
++ lib.optionals (lib.versionOlder qtbase.version "6") ["-DLauncher_QT_VERSION_MAJOR=5"];
_module.args = {
# User-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
};

postUnpack = ''
rm -rf source/libraries/libnbtplusplus
mkdir source/libraries/libnbtplusplus
ln -s ${libnbtplusplus}/* source/libraries/libnbtplusplus
chmod -R +r+w source/libraries/libnbtplusplus
chown -R $USER: source/libraries/libnbtplusplus
'';
perSystem = {system, ...}: {
# Nixpkgs instantiated for supported systems with our overlay.
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
};

qtWrapperArgs = let
libpath = with xorg;
lib.makeLibraryPath ([
libX11
libXext
libXcursor
libXrandr
libXxf86vm
libpulseaudio
libGL
glfw
openal
stdenv.cc.cc.lib
]
++ lib.optional gamemodeSupport gamemode.lib);
in [
"--set LD_LIBRARY_PATH /run/opengl-driver/lib:${libpath}"
"--prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
"--prefix PATH : ${lib.makeBinPath [xorg.xrandr]}"
# Supported systems.
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
# Disabled due to qtbase being currently broken for "aarch64-darwin."
# "aarch64-darwin"
];

meta = with lib; {
homepage = "https://prismlauncher.org/";
description = "A free, open source launcher for Minecraft";
longDescription = ''
Allows you to have multiple, separate instances of Minecraft (each with
their own mods, texture packs, saves, etc) and helps you manage them and
their associated options with a simple interface.
'';
platforms = platforms.linux;
changelog = "https://github.com/PrismLauncher/PrismLauncher/releases/tag/${version}";
license = licenses.gpl3Only;
maintainers = with maintainers; [minion3665 Scrumplex];
};
}