From 79262acc9bd61e6c354c8689e63888bad06eab84 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Wed, 2 Apr 2025 10:37:09 +0200 Subject: [PATCH 1/8] README: Document the purpose of the two jars built by Nix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 656e4e0f5..0b7cd1dca 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ nix build # Flake version ``` In case you are using Nix Flakes, you can skip cloning the repository as usual: `nix build github:VariantSync/DiffDetective#.` -Afterward, the [result](result) symlink points to the [Javadoc](result/share/github-pages/DiffDetective/docs/javadoc/index.html), the [DiffDetective jar](result/share/java/DiffDetective/DiffDetective.jar) and a simple [script](result/bin/DiffDetective) for executing a DiffDetective main class provided as argument (e.g., evaluations used in previous research, see below under 'Publications'). +Afterward, the [result](result) symlink points to the [Javadoc](result/share/github-pages/DiffDetective/docs/javadoc/index.html), a [DiffDetective jar for use as a library](result/share/java/DiffDetective.jar), a [self contained DiffDetective jar with all dependencies included](result/share/java/DiffDetective/DiffDetective-jar-with-dependencies.jar) and a simple [script](result/bin/DiffDetective) for executing a DiffDetective main class provided as argument (e.g., evaluations used in previous research, see below under 'Publications'). ## How to Get Started From a54b459decbc73a4467bb4d0e1c664512be725b6 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Wed, 2 Apr 2025 10:29:30 +0200 Subject: [PATCH 2/8] nix: Rename the JAR with dependencies The difference between the two created Jars should be inferable without looking at the documentation. --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 70e65df3e..4117d38cb 100644 --- a/default.nix +++ b/default.nix @@ -134,7 +134,7 @@ pkgs.stdenvNoCC.mkDerivation rec { # install jars in "$out" install -Dm644 "target/diffdetective-${version}.jar" "$out/share/java/DiffDetective.jar" - local jar="$out/share/java/DiffDetective/DiffDetective.jar" + local jar="$out/share/java/DiffDetective/DiffDetective-jar-with-dependencies.jar" install -Dm644 "target/diffdetective-${version}-jar-with-dependencies.jar" "$jar" makeWrapper "${jre-minimal}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \ --prefix PATH : "${pkgs.graphviz}/bin" From 92680eea1c88ca914711193808a6014fba05038b Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:37:15 +0200 Subject: [PATCH 3/8] nix: Do not reduce the size of the JDK This is a remnant of building the docker container using Nix and was used to reduce the size of the docker container. For our current usage, this only increases complexity, brittleness and reduces maintainability. --- default.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 4117d38cb..8459dd052 100644 --- a/default.nix +++ b/default.nix @@ -93,10 +93,6 @@ pkgs.stdenvNoCC.mkDerivation rec { # build-time and run-time dependencies. outputs = ["out" "maven"]; - jre-minimal = pkgs.callPackage (import "${sources.nixpkgs}/pkgs/development/compilers/openjdk/jre.nix") { - modules = ["java.base" "java.desktop"]; - }; - buildPhase = '' runHook preBuild @@ -136,7 +132,7 @@ pkgs.stdenvNoCC.mkDerivation rec { install -Dm644 "target/diffdetective-${version}.jar" "$out/share/java/DiffDetective.jar" local jar="$out/share/java/DiffDetective/DiffDetective-jar-with-dependencies.jar" install -Dm644 "target/diffdetective-${version}-jar-with-dependencies.jar" "$jar" - makeWrapper "${jre-minimal}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \ + makeWrapper "${pkgs.jdk}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \ --prefix PATH : "${pkgs.graphviz}/bin" # install documentation in "$out" From 5d3a8446e09d6f85da019892c222888c15079223 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:37:57 +0200 Subject: [PATCH 4/8] nix: Reduce the usage of the `with` syntax Due to readability/understandability issues and the hardness for static analyzers, the usage of the `with` syntax is generally discouraged nowadays. --- default.nix | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/default.nix b/default.nix index 8459dd052..677d79f07 100644 --- a/default.nix +++ b/default.nix @@ -41,13 +41,13 @@ pkgs.stdenvNoCC.mkDerivation rec { fileset = gitTracked ./.; }; - nativeBuildInputs = with pkgs; [ - maven - makeWrapper - graphviz - ] ++ pkgs.lib.optional buildGitHubPages (ruby.withPackages (pkgs: with pkgs; [ - github-pages - jekyll-theme-cayman + nativeBuildInputs = [ + pkgs.maven + pkgs.makeWrapper + pkgs.graphviz + ] ++ pkgs.lib.optional buildGitHubPages (pkgs.ruby.withPackages (rubyPkgs: [ + rubyPkgs.github-pages + rubyPkgs.jekyll-theme-cayman ])); # Maven needs to download necessary dependencies which is impure because it @@ -58,7 +58,7 @@ pkgs.stdenvNoCC.mkDerivation rec { inherit version; src = pkgs.lib.sourceByRegex ./. ["^pom.xml$" "^local-maven-repo(/.*)?$"]; - nativeBuildInputs = with pkgs; [maven]; + nativeBuildInputs = [pkgs.maven]; buildPhase = '' runHook preBuild From f64da89b9d92f9398950eb26d1b6f55383fd1d70 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:38:12 +0200 Subject: [PATCH 5/8] nix: Specify dependencies a little bit more accurately This shouldn't make a real difference but makes this a little bit more explicit and maybe even more robust. --- default.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index 677d79f07..69ed09e43 100644 --- a/default.nix +++ b/default.nix @@ -33,8 +33,9 @@ pkgs.stdenvNoCC.mkDerivation rec { # The single source of truth for the version number is stored in `pom.xml`. # Hence, this XML file needs to be parsed to extract the current version. version = pkgs.lib.removeSuffix "\n" (pkgs.lib.readFile - (pkgs.runCommandLocal "DiffDetective-version" {} - "${pkgs.xq-xml}/bin/xq -x '/project/version' ${./pom.xml} > $out")); + (pkgs.runCommandLocal "DiffDetective-version" { + nativeBuildInputs = [pkgs.xq-xml]; + } "xq -x '/project/version' ${./pom.xml} > $out")); src = with pkgs.lib.fileset; toSource { root = ./.; @@ -44,12 +45,15 @@ pkgs.stdenvNoCC.mkDerivation rec { nativeBuildInputs = [ pkgs.maven pkgs.makeWrapper - pkgs.graphviz ] ++ pkgs.lib.optional buildGitHubPages (pkgs.ruby.withPackages (rubyPkgs: [ rubyPkgs.github-pages rubyPkgs.jekyll-theme-cayman ])); + nativeCheckInputs = [ + pkgs.graphviz + ]; + # Maven needs to download necessary dependencies which is impure because it # requires network access. Hence, we download all dependencies as a # fixed-output derivation. This also serves as a nice cache. From 81e033c088cb6557cf32b62fa3476e0b697dd8f5 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:38:58 +0200 Subject: [PATCH 6/8] nix: Expand variables as late as possible This makes overrides easier in my experience. --- default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 69ed09e43..0588f5df5 100644 --- a/default.nix +++ b/default.nix @@ -133,9 +133,9 @@ pkgs.stdenvNoCC.mkDerivation rec { runHook preInstall # install jars in "$out" - install -Dm644 "target/diffdetective-${version}.jar" "$out/share/java/DiffDetective.jar" + install -Dm644 "target/diffdetective-$version.jar" "$out/share/java/DiffDetective.jar" local jar="$out/share/java/DiffDetective/DiffDetective-jar-with-dependencies.jar" - install -Dm644 "target/diffdetective-${version}-jar-with-dependencies.jar" "$jar" + install -Dm644 "target/diffdetective-$version-jar-with-dependencies.jar" "$jar" makeWrapper "${pkgs.jdk}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \ --prefix PATH : "${pkgs.graphviz}/bin" From c59db0e209974f5bc4ee0f7a004cdf40ab3f1df6 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:39:45 +0200 Subject: [PATCH 7/8] nix: Improve some code formatting --- default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 0588f5df5..95dfa8592 100644 --- a/default.nix +++ b/default.nix @@ -136,13 +136,15 @@ pkgs.stdenvNoCC.mkDerivation rec { install -Dm644 "target/diffdetective-$version.jar" "$out/share/java/DiffDetective.jar" local jar="$out/share/java/DiffDetective/DiffDetective-jar-with-dependencies.jar" install -Dm644 "target/diffdetective-$version-jar-with-dependencies.jar" "$jar" - makeWrapper "${pkgs.jdk}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \ + makeWrapper \ + "${pkgs.jdk}/bin/java" "$out/bin/DiffDetective" \ + --add-flags "-cp \"$jar\"" \ --prefix PATH : "${pkgs.graphviz}/bin" - # install documentation in "$out" ${ if buildGitHubPages then '' + # install documentation in "$out" mkdir "$out/share/github-pages" cp -r _site "$out/share/github-pages/DiffDetective" '' From d8461fc9ed92dcbdafc62000f09216d266af44c9 Mon Sep 17 00:00:00 2001 From: Benjamin Moosherr Date: Thu, 3 Apr 2025 13:39:52 +0200 Subject: [PATCH 8/8] nix: Use a specific helper to improve robustness --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 95dfa8592..182886b9c 100644 --- a/default.nix +++ b/default.nix @@ -139,7 +139,7 @@ pkgs.stdenvNoCC.mkDerivation rec { makeWrapper \ "${pkgs.jdk}/bin/java" "$out/bin/DiffDetective" \ --add-flags "-cp \"$jar\"" \ - --prefix PATH : "${pkgs.graphviz}/bin" + --prefix PATH : "${pkgs.lib.makeBinPath [pkgs.graphviz]}" ${ if buildGitHubPages