From 5a348fb7dfaf398922c119d21acb7d7f831f8688 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 24 Jun 2025 21:37:25 +0300 Subject: [PATCH] Nix: filter src using fileset Allows reusing already-built derivation when changing files outside the ones defined in the fileset. --- nix/default.nix | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 381867bec..fd3cb9d82 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -53,12 +53,12 @@ hidpiXWayland ? false, legacyRenderer ? false, }: let - inherit (builtins) baseNameOf foldl' readFile; + inherit (builtins) foldl' readFile; inherit (lib.asserts) assertMsg; inherit (lib.attrsets) mapAttrsToList; inherit (lib.lists) flatten concatLists optional optionals; - inherit (lib.sources) cleanSourceWith cleanSource; - inherit (lib.strings) hasSuffix makeBinPath optionalString mesonBool mesonEnable trim; + inherit (lib.strings) makeBinPath optionalString mesonBool mesonEnable trim; + fs = lib.fileset; adapters = flatten [ stdenvAdapters.useMoldLinker @@ -75,12 +75,28 @@ in pname = "hyprland${optionalString debug "-debug"}"; inherit version; - src = cleanSourceWith { - filter = name: _type: let - baseName = baseNameOf (toString name); - in - ! (hasSuffix ".nix" baseName); - src = cleanSource ../.; + src = fs.toSource { + root = ../.; + fileset = + fs.intersection + # allows non-flake builds to only include files tracked by git + (fs.gitTracked ../.) + (fs.unions [ + ../assets/hyprland-portals.conf + ../assets/install + ../hyprctl + ../hyprland.pc.in + ../LICENSE + ../meson_options.txt + ../protocols + ../src + ../systemd + ../VERSION + (fs.fileFilter (file: file.hasExt "1") ../docs) + (fs.fileFilter (file: file.hasExt "conf" || file.hasExt "desktop") ../example) + (fs.fileFilter (file: file.hasExt "sh") ../scripts) + (fs.fileFilter (file: file.name == "meson.build") ../.) + ]); }; postPatch = ''