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

Don't instantiate nixpkgs in Flake #1574

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 15 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@
outputs = inputs:
inputs.flake-parts.lib.mkFlake
{inherit inputs;}
{imports = [./nix];};
{
imports = [
inputs.pre-commit-hooks.flakeModule

./nix/dev.nix
./nix/distribution.nix
];

systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
};
}
31 changes: 0 additions & 31 deletions nix/default.nix

This file was deleted.

38 changes: 17 additions & 21 deletions nix/dev.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
{
inputs,
self,
...
}: {
perSystem = {
system,
config,
lib,
pkgs,
...
}: {
checks = {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
markdownlint.enable = true;
pre-commit.settings = {
hooks = {
markdownlint.enable = true;

alejandra.enable = true;
deadnix.enable = true;
nil.enable = true;
alejandra.enable = true;
deadnix.enable = true;
nil.enable = true;

clang-format = {
enable = true;
types_or = ["c" "c++" "java" "json" "objective-c"];
};
clang-format = {
enable = true;
types_or = ["c" "c++" "java" "json" "objective-c"];
};

tools.clang-tools = pkgs.clang-tools_16;
};

tools.clang-tools = lib.mkForce pkgs.clang-tools_16;
};

devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
shellHook = ''
${config.pre-commit.installationScript}
'';

inputsFrom = [self.packages.${system}.prismlauncher-unwrapped];
inputsFrom = [config.packages.prismlauncher-unwrapped];
buildInputs = with pkgs; [ccache ninja];
};

Expand Down
46 changes: 30 additions & 16 deletions nix/distribution.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
{
inputs,
self,
version,
...
}: {
perSystem = {pkgs, ...}: {
packages = {
inherit (pkgs) prismlauncher-qt5-unwrapped prismlauncher-qt5 prismlauncher-unwrapped prismlauncher;
default = pkgs.prismlauncher;
perSystem = {
lib,
pkgs,
...
}: {
packages = let
ourPackages = lib.fix (final: self.overlays.default ({inherit (pkgs) darwin;} // final) pkgs);
in {
inherit
(ourPackages)
prismlauncher-qt5-unwrapped
prismlauncher-qt5
prismlauncher-unwrapped
prismlauncher
;
default = ourPackages.prismlauncher;
};
};

flake = {
overlays.default = final: prev: let
# Helper function to build prism against different versions of Qt.
mkPrism = qt:
qt.callPackage ./package.nix {
inherit (inputs) libnbtplusplus;
inherit (prev.darwin.apple_sdk.frameworks) Cocoa;
inherit self version;
};
version = builtins.substring 0 8 self.lastModifiedDate or "dirty";

# common args for prismlauncher evaluations
unwrappedArgs = {
getchoo marked this conversation as resolved.
Show resolved Hide resolved
inherit (inputs) libnbtplusplus;
inherit (final.darwin.apple_sdk.frameworks) Cocoa;
inherit self version;
};
in {
prismlauncher-qt5-unwrapped = mkPrism final.libsForQt5;
prismlauncher-qt5 = prev.prismlauncher-qt5.override {prismlauncher-unwrapped = final.prismlauncher-qt5-unwrapped;};
prismlauncher-unwrapped = mkPrism final.qt6Packages;
prismlauncher = prev.prismlauncher.override {inherit (final) prismlauncher-unwrapped;};
prismlauncher-qt5-unwrapped = prev.libsForQt5.callPackage ./pkg unwrappedArgs;
prismlauncher-qt5 = prev.libsForQt5.callPackage ./pkg/wrapper.nix {
prismlauncher-unwrapped = final.prismlauncher-qt5-unwrapped;
};
prismlauncher-unwrapped = prev.qt6Packages.callPackage ./pkg unwrappedArgs;
prismlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix {inherit (final) prismlauncher-unwrapped;};
};
};
}
File renamed without changes.
91 changes: 91 additions & 0 deletions nix/pkg/wrapper.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
lib,
stdenv,
symlinkJoin,
prismlauncher-unwrapped,
wrapQtAppsHook,
qtbase, # needed for wrapQtAppsHook
qtsvg,
qtwayland,
xorg,
libpulseaudio,
libGL,
glfw,
openal,
jdk8,
jdk17,
gamemode,
flite,
mesa-demos,
udev,
msaClientID ? null,
gamemodeSupport ? stdenv.isLinux,
textToSpeechSupport ? stdenv.isLinux,
jdks ? [jdk17 jdk8],
additionalLibs ? [],
additionalPrograms ? [],
}: let
prismlauncherFinal = prismlauncher-unwrapped.override {
inherit msaClientID gamemodeSupport;
};
in
symlinkJoin {
name = "prismlauncher-${prismlauncherFinal.version}";

paths = [prismlauncherFinal];

nativeBuildInputs = [
wrapQtAppsHook
];

buildInputs =
[
qtbase
qtsvg
]
++ lib.optional (lib.versionAtLeast qtbase.version "6" && stdenv.isLinux) qtwayland;

postBuild = ''
wrapQtAppsHook
'';

qtWrapperArgs = let
runtimeLibs =
(with xorg; [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
])
++ [
# lwjgl
libpulseaudio
libGL
glfw
openal
stdenv.cc.cc.lib

# oshi
udev
]
++ lib.optional gamemodeSupport gamemode.lib
++ lib.optional textToSpeechSupport flite
++ additionalLibs;

runtimePrograms =
[
xorg.xrandr
mesa-demos # need glxinfo
]
++ additionalPrograms;
in
["--prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"]
++ lib.optionals stdenv.isLinux [
"--set LD_LIBRARY_PATH /run/opengl-driver/lib:${lib.makeLibraryPath runtimeLibs}"
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
"--prefix PATH : ${lib.makeBinPath runtimePrograms}"
];

inherit (prismlauncherFinal) meta;
}