From 965b289484d41255c707afd707e21ec193dc4793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 16 Jun 2024 13:50:55 +0200 Subject: [PATCH] [feat] package: reduce rebuilds Only copy Rust sources to reduce rebuilds if only nix stuff (or CI) changed. --- .cargo/config | 1 + default.nix | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 120000 .cargo/config diff --git a/.cargo/config b/.cargo/config new file mode 120000 index 0000000..ab8b69c --- /dev/null +++ b/.cargo/config @@ -0,0 +1 @@ +config.toml \ No newline at end of file diff --git a/default.nix b/default.nix index 4cd4398..a374ee4 100644 --- a/default.nix +++ b/default.nix @@ -6,13 +6,30 @@ cargoToml = readToml ./Cargo.toml; pname = cargoToml.package.name; inherit (cargoToml.package) version description; + src = lib.cleanSourceWith { + src = ./.; + name = "${pname}-source"; + # Adapted from + # no need to pull in crane for just this + filter = orig_path: type: let + path = toString orig_path; + base = baseNameOf path; + parentDir = baseNameOf (dirOf path); + matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [ + # Rust sources + ".rs" + # TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml) + ".toml" + ]; + isCargoLock = base == "Cargo.lock"; + # .cargo/config.toml is captured above + isOldStyleCargoConfig = parentDir == ".cargo" && base == "config"; + in + type == "directory" || matchesSuffix || isCargoLock || isOldStyleCargoConfig; + }; in rustPlatform.buildRustPackage { - inherit pname version; - src = builtins.path { - path = ./.; - name = "${pname}-source"; - }; + inherit pname version src; cargoLock.lockFile = ./Cargo.lock; useNextest = true;