From f2e8954923febf116e67af74627b7cc396756286 Mon Sep 17 00:00:00 2001 From: Shuxian Wang Date: Tue, 3 Jan 2023 23:09:23 -0800 Subject: [PATCH] Rework source filtering. To actually avoid triggering unnecessary rebuilds when irrelevant files change. --- .gitignore | 2 +- flake.lock | 16 ++++++++++++++++ flake.nix | 19 +++++++++++-------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 5b3f1de2..93276fce 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ vendor vendor.tar .vscode *.log -result +/result diff --git a/flake.lock b/flake.lock index e09079d3..9e570c51 100644 --- a/flake.lock +++ b/flake.lock @@ -90,6 +90,21 @@ "type": "github" } }, + "nix-filter": { + "locked": { + "lastModified": 1666547822, + "narHash": "sha256-razwnAybPHyoAyhkKCwXdxihIqJi1G6e1XP4FQOJTEs=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "1a3b735e13e90a8d2fd5629f2f8363bd7ffbbec7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1672428209, @@ -111,6 +126,7 @@ "crane": "crane", "fenix": "fenix", "flake-utils": "flake-utils_2", + "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 46beac60..4d9dbae7 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + nix-filter.url = "github:numtide/nix-filter"; crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; @@ -14,20 +15,22 @@ }; }; - outputs = { self, nixpkgs, flake-utils, crane, fenix }: + outputs = { self, nixpkgs, flake-utils, nix-filter, crane, fenix }: flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: let pkgs = nixpkgs.legacyPackages.${system}; craneLib = crane.lib.${system}.overrideToolchain fenix.packages.${system}.stable.toolchain; pkgDef = { - src = pkgs.nix-gitignore.gitignoreSource [ - "flake.nix" - "flake.lock" - "data" - "debian" - "LICENSE" - ] ./.; + src = nix-filter.lib.filter { + root = ./.; + include = [ + ./src + ./Cargo.toml + ./Cargo.lock + ./resources + ]; + }; nativeBuildInputs = with pkgs; [ pkg-config autoPatchelfHook ]; buildInputs = with pkgs; [ wayland