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

Comparison with cleanSourceWith #10

Open
asymmetric opened this issue May 5, 2021 · 3 comments
Open

Comparison with cleanSourceWith #10

asymmetric opened this issue May 5, 2021 · 3 comments

Comments

@asymmetric
Copy link

I'm currently using cleanSourceWith like:

      let srcFilter = path: type:
        let
          p = baseNameOf path;
        in
          !(
            # ignore CI directories
            (type == "directory" && (p == ".github" || p == "ci")) ||
            # ignore CI files
            p == ".travis.yml" || p == "cloudbuild.yaml" ||
            # ignore flake.(nix|lock)
            p == "flake.nix" || p == "flake.lock" ||
            # ignore docker files
            p == ".dockerignore" || p == "docker-compose.yml" ||
            # ignore misc
            p == "rustfmt.toml"
          );

         # ...

          src = pkgs.lib.cleanSourceWith {
            src = ./.;
            filter = srcFilter;
            name = "foo-source";
          };

What is the advantage of using nix-filter?

@ilkecan
Copy link
Contributor

ilkecan commented Sep 7, 2021

Compare yours to below

src = nix-filter {
  root = ./.;
  exclude = [
    .github
    ci
    .travis.yml
    ...
  ];
};

It is shorter and doesn't contain any visual clutter. You are only doing blacklisting on your example; once you start to do whitelisting baseNameOf path won't cut it anymore for the directories. You will need to also define something like relativePath = removePrefix (toString src) name inside the let expression and then check for hasPrefix dir relativePath.

It also provides some other utilities like matchExt that are documented in the README.

Like every library, it tries to create an reusable useful abstraction so that you don't have to reinvent or copy the same thing every time.

@zimbatm
Copy link
Member

zimbatm commented Jan 17, 2022

These filters need to be super precise in order to minimize rebuilds. The best way to do this is to make them easy to maintain and debug.

@fzakaria
Copy link
Contributor

I put cleanSourceWith on my ./. src root and it made the derivation take way longer interestingly

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

No branches or pull requests

4 participants