Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add positive source filter #8832

Merged
merged 3 commits into from
Aug 18, 2023

Conversation

roberth
Copy link
Member

@roberth roberth commented Aug 16, 2023

Motivation

This improves the source filter as promised.

Source filtering is a really nice Nix feature that lets us avoid a lot of rebuilds, which speeds up the iteration cycle a lot in cases where the relevant source files aren't actually modified.

We used to have a source filter that marked a few files as irrelevant, but this is the wrong approach, as we have many more files that are irrelevant. We may call this negative filtering.

This commit switches the source filtering to positive filtering, which is a lot more robust. Instead of marking which files we don't need we marked the files that we do need.

It's a superior approach because it is fail safe. Instead of allowing build performance problems to creep in over time, we require that all source inputs are declared.

I shouldn't have to explain that declaring inputs is a good practice, so I'll stop over-explaining here.

I do have to acknowledge that this will cause a build failure when the filter is incomplete. This is good, because it's the only realistic way we could be reminded of these problems. These events will be infrequent, so the small cost of extending the filter is worth it, compared to the hidden cost of longer dev cycles for things like tests, docker image, etc, etc.

Context

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 👍 to pull requests you find important.

Source filtering is a really cool Nix feature that lets us avoid a
lot of rebuilds, which speeds up the iteration cycle a lot in cases
where the relevant source files aren't actually modified.

We used to have a source filter that marked a few files as irrelevant,
but this is the wrong approach, as we have many more files that are
irrelevant. We may call this negative filtering.

This commit switches the source filtering to positive filtering, which
is a lot more robust. Instead of marking which files we don't need
we marked the files that we do need.

It's a superior approach because it is fail safe. Instead of allowing
build performance problems to creep in over time, we require that all
source inputs are declared.

I shouldn't have to explain that declaring inputs is a good practice,
so I'll stop over-explaining here.

I do have to acknowledge that this will cause a build failure when the
filter is incomplete. This is *good*, because it's the only realistic
way we could be reminded of these problems. These events will be
infrequent, so the small cost of extending the filter is worth it,
compared to the hidden cost of longer dev cycles for things like tests,
docker image, etc, etc.

(Also rebuilding Nix for stupid unnecessary reasons makes my blood boil)
@roberth roberth requested a review from edolstra as a code owner August 16, 2023 12:25
flake.nix Outdated
# - Propagation to dependent locks: https://github.com/NixOS/nix/issues/7730
# - Subflake would download redundant and huge parent flake
# - No git tree hash support: https://github.com/NixOS/nix/issues/6044
inherit (import (builtins.fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/1bdcd7fc8a6a40b2e805bad759b36e64e911036b.tar.gz"; sha256 = "sha256:14ljlpdsp4x7h1fkhbmc4bd3vsqnx8zdql4h3037wh09ad6a0893"; }))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is from an unmerged PR is there a risk it would go away?

Could we merge it and back port it? Or is that too much?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the tree to this repo using a merge commit now.

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely support the concept. This is much better than before. Just the one question on where we are fetching the filtering library from.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice to see the file set library being used here! I do have to point out that the code from the PR you're using (NixOS/nixpkgs#222981) hasn't been properly tested, but the first mergeable part of it (NixOS/nixpkgs#245623) now has a great test suite :)

@Ericson2314
Copy link
Member

@infinisil Are you saying that if we merge that second part, and backport it, it is enough for this?

@infinisil
Copy link
Member

@Ericson2314 Nope, it will take a bunch more work to get all the parts necessary for this. That second PR only adds lib.fileset.toSource, this here uses lib.fileset.{union,intersect,difference,fileFilter} as well

@Ericson2314
Copy link
Member

OK sounds good, thanks for approving this @infinisil and clarifying to me the Nixpkgs situation.

@roberth has also explained to me what is going on with the fetchTarball of the tree hash above. (I am delighted GitHub allows downloading by tree hash!) I want to add more detail to the comment, but we need to get to 23.05 to fix some things, so I will do that after we merge this.

@Ericson2314 Ericson2314 merged commit 0f1eb7c into NixOS:master Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants