build: split derivation for extensible wrapper

This commit is contained in:
Rexiel Scarlet 2025-07-18 14:43:09 +04:00
parent ecc4a1249d
commit e55d519c28

View file

@ -43,64 +43,93 @@
withPam ? true, withPam ? true,
withHyprland ? true, withHyprland ? true,
withI3 ? true, withI3 ? true,
}: buildStdenv.mkDerivation { }: let
pname = "quickshell${lib.optionalString debug "-debug"}"; unwrapped = buildStdenv.mkDerivation {
version = "0.1.0"; pname = "quickshell${lib.optionalString debug "-debug"}";
src = nix-gitignore.gitignoreSource [] ./.; version = "0.1.0";
src = nix-gitignore.gitignoreSource "/default.nix\n" ./.;
nativeBuildInputs = [ dontWrapQtApps = true; # see wrappers
cmake
ninja
qt6.qtshadertools
spirv-tools
qt6.wrapQtAppsHook
pkg-config
]
++ lib.optional withWayland wayland-scanner;
buildInputs = [ nativeBuildInputs = [
qt6.qtbase cmake
qt6.qtdeclarative ninja
cli11 qt6.qtshadertools
] spirv-tools
++ lib.optional withQtSvg qt6.qtsvg pkg-config
++ lib.optional withCrashReporter breakpad ]
++ lib.optional withJemalloc jemalloc ++ lib.optional withWayland wayland-scanner;
++ 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"; 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;
cmakeFlags = [ cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";
(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: cmakeFlags = [
# 1. build `quickshell.debug` (lib.cmakeFeature "DISTRIBUTOR" "Official-Nix-Flake")
# 2. set NIX_DEBUG_INFO_DIRS="<quickshell.debug store path>/lib/debug" (lib.cmakeFeature "INSTALL_QML_PREFIX" qt6.qtbase.qtQmlPrefix)
# 3. launch gdb / coredumpctl and debuginfo will work (lib.cmakeBool "DISTRIBUTOR_DEBUGINFO_AVAILABLE" true)
separateDebugInfo = !debug; (lib.cmakeFeature "GIT_REVISION" gitRev)
dontStrip = debug; (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)
];
meta = with lib; { # How to get debuginfo in gdb from a release build:
homepage = "https://quickshell.outfoxxed.me"; # 1. build `quickshell.debug`
description = "Flexbile QtQuick based desktop shell toolkit"; # 2. set NIX_DEBUG_INFO_DIRS="<quickshell.debug store path>/lib/debug"
license = licenses.lgpl3Only; # 3. launch gdb / coredumpctl and debuginfo will work
platforms = platforms.linux; separateDebugInfo = !debug;
mainProgram = "quickshell"; 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 {
inherit (unwrapped) version meta buildInputs;
pname = "${unwrapped.pname}-wrapped";
nativeBuildInputs = unwrapped.nativeBuildInputs ++ [ qt6.wrapQtAppsHook ];
dontUnpack = true;
dontConfigure = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin
# cp will create .quickshell-wrapped in path, ln will not. It is occasionally useful.
cp -r ${unwrapped}/bin/* $out/bin
ln -s ${unwrapped}/share $out/share
# not /lib
'';
passthru = {
unwrapped = unwrapped;
withModules = modules: wrapper.overrideAttrs (prev: {
buildInputs = prev.buildInputs ++ modules;
});
};
};
in wrapper