From 2854de4ef2b45acee31a4362ff1adf52eb2d0c47 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 2 Dec 2026 21:03:43 +0000 Subject: pkgs/rust: clean the packages' sources in the overlay A package file in pkgs/rust names its source as it is; the overlay builds a cleaned copy of it, and checks the plan against the source itself. So the copy can leave Cargo.lock out next to a Cargo.json, as before, while the lock check still has it. A source in the store already, like a fetched one, isn't copied again. --- pkgs/rust/default.nix | 17 ++++++++++++++--- pkgs/rust/enstate/default.nix | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'pkgs/rust') diff --git a/pkgs/rust/default.nix b/pkgs/rust/default.nix index 9d4f790d..318a6a9e 100644 --- a/pkgs/rust/default.nix +++ b/pkgs/rust/default.nix @@ -33,8 +33,8 @@ let { resolvedJson = path + "/Cargo.json"; }; # Checks the JSON plan against the checkout's Cargo.lock and Cargo.toml. - # These come from dir, not src, because cleanCargoSource drops Cargo.lock - # next to a Cargo.json. + # These come from the source itself, not its copy in the store, because + # cleanCargoSource leaves Cargo.lock out next to a Cargo.json. planChecks = dir: lib.optionalAttrs (builtins.pathExists (dir + "/Cargo.lock")) { cargoLock = dir + "/Cargo.lock"; @@ -42,6 +42,13 @@ let // lib.optionalAttrs (builtins.pathExists (dir + "/Cargo.toml")) { cargoToml = dir + "/Cargo.toml"; }; + + # A source in the store already, like a fetched one, stays as it is: + # copying it would only make another one. + cleanSource = name: src: + if lib.isStorePath (toString src) then src + else self.cleanCargoSource name src; + in { @@ -100,8 +107,12 @@ in lib.mapAttrs (pname: path: let args = callArgs path; + # The package file names the source as it is. A copy of it in the + # store gets built; the checks read the source itself, where + # Cargo.lock is even when the copy leaves it out. + src = cleanSource pname args.src; in - hrmPlan path args.src // args // planChecks args.src) + hrmPlan path src // args // { inherit src; } // planChecks args.src) explicitPackages; # Copies a Cargo workspace into the store, leaving out what the build diff --git a/pkgs/rust/enstate/default.nix b/pkgs/rust/enstate/default.nix index ab39cd41..dd375ddb 100644 --- a/pkgs/rust/enstate/default.nix +++ b/pkgs/rust/enstate/default.nix @@ -1,10 +1,10 @@ -{ cleanCargoSource, inputs, installShellFiles, runCommand }: +{ inputs, installShellFiles, runCommand }: { name = "enstate"; meta.mainProgram = "enstate"; # The populated source, as for the NixOS module. - src = cleanCargoSource "enstate" inputs.enstate; + src = inputs.enstate; # From the source as built, which can be a checkout instead. extraPaths = { src }: [ (runCommand "enstate-bash-completion" { -- cgit v1.3.1