Skip to content

Flake: diversify wrapper and package #173

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ci/matrix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
}: let
nixpkgs = (import ./nix-checkouts.nix).${builtins.replaceStrings ["."] ["_"] qtver};
compilerOverride = (nixpkgs.callPackage ./variations.nix {}).${compiler};
pkg = (nixpkgs.callPackage ../default.nix {}).override compilerOverride;
pkg = nixpkgs.callPackage ../default.nix {
quickshell-unwrapped = (nixpkgs.callPackage ../unwrapped.nix {}).override compilerOverride;
};
in pkg
128 changes: 15 additions & 113 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,117 +1,18 @@
{
callPackage,
lib,
nix-gitignore,
pkgs,
keepDebugInfo,
buildStdenv ? pkgs.clangStdenv,

pkg-config,
cmake,
ninja,
spirv-tools,
quickshell-unwrapped ? callPackage ./unwrapped.nix {},
qt6,
breakpad,
jemalloc,
cli11,
wayland,
wayland-protocols,
wayland-scanner,
xorg,
libdrm,
libgbm ? null,
pipewire,
pam,

gitRev ? (let
headExists = builtins.pathExists ./.git/HEAD;
headContent = builtins.readFile ./.git/HEAD;
in if headExists
then (let
matches = builtins.match "ref: refs/heads/(.*)\n" headContent;
in if matches != null
then builtins.readFile ./.git/refs/heads/${builtins.elemAt matches 0}
else headContent)
else "unknown"),

debug ? false,
withCrashReporter ? true,
withJemalloc ? true, # masks heap fragmentation
withQtSvg ? true,
withWayland ? true,
withX11 ? true,
withPipewire ? true,
withPam ? true,
withHyprland ? true,
withI3 ? true,
}: let
unwrapped = buildStdenv.mkDerivation {
pname = "quickshell${lib.optionalString debug "-debug"}";
version = "0.2.0";
src = nix-gitignore.gitignoreSource "/default.nix\n" ./.;

dontWrapQtApps = true; # see wrappers

nativeBuildInputs = [
cmake
ninja
qt6.qtshadertools
spirv-tools
pkg-config
]
++ lib.optional withWayland wayland-scanner;

buildInputs = [
qt6.qtbase
qt6.qtdeclarative
cli11
]
++ lib.optional withQtSvg qt6.qtsvg
++ lib.optional withCrashReporter breakpad
++ lib.optional withJemalloc jemalloc
++ lib.optionals withWayland [ qt6.qtwayland wayland wayland-protocols ]
++ lib.optionals (withWayland && libgbm != null) [ libdrm libgbm ]
++ lib.optional withX11 xorg.libxcb
++ lib.optional withPam pam
++ lib.optional withPipewire pipewire;

cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";

cmakeFlags = [
(lib.cmakeFeature "DISTRIBUTOR" "Official-Nix-Flake")
(lib.cmakeFeature "INSTALL_QML_PREFIX" qt6.qtbase.qtQmlPrefix)
(lib.cmakeBool "DISTRIBUTOR_DEBUGINFO_AVAILABLE" true)
(lib.cmakeFeature "GIT_REVISION" gitRev)
(lib.cmakeBool "CRASH_REPORTER" withCrashReporter)
(lib.cmakeBool "USE_JEMALLOC" withJemalloc)
(lib.cmakeBool "WAYLAND" withWayland)
(lib.cmakeBool "SCREENCOPY" (libgbm != null))
(lib.cmakeBool "SERVICE_PIPEWIRE" withPipewire)
(lib.cmakeBool "SERVICE_PAM" withPam)
(lib.cmakeBool "HYPRLAND" withHyprland)
(lib.cmakeBool "I3" withI3)
];

# How to get debuginfo in gdb from a release build:
# 1. build `quickshell.debug`
# 2. set NIX_DEBUG_INFO_DIRS="<quickshell.debug store path>/lib/debug"
# 3. launch gdb / coredumpctl and debuginfo will work
separateDebugInfo = !debug;
dontStrip = debug;

meta = with lib; {
homepage = "https://quickshell.org";
description = "Flexbile QtQuick based desktop shell toolkit";
license = licenses.lgpl3Only;
platforms = platforms.linux;
mainProgram = "quickshell";
};
};

