Skip to content

Commit bb9c688

Browse files
committed
Allow filtered sources
Fixes #31
1 parent b2bd70c commit bb9c688

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

buildGradleApplication/mkM2Repository.nix

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@
1111
repositories ? ["https://plugins.gradle.org/m2/" "https://repo1.maven.org/maven2/"],
1212
verificationFile ? "gradle/verification-metadata.xml",
1313
}: let
14-
filteredSrc = lib.fileset.toSource {
15-
root = src;
16-
fileset = lib.path.append src verificationFile;
17-
};
14+
verificationXmlFile =
15+
if lib.isPath src
16+
then lib.path.append src verificationFile
17+
else let
18+
storePathPrefix = "${src}/";
19+
in
20+
lib.cleanSourceWith {
21+
src = storePathPrefix;
22+
filter = path: type: let
23+
relPath = lib.removePrefix storePathPrefix path;
24+
in
25+
if type == "directory"
26+
then lib.strings.hasPrefix relPath verificationFile
27+
else relPath == verificationFile;
28+
}
29+
+ "/"
30+
+ verificationFile;
1831

1932
depSpecs = builtins.filter dependencyFilter (
2033
# Read all build and runtime dependencies from the verification-metadata XML
2134
builtins.fromJSON (builtins.readFile (
2235
runCommand "depSpecs" {buildInputs = [python3];}
23-
"python ${./parse.py} ${filteredSrc}/${verificationFile} ${builtins.toString (builtins.map lib.escapeShellArg repositories)}> $out"
36+
"python ${./parse.py} ${verificationXmlFile} ${builtins.toString (builtins.map lib.escapeShellArg repositories)}> $out"
2437
))
2538
);
2639
mkDep = depSpec: {
@@ -34,7 +47,7 @@
3447
# write a dedicated script for the m2 repository creation. Otherwise, the m2Repository derivation might crash with 'Argument list too long'
3548
m2Repository =
3649
runCommand "${pname}-${version}-m2-repository"
37-
{src = filteredSrc;}
50+
{}
3851
(
3952
"mkdir $out"
4053
+ lib.concatMapStringsSep "\n" (dep: "mkdir -p $out/${dep.path}\nln -s ${builtins.toString dep.jar} $out/${dep.path}/${dep.name}") dependencies

examples/hello-world/package.nix

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ in
1313
buildGradleApplication {
1414
inherit gradle version jdk;
1515
pname = "hello-world";
16-
src = ./.;
16+
src = lib.cleanSourceWith {
17+
src = lib.cleanSource ./.;
18+
filter = path: type: let
19+
ignore = builtins.elem (baseNameOf path);
20+
in
21+
! ignore [
22+
"package.nix"
23+
"gradlew.bat"
24+
"gradlew"
25+
];
26+
};
27+
1728
meta = with lib; {
1829
description = "Hello World Application";
1930
longDescription = ''

0 commit comments

Comments
 (0)