gitSource: add subdir option

This commit is contained in:
xenia 2024-06-05 00:34:50 -04:00
parent 1887330cac
commit 7d2c182c6e
2 changed files with 13 additions and 2 deletions

View File

@ -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 {

View File

@ -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; }