NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.67k stars 13.12k forks source link

[Tracking issue] remove all `src = ./.` entries that unintentionally include their own `.nix` files #301014

Open philiptaron opened 3 months ago

philiptaron commented 3 months ago

Issue description

Derivations that use src = ./. will be rebuilt on any change to the .nix file that includes them, including formatting changes caused by nixfmt-rfc-style for RFC 166.

List of files where this may be the case

Generated with rg -F 'src = ./.' --sort=path -l -tnix and not very thoroughly audited. Unchecked entries need work or attention.

nixos-discourse commented 3 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/call-for-testing-nix-formatter/39179/21

oliviacrain commented 3 months ago

Did a quick check for false positives, found four:

Uses lib.cleanSourceWith to filter out default.nix

pkgs/build-support/node/fetch-npm-deps/default.nix maintainers/scripts/convert-to-import-cargo-lock/default.nix pkgs/misc/documentation-highlighter/default.nix

Found src = ./. in a comment

pkgs/build-support/release/default.nix

philiptaron commented 3 months ago

Thanks! I updated the listing to check those off.

infinisil commented 3 months ago

Note that we can use the new lib.fileset library (tutorial) to fix this now!

infinisil commented 1 month ago

Made a bunch of PRs to fix some of these, see the links above :)

philiptaron commented 1 month ago

Made a bunch of PRs to fix some of these, see the links above :)

All ✅ by me or someone else.

infinisil commented 1 month ago

Also mentioning it here, this is a hack to print the filtered out files of a fileset by default :P:

diff --git a/lib/fileset/default.nix b/lib/fileset/default.nix
index bb327226731e..32bfcf21ecf6 100644
--- a/lib/fileset/default.nix
+++ b/lib/fileset/default.nix
@@ -123,6 +123,7 @@ let
     isPath
     pathExists
     seq
+    trace
     typeOf
     nixVersion
     ;
@@ -473,6 +474,8 @@ in {
             - Set `fileset` to a file set that cannot contain files outside the `root` (${toString root}). This could change the files included in the result.''
     else
       seq sourceFilter
+      trace "lib.fileset.toSource: These files are excluded:"
+      seq (_printFileset (_difference (_singleton root) fileset))
       cleanSourceWith {
         name = "source";
         src = root;
infinisil commented 1 month ago

Whoops it looks like we missed https://github.com/NixOS/nixpkgs/pull/300428

philiptaron commented 1 month ago

For pkgs/tools/nix/nixos-option/default.nix, consider merging https://github.com/NixOS/nixpkgs/pull/313497 instead.

Atemu commented 3 weeks ago

@Infinidoge and I fixed fetchYarnDeps unaware of this tracking issue. It appears to have been missed in this list somehow, perhaps your regex needs updating.

https://github.com/NixOS/nixpkgs/pull/319623

infinisil commented 1 week ago

Fixing a bunch here: https://github.com/NixOS/nixpkgs/pull/326430