diff --git a/README.md b/README.md index 95a8c53..e898a66 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,11 @@ pkgs.mkNginxServer { for development package nix files, computes the source set of files tracked by git at the given root path +arguments: +- `root`: the root of the git repo, where `.git` is located +- `subdir`, optional: a subdirectory within the git repo. if provided, only files in this + subdirectory will go into the final source set + example: ```nix stdenv.mkDerivation { diff --git a/lib/git-source/default.nix b/lib/git-source/default.nix index 9ed4f6f..d9b68b7 100644 --- a/lib/git-source/default.nix +++ b/lib/git-source/default.nix @@ -1,8 +1,14 @@ -{ lib }: { root }: +{ lib }: { root, subdir ? null }: let fs = lib.fileset; sourceFiles = fs.difference (fs.gitTracked root) (fs.fileFilter (file: file.hasExt "nix") root); + finalSourceFiles = + if subdir == null then + sourceFiles + else + fs.intersection sourceFiles subdir; + finalRoot = if subdir == null then root else subdir; in - fs.toSource { inherit root; fileset = sourceFiles; } + fs.toSource { root = finalRoot; fileset = sourceFiles; }