wrapper = unwrapped.stdenv.mkDerivation {
unwrapped = quickshell-unwrapped;
inherit (unwrapped.stdenv) mkDerivation;
inherit (lib) typeOf asserts;
in
mkDerivation (final: {
inherit (unwrapped) version meta buildInputs;
pname = "${unwrapped.pname}-wrapped";

nativeBuildInputs = unwrapped.nativeBuildInputs ++ [ qt6.wrapQtAppsHook ];
nativeBuildInputs = unwrapped.nativeBuildInputs ++ [qt6.wrapQtAppsHook];

dontUnpack = true;
dontConfigure = true;
Expand All @@ -123,10 +24,11 @@
'';

passthru = {
unwrapped = unwrapped;
withModules = modules: wrapper.overrideAttrs (prev: {
buildInputs = prev.buildInputs ++ modules;
});
inherit unwrapped;
withModules = modules:
assert (asserts.assertMsg (typeOf modules == "list") "`modules` must be a list of packages");
final.finalPackage.overrideAttrs (prev: {
buildInputs = prev.buildInputs ++ modules;
});
};
};
in wrapper
})
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
(system: fn system nixpkgs.legacyPackages.${system});
in {
packages = forEachSystem (system: pkgs: rec {
quickshell = pkgs.callPackage ./default.nix {
quickshell-unwrapped = pkgs.callPackage ./unwrapped.nix {
gitRev = self.rev or self.dirtyRev;
};

quickshell = pkgs.callPackage ./default.nix {inherit quickshell-unwrapped;};
default = quickshell;
});

Expand Down
107 changes: 107 additions & 0 deletions unwrapped.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
lib,
nix-gitignore,
pkgs,
keepDebugInfo,
buildStdenv ? pkgs.clangStdenv,

pkg-config,
cmake,
ninja,
spirv-tools,
qt6,
breakpad,
jemalloc,
cli11,
wayland,
wayland-protocols,
wayland-scanner,
xorg,
libdrm,
libgbm ? null,
pipewire,
pam,

gitRev ? (let
headExists = builtins.pathExists ./.git/HEAD;
headContent = builtins.readFile ./.git/HEAD;
in if headExists
then (let
matches = builtins.match "ref: refs/heads/(.*)\n" headContent;
in if matches != null
then builtins.readFile ./.git/refs/heads/${builtins.elemAt matches 0}
else headContent)
else "unknown"),

debug ? false,
withCrashReporter ? true,
withJemalloc ? true, # masks heap fragmentation
withQtSvg ? true,
withWayland ? true,
withX11 ? true,
withPipewire ? true,
withPam ? true,
withHyprland ? true,
withI3 ? true,
}: buildStdenv.mkDerivation {
pname = "quickshell${lib.optionalString debug "-debug"}";
version = "0.2.0";
src = nix-gitignore.gitignoreSource "/default.nix\n" ./.;

dontWrapQtApps = true; # see wrappers

nativeBuildInputs = [
cmake
ninja
qt6.qtshadertools
spirv-tools
pkg-config
]
++ lib.optional withWayland wayland-scanner;

buildInputs = [
qt6.qtbase
qt6.qtdeclarative
cli11
]
++ lib.optional withQtSvg qt6.qtsvg
++ lib.optional withCrashReporter breakpad
++ lib.optional withJemalloc jemalloc
++ lib.optionals withWayland [ qt6.qtwayland wayland wayland-protocols ]
++ lib.optionals (withWayland && libgbm != null) [ libdrm libgbm ]
++ lib.optional withX11 xorg.libxcb
++ lib.optional withPam pam
++ lib.optional withPipewire pipewire;

cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";

cmakeFlags = [
(lib.cmakeFeature "DISTRIBUTOR" "Official-Nix-Flake")
(lib.cmakeFeature "INSTALL_QML_PREFIX" qt6.qtbase.qtQmlPrefix)
(lib.cmakeBool "DISTRIBUTOR_DEBUGINFO_AVAILABLE" true)
(lib.cmakeFeature "GIT_REVISION" gitRev)
(lib.cmakeBool "CRASH_REPORTER" withCrashReporter)
(lib.cmakeBool "USE_JEMALLOC" withJemalloc)
(lib.cmakeBool "WAYLAND" withWayland)
(lib.cmakeBool "SCREENCOPY" (libgbm != null))
(lib.cmakeBool "SERVICE_PIPEWIRE" withPipewire)
(lib.cmakeBool "SERVICE_PAM" withPam)
(lib.cmakeBool "HYPRLAND" withHyprland)
(lib.cmakeBool "I3" withI3)
];

# How to get debuginfo in gdb from a release build:
# 1. build `quickshell.debug`
# 2. set NIX_DEBUG_INFO_DIRS="<quickshell.debug store path>/lib/debug"
# 3. launch gdb / coredumpctl and debuginfo will work
separateDebugInfo = !debug;
dontStrip = debug;

meta = with lib; {
homepage = "https://quickshell.org";
description = "Flexbile QtQuick based desktop shell toolkit";
license = licenses.lgpl3Only;
platforms = platforms.linux;
mainProgram = "quickshell";
};
}