nova-shell/flake.nix

185 lines
6.6 KiB
Nix

{
description = "nova-shell - minimal Quickshell bar for niri";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
quickshell = {
url = "git+https://git.outfoxxed.me/outfoxxed/quickshell";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
quickshell,
treefmt-nix,
...
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
];
treefmt-config = {
projectRootFile = "flake.nix";
programs.nixfmt.enable = true;
programs.qmlformat.enable = true;
programs.rustfmt.enable = true;
programs.taplo.enable = true;
programs.keep-sorted.enable = true;
};
# Patch qtbase wayland client to fix use-after-free in QWaylandSurface::oldestEnteredScreen.
# Waiting screens deleted via registry_global_remove leave dangling pointers in surface
# m_screens lists, crashing on the next screensChanged signal. Track surfaces in the
# display and scrub references before any screen deletion.
# TODO: remove once fixed upstream in Qt
qtbaseOverlay = final: prev: {
qt6 = prev.qt6.overrideScope (
qtFinal: qtPrev: {
qtbase = qtPrev.qtbase.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [ ./nix/patches/qtbase-wayland-screen-uaf.patch ];
});
}
);
};
forAllSystems =
fn:
nixpkgs.lib.genAttrs systems (
system:
fn rec {
pkgs = (nixpkgs.legacyPackages.${system}).extend qtbaseOverlay;
treefmt-eval = treefmt-nix.lib.evalModule pkgs treefmt-config;
}
);
in
{
formatter = forAllSystems ({ treefmt-eval, ... }: treefmt-eval.config.build.wrapper);
packages = forAllSystems (
{ pkgs, ... }:
let
# Rebuild quickshell against patched Qt via its overlay
qs = (pkgs.extend quickshell.overlays.default).quickshell.override {
withX11 = false;
withI3 = false;
};
nova-stats = pkgs.callPackage ./nix/stats-daemon.nix { };
nova-shaders = pkgs.callPackage ./nix/shaders.nix { };
in
rec {
inherit nova-stats nova-shaders;
nova-shell = pkgs.callPackage ./nix/package.nix {
quickshell = qs;
inherit nova-stats nova-shaders;
};
nova-shell-cli = pkgs.runCommand "nova-shell-cli" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
mkdir -p $out/bin
makeWrapper ${qs}/bin/quickshell $out/bin/nova-shell \
--add-flags "-p ${nova-shell}/share/nova-shell/shell.qml"
'';
docs = pkgs.callPackage ./nix/docs.nix { inherit self; };
default = nova-shell;
# Reproducer for the qtbase wayland screen UAF, built twice:
# patched (should survive) and unpatched (should crash).
screen-uaf-reproducer-patched = pkgs.stdenv.mkDerivation {
pname = "screen-uaf-reproducer-patched";
version = "0";
src = ./test/screen-uaf-reproducer;
nativeBuildInputs = [ pkgs.cmake pkgs.qt6.wrapQtAppsHook ];
buildInputs = [ pkgs.qt6.qtbase ];
};
screen-uaf-reproducer-unpatched =
let
rawPkgs = nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system};
in
rawPkgs.stdenv.mkDerivation {
pname = "screen-uaf-reproducer-unpatched";
version = "0";
src = ./test/screen-uaf-reproducer;
nativeBuildInputs = [ rawPkgs.cmake rawPkgs.qt6.wrapQtAppsHook ];
buildInputs = [ rawPkgs.qt6.qtbase ];
};
}
);
devShells = forAllSystems (
{ pkgs, ... }:
{
default = pkgs.mkShell {
packages = with pkgs; [
cargo
rustc
rust-analyzer
clippy
rustfmt
libnotify
qt6.qtdeclarative
];
};
}
);
checks = forAllSystems (
{ pkgs, treefmt-eval }:
{
formatting = treefmt-eval.config.build.check self;
build = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
nova-stats = self.packages.${pkgs.stdenv.hostPlatform.system}.nova-stats;
docs = self.packages.${pkgs.stdenv.hostPlatform.system}.docs;
qmllint =
pkgs.runCommand "nova-shell-qmllint"
{
nativeBuildInputs = [ pkgs.qt6.qtdeclarative ];
src = self;
}
''
cd $src
export QML_IMPORT_PATH="${pkgs.qt6.qtdeclarative}/lib/qt-6/qml:${
quickshell.packages.${pkgs.stdenv.hostPlatform.system}.default
}/lib/qt-6/qml"
qmllint -E \
-I shell/modules -I shell/services -I shell/applets -I shell/lock \
shell/shell.qml shell/modules/*.qml shell/services/*.qml \
shell/applets/*.qml shell/lock/*.qml \
> $TMPDIR/output.txt 2>&1 || true
# Extract unique warning messages (file:message, without line numbers)
grep -E "^Warning:" $TMPDIR/output.txt \
| sed 's/^Warning: //' \
| sed 's/\([^:]*\):[0-9]*:[0-9]*: /\1: /' \
| sort -u > $TMPDIR/current.txt
# Diff against known baseline - new warnings = failure
if ! diff -u test/qmllint-baseline.txt $TMPDIR/current.txt > $TMPDIR/diff.txt 2>&1; then
new=$(grep '^+[^+]' $TMPDIR/diff.txt || true)
if [ -n "$new" ]; then
echo "qmllint found new warnings not in baseline:"
echo "$new"
exit 1
fi
fi
cp $TMPDIR/output.txt $out
'';
nova-stats-clippy = (pkgs.callPackage ./nix/stats-daemon.nix { }).overrideAttrs (old: {
pname = "nova-stats-clippy";
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.clippy ];
buildPhase = "cargo clippy --all-targets -- -D warnings";
installPhase = "touch $out";
doCheck = false;
});
}
);
homeModules.default = import ./nix/hm-module.nix self;
homeManagerModules.default = self.homeModules.default;
};
}