summaryrefslogtreecommitdiff
path: root/pkgs/dlnatoad/default.nix
blob: 7388ed0f58e0e7186daa8084c3baab037b210206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ pkgs }:
with pkgs;

let
  snapshotJar = "dlnatoad-1-SNAPSHOT-jar-with-dependencies.jar";

in stdenv.mkDerivation rec {
  name = "dlnatoad-${version}";
  version = "latest";

  src = fetchFromGitHub {
    owner = "haku";
    repo = "dlnatoad";
    rev = "837e801b8da5726f25e73a4fd70c991eccc942c5";
    sha256 = "060360q4n3li773rviq8ab1931l0gfk5w9dqpc0711prng5ywqy4";
  };

  buildInputs = [
    maven
    makeWrapper
  ];

  mavenDependenciesSHA256 = "1ly6xyhyal98pbwilx23rib3vkl2q9d0wpkrxhw12gzw1417kmxp";

  fetchedMavenDeps = stdenv.mkDerivation {
    name = "dlnatoad-${version}-maven-deps";
    inherit src buildInputs;
    buildPhase = ''
      mvn \
        --threads $NIX_BUILD_CORES \
        -Dmaven.repo.local=$out/.m2 \
        -Dmaven.test.skip=true \
        dependency:resolve-plugins \
        package
    '';
    installPhase = ''
      # delete files with lastModified timestamps inside.
      find $out/.m2 -type f \! -regex '.+\(pom\|jar\|xml\|sha1\)' -delete
    '';
    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = mavenDependenciesSHA256;
  };

  buildPhase = ''
    mvn \
      --offline \
      --threads $NIX_BUILD_CORES \
      -Dmaven.test.skip=true \
      -Dmaven.repo.local=$(cp -dpR ${fetchedMavenDeps}/.m2 ./ && chmod +w -R .m2 && pwd)/.m2 \
      package
  '';

  installPhase = ''
    mkdir -p $out/bin
    mkdir -p $out/share/java
    cp target/${snapshotJar} $out/share/java
    makeWrapper ${pkgs.jdk}/bin/java $out/bin/dlnatoad \
      --add-flags "-jar $out/share/java/${snapshotJar}"
  '';
}