[Nix-dev] Building with default.nix

Bas van Dijk v.dijk.bas at gmail.com
Fri Aug 12 12:51:46 CEST 2016


Indeed, I use the following function in my projects:

  # Copy everything under src into the Nix store except
  # those paths that don't have one of the specified
  # allowedPrefixes.
  whitelistSource = src: allowedPrefixes:
    builtins.filterSource
      (path: type:
        lib.any (allowedPrefix: lib.hasPrefix
                   (toString (src + "/${allowedPrefix}"))
                   path
                ) allowedPrefixes
      ) src;

In my Haskell projects I use it like:

 src = whitelistSource ./. [
          "my-project.cabal"
          "src"
        ];

All other non-essential files like "dist", ".ghci", etc. are automatically
filtered out.

Bas

On 11 August 2016 at 18:50, Daniel Barlow <dan at telent.net> wrote:

> Have you considered using builtins.filterSource ?  I usually do something
> like this:
>
> let sourceFilesOnly = path: type:
>     (lib.hasPrefix "var" (toString path)) ||
>     (lib.hasPrefix "target" (toString path)) ;
> in stdenv.mkDerivation {
>     src = builtins.filterSource sourceFilesOnly ./.;
>     # ...
>
> It's not as tight as "git tracked files only" but works well enough for
> e.g. Clojure projects where I can reasonably get build artefacts to go into
> target/ so at least I'm not copying huge jar files into the store.
> Likewise in a Ruby project I'd exclude vendor/bundle the same way
>
> Any use?
>
> -dan
>
> --
> dan at telent.net
> http://ww.telent.net
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160812/a578e3ea/attachment-0001.html>


More information about the nix-dev mailing list