4

This derivation seems to include all files in the current directory, recursively, as expected:

src = builtins.path {
  name = pname;
  path = ./.;
};

I'd like to only include a small subset of that; content/index.html and package.json. But my filter seems to be excluding everything:

src = builtins.path {
  name = pname;
  path = ./.;
  filter = path: type:
    builtins.elem path [
      ./content/index.html
      ./package.json
    ];
};

At least according to pkgs.mkYarnPackage:

error: opening file '/nix/store/[…]/package.json': No such file or directory

What's wrong with my filter?

The following filter does work, but is a bit of a hack:

filter = path: type:
  builtins.elem (baseNameOf path) [
    "index.html"
    "package.json"
  ];

I guess there's some issue with the equality of ./package.json and the src entry. Are the paths returned by builtins.path not the same data type/values as ./foo?

l0b0
  • 51,350

1 Answers1

3

Found the answer: converting builtins.path entries to paths is as simple as this:

filter = path: type:
  builtins.elem (/. + path) [
    ./content
    ./content/index.html
    ./package.json
  ];

(You have to list each directory in addition to its contents.)

l0b0
  • 51,350