hercules-ci / gitignore.nix

Nix functions for filtering local git sources
The Unlicense
242 stars 19 forks source link

Add a file back after using gitIgnoreSource/cleanSourceWith #45

Open codygman opened 4 years ago

codygman commented 4 years ago

I have the following:

    root = pkgs.lib.cleanSourceWith
      { filter = (path: type:
          ! (builtins.any
            (r: (builtins.match r (builtins.baseNameOf path)) != null)
            [
              "README.md"
              "notes"
              "ops"
              "tf"
              ".ghcid"
              ".dir-locals.el"
              ".semaphore"
            ])
        );
        src = gitignoreSource ./. ++ [];
      } ;

This worked alright until in lorri/issues#415 it was recommended that I make generating hpack part of my build process. So I did that like this:

        preConfigure = ''
          echo "generating cabal file from package.yaml..."
          hpack
           '';

But now I need to unignore the cabal file so that lorri will watch changes to it. Is there a way to do this? Can I compose a function to add a filepath back after cleanSourceWith?

roberth commented 4 years ago

You can achieve this by using gitignoreFilter directly.

Since you're using hpack, you might be interested in pre-commit-hooks.nix, which had hpack support merged recently.

CMCDragonkai commented 2 years ago

Can you provide an example in gitignoreFilter how to apply a list of files/paths you want to ignore on top of whatever gitignoreSource does? I'm trying to replicate the old nix-gitignore.gitignoreSource:

  src = nix-gitignore.gitignoreSource [
    ".git" 
    "/*.nix" 
    ".*"
  ] ./.;
roberth commented 2 years ago

You can modify the filter expression at the nix level with gitignoreFilter, but currently there's no interface for inserting extra rules, or for working off manually provided rules only. These features can be added of course.