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

lib.fileset needs something like lib.cleanSource #269517

Open
infinisil opened this issue Nov 23, 2023 · 0 comments
Open

lib.fileset needs something like lib.cleanSource #269517

infinisil opened this issue Nov 23, 2023 · 0 comments
Labels
5. scope: tracked Issue (or PR) is linked back to a `5. scope: tracking` issue

Comments

@infinisil
Copy link
Member

infinisil commented Nov 23, 2023

Issue description

lib.cleanSource filters out some of the most commonly unneeded files for you by default:

  1. The .git directory/file, but also other version control systems like .svn or .hg
  2. Editor backup/swap files like default.nix~
  3. Generated files like .o and .so (this one seems a bit weird to me)
  4. The result symlinks
  5. Files with unknown type, they can't be imported into the store anyways

While it's possible to use

lib.fileset.fromSource (lib.cleanSource ./.)

this is clunky and makes the fileset library reliant on lib.sources. We should eventually be able to deprecate lib.sources at some point, but then we need a replacement.

One can also set up manual filters, but it's not pretty:

lib.fileset.difference ./. (lib.fileset.unions [
  ./.git
  (fileFilter (file:
    file.hasExt "o"
    || file.hasExt "so"
    || lib.hasSuffix "~"
    || file.type == "symlink" && lib.hasPrefix "result" file.name
    || file.type == "unknown"
  ) ./.)
])

Ideas

lib.fileset.clean

One simple idea is to have a lib.fileset.clean ./. that does kind of the same.

I don't like how the filtered out files are fairly arbitrary though. What if another editor comes along and uses the .blorp file extension to store its swap files, would we add it to this function and risk breaking users? The file set library should stay backwards compatible.

Filter library

So another idea would be to allow creating a sort of library of filters, something like

{
  fileset.garbageFileFilter = {
    c = file: file.hasExt "o";
    emacs = file: lib.hasSuffix "~" file.name;
    nix = file: lib.hasPrefix "result" file.name && file.type == "symlink";
  };
}

Then these could be combined in a fileFilter as necessary. Maybe a bit too manual though.

Versioned lib.fileset.clean

Another idea (which could also use the above) would be to create a versioned clean function like

{
  fileset.clean = {
    v1 = fileFilter (file: ...);
    v2 = fileFilter (file: ...);
  };
}

Where each single version stays backwards compatible, but new ones can always be introduced as necessary.


This issue is sponsored by Antithesis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5. scope: tracked Issue (or PR) is linked back to a `5. scope: tracking` issue
Projects
None yet
Development

No branches or pull requests

2 participants