Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a31fd3cb7fd0
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9e6d7d3c744a
Choose a head ref

Commits on Sep 21, 2020

  1. bump: init at 0.2.2

    doronbehar committed Sep 21, 2020
    Copy the full SHA
    d784ae8 View commit details

Commits on Oct 5, 2020

  1. Copy the full SHA
    674c9af View commit details

Commits on Oct 11, 2020

  1. halide: 2019.08.27 -> 10.0.0

    OPNA2608 committed Oct 11, 2020
    Copy the full SHA
    2699d3f View commit details
  2. Copy the full SHA
    0a24ff0 View commit details

Commits on Oct 17, 2020

  1. Copy the full SHA
    e373dd9 View commit details
  2. Copy the full SHA
    4627d76 View commit details

Commits on Oct 20, 2020

  1. Copy the full SHA
    323b47d View commit details
  2. epgstation: 1.7.4 -> 1.7.5

    midchildan committed Oct 20, 2020
    Copy the full SHA
    e2a3a02 View commit details

Commits on Oct 21, 2020

  1. Copy the full SHA
    d59bfde View commit details

Commits on Oct 26, 2020

  1. kube3d: add completion for fish

    fish completion was added in 3.0.2
    https://github.com/rancher/k3d/releases/tag/v3.0.2
    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    4c812da View commit details
  2. kube3d: 3.0.2 -> 3.1.0

    Also bumped k3sVersion
    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    31ae30a View commit details
  3. kube3d: 3.1.0 -> 3.1.1

    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    caaca24 View commit details
  4. kube3d: 3.1.1 -> 3.1.2

    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    f280304 View commit details
  5. kube3d: 3.1.2 -> 3.1.3

    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    56de136 View commit details
  6. kube3d: 3.1.3 -> 3.1.4

    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    ba708de View commit details
  7. kube3d: 3.1.4 -> 3.1.5

    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    797a342 View commit details
  8. kube3d: add jk as a maintainer

    Add jk (myself) as a maintainer to help keeping kube3d working and
    up-to-date.
    06kellyjac committed Oct 26, 2020
    Copy the full SHA
    aaa2cf6 View commit details

Commits on Oct 27, 2020

  1. php: fix on darwin

    sikmir committed Oct 27, 2020
    Copy the full SHA
    e300f0f View commit details
  2. nixos/keycloak: Init

    talyz committed Oct 27, 2020
    Copy the full SHA
    513599a View commit details

Commits on Oct 28, 2020

  1. riak-cs: delete

    DianaOlympos committed Oct 28, 2020
    Copy the full SHA
    63caece View commit details

Commits on Oct 29, 2020

  1. fraunces: init at 1.000

    marsam committed Oct 29, 2020
    Copy the full SHA
    322aaa9 View commit details
  2. nixos/keycloak: Add test

    talyz committed Oct 29, 2020
    Copy the full SHA
    31fe90d View commit details
  3. Copy the full SHA
    fe5a16a View commit details
  4. Copy the full SHA
    c6e4388 View commit details
  5. Copy the full SHA
    d1d3c86 View commit details
  6. nixos/keycloak: Add support for MySQL and external DBs with SSL

    - Add support for using MySQL as an option to PostgreSQL.
    - Enable connecting to external DBs with SSL
    - Add a database port config option
    talyz committed Oct 29, 2020
    Copy the full SHA
    89e8383 View commit details
  7. numix-cursor-theme: patch inkscape command

    The generated cursor files were previously empty due to inkscape rejecting the command line argument. See #98481.
    stephaneyfx committed Oct 29, 2020
    Copy the full SHA
    d1cf7bd View commit details

Commits on Oct 31, 2020

  1. Copy the full SHA
    0989b93 View commit details

Commits on Nov 1, 2020

  1. Copy the full SHA
    495f997 View commit details
  2. linux_zen: add maintainer

    andresilva committed Nov 1, 2020
    Copy the full SHA
    c633a2e View commit details

Commits on Nov 2, 2020

  1. Copy the full SHA
    17ee53c View commit details
  2. Copy the full SHA
    1f7e201 View commit details
  3. icewm: 1.8.3 -> 1.9.0

    r-ryantm committed Nov 2, 2020
    Copy the full SHA
    eab501c View commit details
  4. deno: 1.5.0 -> 1.5.1

    06kellyjac committed Nov 2, 2020
    Copy the full SHA
    3c82813 View commit details
  5. python3Packages.azure-appconfiguration: 1.1.0 -> 1.1.1

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    6797200 View commit details
  6. python3Packages.azure-core: 1.8.1 -> 1.8.2

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    b7405df View commit details
  7. python3Packages.azure-datalake-store: 0.0.50 -> 0.0.51

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    7a64c2a View commit details
  8. python3Packages.azure-identity: 1.4.0 -> 1.4.1

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    1a89360 View commit details
  9. python3Packages.azure-mgmt-billing: 0.2.0 -> 1.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    7c05731 View commit details
  10. python3Packages.azure-mgmt-cognitiveservices: 6.2.0 -> 6.3.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    0c8ee0f View commit details
  11. python3Packages.azure-mgmt-containerservice: 9.4.0 -> 10.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    079761d View commit details
  12. python3Packages.azure-mgmt-core: 1.2.0 -> 1.2.1

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    0d96c45 View commit details
  13. python3Packages.azure-mgmt-datafactory: 0.13.0 -> 0.14.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    f4e45b8 View commit details
  14. python3Packages.azure-mgmt-hdinsight: 1.7.0 -> 2.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    247bf7e View commit details
  15. python3Packages.azure-mgmt-media: 2.2.0 -> 3.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    94888c0 View commit details
  16. python3Packages.azure-mgmt-search: 2.1.0 -> 3.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    d15b948 View commit details
  17. python3Packages.azure-mgmt-security: 0.4.1 -> 0.5.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    f60b397 View commit details
  18. python3Packages.azure-mgmt-servicebus: 0.6.0 -> 1.0.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    b41c236 View commit details
  19. python3Packages.azure-mgmt-sql: 0.22.0 -> 0.23.0

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    2b08bd3 View commit details
  20. python3Packages.azure-servicefabric: 7.1.0.45 -> 7.2.0.46

    Jonathan Ringer committed Nov 2, 2020
    Copy the full SHA
    5d4fdf5 View commit details
Showing with 7,079 additions and 4,474 deletions.
  1. +1 −0 doc/languages-frameworks/index.xml
  2. +354 −0 doc/languages-frameworks/maven.section.md
  3. +23 −1 nixos/doc/manual/release-notes/rl-2103.xml
  4. +4 −4 nixos/modules/misc/ids.nix
  5. +2 −3 nixos/modules/module-list.nix
  6. +0 −202 nixos/modules/services/databases/riak-cs.nix
  7. +0 −194 nixos/modules/services/databases/stanchion.nix
  8. +95 −0 nixos/modules/services/logging/promtail.nix
  9. +0 −89 nixos/modules/services/mail/freepops.nix
  10. +12 −5 nixos/modules/services/network-filesystems/ipfs.nix
  11. +5 −0 nixos/modules/services/networking/dhcpcd.nix
  12. +3 −1 nixos/modules/services/networking/ntp/chrony.nix
  13. +0 −31 nixos/modules/services/video/epgstation/generate
  14. +63 −63 nixos/modules/services/video/epgstation/streaming.json
  15. +692 −0 nixos/modules/services/web-apps/keycloak.nix
  16. +205 −0 nixos/modules/services/web-apps/keycloak.xml
  17. +1 −0 nixos/tests/all-tests.nix
  18. +4 −0 nixos/tests/initrd-network-ssh/default.nix
  19. +144 −0 nixos/tests/keycloak.nix
  20. +22 −9 nixos/tests/loki.nix
  21. +2 −2 pkgs/applications/audio/ft2-clone/default.nix
  22. +2 −2 pkgs/applications/audio/ncmpc/default.nix
  23. +2 −2 pkgs/applications/audio/ncpamixer/default.nix
  24. +2 −2 pkgs/applications/audio/picard/default.nix
  25. +34 −0 pkgs/applications/audio/ptcollab/default.nix
  26. +0 −16 pkgs/applications/graphics/gimp/plugins/default.nix
  27. +2 −2 pkgs/applications/graphics/krita/default.nix
  28. +2 −2 pkgs/applications/misc/dbeaver/default.nix
  29. +30 −14 pkgs/applications/misc/haxor-news/default.nix
  30. +3 −3 pkgs/applications/misc/hugo/default.nix
  31. +2 −2 pkgs/applications/misc/obsidian/default.nix
  32. +6 −1 pkgs/applications/networking/browsers/chromium/common.nix
  33. +2 −13 pkgs/applications/networking/browsers/chromium/default.nix
  34. +29 −1 pkgs/applications/networking/browsers/chromium/update.py
  35. +33 −9 pkgs/applications/networking/browsers/chromium/upstream-info.json
  36. +1 −0 pkgs/applications/networking/browsers/tor-browser-bundle-bin/default.nix
  37. +10 −8 pkgs/applications/networking/cluster/kube3d/default.nix
  38. +1 −0 pkgs/applications/networking/cluster/terraform-providers/default.nix
  39. +32 −0 pkgs/applications/networking/cluster/terraform-providers/hcloud/default.nix
  40. +21 −28 pkgs/applications/networking/cluster/terraform-providers/providers.json
  41. +2 −2 pkgs/applications/networking/instant-messengers/mcabber/default.nix
  42. +2 −2 pkgs/applications/networking/nextcloud-client/default.nix
  43. +19 −13 pkgs/applications/networking/sync/backintime/common.nix
  44. +26 −0 pkgs/applications/networking/sync/backintime/qt.nix
  45. +0 −28 pkgs/applications/networking/sync/backintime/qt4.nix
  46. +3 −3 pkgs/applications/networking/syncthing/default.nix
  47. +0 −25 pkgs/applications/science/biology/plink/default.nix
  48. +2 −2 pkgs/applications/science/chemistry/marvin/default.nix
  49. +2 −2 pkgs/applications/version-management/git-and-tools/git-machete/default.nix
  50. +0 −24 pkgs/applications/video/dvb-apps/default.nix
  51. +100 −63 pkgs/applications/video/epgstation/default.nix
  52. +0 −34 pkgs/applications/video/epgstation/generate.sh
  53. +43 −59 pkgs/applications/video/epgstation/package.json
  54. +66 −0 pkgs/applications/video/epgstation/update.nix
  55. +2 −2 pkgs/applications/virtualization/crun/default.nix
  56. +21 −0 pkgs/applications/virtualization/nvidia-docker/avoid-static-libtirpc-build.patch
  57. +38 −16 pkgs/applications/virtualization/nvidia-docker/libnvc.nix
  58. +2 −2 pkgs/applications/window-managers/i3/default.nix
  59. +20 −3 pkgs/applications/window-managers/i3/status-rust.nix
  60. +2 −2 pkgs/applications/window-managers/icewm/default.nix
  61. +25 −0 pkgs/data/fonts/fraunces/default.nix
  62. +10 −1 pkgs/data/icons/numix-cursor-theme/default.nix
  63. +2 −2 pkgs/data/icons/numix-icon-theme-circle/default.nix
  64. +2 −2 pkgs/data/icons/numix-icon-theme-square/default.nix
  65. +0 −30 pkgs/desktops/gnome-3/extensions/battery-status/default.nix
  66. +2 −2 pkgs/desktops/lxde/core/lxtask/default.nix
  67. +3 −3 pkgs/development/compilers/gleam/default.nix
  68. +167 −0 pkgs/development/compilers/graalvm/community-edition.nix
  69. +19 −31 pkgs/development/compilers/halide/default.nix
  70. +0 −56 pkgs/development/compilers/halide/nix.patch
  71. +2 −2 pkgs/development/compilers/owl-lisp/default.nix
  72. +1 −1 pkgs/development/interpreters/php/default.nix
  73. +3 −3 pkgs/development/interpreters/racket/default.nix
  74. +1 −1 pkgs/development/interpreters/racket/minimal.nix
  75. +2 −2 pkgs/development/libraries/java/lombok/default.nix
  76. +2 −2 pkgs/development/libraries/kdsoap/default.nix
  77. +2 −2 pkgs/development/libraries/libfilezilla/default.nix
  78. +4 −4 pkgs/development/libraries/libmwaw/default.nix
  79. +2 −2 pkgs/development/libraries/libqalculate/default.nix
  80. +2 −2 pkgs/development/libraries/libsolv/default.nix
  81. +2 −2 pkgs/development/libraries/osip/default.nix
  82. +1 −0 pkgs/development/node-packages/node-packages.json
  83. +4,128 −2,841 pkgs/development/node-packages/node-packages.nix
  84. +28 −0 pkgs/development/ocaml-modules/mirage-channel/default.nix
  85. +2 −2 pkgs/development/ocaml-modules/mirage-crypto/default.nix
  86. +2 −2 pkgs/development/php-packages/composer/2.0.nix
  87. +2 −2 pkgs/development/php-packages/phpstan/default.nix
  88. +2 −2 pkgs/development/php-packages/psalm/default.nix
  89. +2 −2 pkgs/development/python-modules/authlib/default.nix
  90. +2 −2 pkgs/development/python-modules/azure-appconfiguration/default.nix
  91. +2 −2 pkgs/development/python-modules/azure-core/default.nix
  92. +2 −2 pkgs/development/python-modules/azure-datalake-store/default.nix
  93. +2 −2 pkgs/development/python-modules/azure-identity/default.nix
  94. +3 −3 pkgs/development/python-modules/azure-mgmt-billing/default.nix
  95. +2 −2 pkgs/development/python-modules/azure-mgmt-cognitiveservices/default.nix
  96. +2 −2 pkgs/development/python-modules/azure-mgmt-containerservice/default.nix
  97. +2 −2 pkgs/development/python-modules/azure-mgmt-core/default.nix
  98. +2 −2 pkgs/development/python-modules/azure-mgmt-datafactory/default.nix
  99. +2 −2 pkgs/development/python-modules/azure-mgmt-hdinsight/default.nix
  100. +2 −2 pkgs/development/python-modules/azure-mgmt-media/default.nix
  101. +2 −2 pkgs/development/python-modules/azure-mgmt-search/default.nix
  102. +2 −2 pkgs/development/python-modules/azure-mgmt-security/default.nix
  103. +2 −2 pkgs/development/python-modules/azure-mgmt-servicebus/default.nix
  104. +2 −2 pkgs/development/python-modules/azure-mgmt-sql/default.nix
  105. +2 −2 pkgs/development/python-modules/azure-servicefabric/default.nix
  106. +31 −0 pkgs/development/python-modules/azure-synapse-artifacts/default.nix
  107. +1 −1 pkgs/development/python-modules/batchspawner/default.nix
  108. +2 −4 pkgs/development/python-modules/credstash/default.nix
  109. +1 −1 pkgs/development/python-modules/distro/default.nix
  110. +1 −1 pkgs/development/python-modules/dockerspawner/default.nix
  111. +1 −1 pkgs/development/python-modules/gym/default.nix
  112. +2 −2 pkgs/development/python-modules/kaitaistruct/default.nix
  113. +3 −0 pkgs/development/python-modules/nix-kernel/default.nix
  114. +2 −2 pkgs/development/python-modules/nvchecker/default.nix
  115. +34 −0 pkgs/development/python-modules/pandas-datareader/default.nix
  116. +2 −2 pkgs/development/python-modules/papis/default.nix
  117. +1 −1 pkgs/development/python-modules/wled/default.nix
  118. +1 −1 pkgs/development/tools/build-managers/gn/default.nix
  119. +2 −2 pkgs/development/tools/buildpack/default.nix
  120. +2 −2 pkgs/development/tools/coursier/default.nix
  121. +29 −0 pkgs/development/tools/github/bump/default.nix
  122. +3 −3 pkgs/development/web/deno/default.nix
  123. +3 −3 pkgs/games/minecraft-server/default.nix
  124. +2 −2 pkgs/games/scummvm/default.nix
  125. +2 −2 pkgs/misc/emulators/mgba/default.nix
  126. +74 −62 pkgs/misc/vim-plugins/generated.nix
  127. +1 −0 pkgs/misc/vim-plugins/vim-plugin-names
  128. +2 −2 pkgs/os-specific/linux/i2c-tools/default.nix
  129. +2 −2 pkgs/os-specific/linux/ipset/default.nix
  130. +2 −2 pkgs/os-specific/linux/kernel/linux-5.4.nix
  131. +2 −2 pkgs/os-specific/linux/kernel/linux-5.8.nix
  132. +2 −2 pkgs/os-specific/linux/kernel/linux-5.9.nix
  133. +3 −3 pkgs/os-specific/linux/kernel/linux-rt-5.4.nix
  134. +2 −2 pkgs/os-specific/linux/kernel/linux-testing.nix
  135. +4 −4 pkgs/os-specific/linux/kernel/linux-zen.nix
  136. +2 −2 pkgs/os-specific/linux/lxcfs/default.nix
  137. +40 −7 pkgs/servers/keycloak/default.nix
  138. +2 −2 pkgs/servers/lidarr/default.nix
  139. +0 −29 pkgs/servers/mail/freepops/default.nix
  140. +2 −2 pkgs/servers/monitoring/kapacitor/default.nix
  141. +2 −2 pkgs/servers/monitoring/munin/default.nix
  142. +2 −2 pkgs/servers/mqtt/mosquitto/default.nix
  143. +0 −70 pkgs/servers/nosql/riak-cs/2.1.1.nix
  144. +0 −65 pkgs/servers/nosql/riak-cs/stanchion.nix
  145. +35 −0 pkgs/servers/rtsp-simple-server/default.nix
  146. +5 −4 pkgs/servers/tailscale/default.nix
  147. +26 −0 pkgs/servers/tracing/tempo/default.nix
  148. +2 −2 pkgs/shells/liquidprompt/default.nix
  149. +2 −2 pkgs/shells/mksh/default.nix
  150. +4 −5 pkgs/tools/admin/azure-cli/default.nix
  151. +32 −13 pkgs/tools/admin/azure-cli/python-packages.nix
  152. +2 −2 pkgs/tools/admin/salt/default.nix
  153. +2 −2 pkgs/tools/filesystems/mtools/default.nix
  154. +2 −2 pkgs/tools/misc/cloud-utils/default.nix
  155. +2 −2 pkgs/tools/misc/fzf/default.nix
  156. +2 −2 pkgs/tools/misc/parallel/default.nix
  157. +2 −2 pkgs/tools/networking/dropbear/default.nix
  158. +2 −2 pkgs/tools/networking/i2pd/default.nix
  159. +2 −2 pkgs/tools/networking/oneshot/default.nix
  160. +3 −3 pkgs/tools/security/bitwarden_rs/default.nix
  161. +2 −2 pkgs/tools/security/bitwarden_rs/vault.nix
  162. +2 −2 pkgs/tools/system/memtester/default.nix
  163. +2 −2 pkgs/tools/system/monit/default.nix
  164. +0 −17 pkgs/tools/typesetting/pdf2htmlEX/add-glib-cmake.patch
  165. +0 −48 pkgs/tools/typesetting/pdf2htmlEX/default.nix
  166. +0 −17 pkgs/tools/video/flvtool2/default.nix
  167. +5 −0 pkgs/top-level/aliases.nix
  168. +19 −24 pkgs/top-level/all-packages.nix
  169. +2 −0 pkgs/top-level/ocaml-packages.nix
  170. +4 −0 pkgs/top-level/python-packages.nix
1 change: 1 addition & 0 deletions doc/languages-frameworks/index.xml
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
<xi:include href="ios.section.xml" />
<xi:include href="java.xml" />
<xi:include href="lua.section.xml" />
<xi:include href="maven.section.xml" />
<xi:include href="node.section.xml" />
<xi:include href="ocaml.xml" />
<xi:include href="perl.xml" />
354 changes: 354 additions & 0 deletions doc/languages-frameworks/maven.section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
---
title: Maven
author: Farid Zakaria
date: 2020-10-15
---

# Maven

Maven is a well-known build tool for the Java ecosystem however it has some challenges when integrating into the Nix build system.

The following provides a list of common patterns with how to package a Maven project (or any JVM language that can export to Maven) as a Nix package.

For the purposes of this example let's consider a very basic Maven project with the following `pom.xml` with a single dependency on [emoji-java](https://github.com/vdurmont/emoji-java).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.fzakaria</groupId>
<artifactId>maven-demo</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>NixOS Maven Demo</name>

<dependencies>
<dependency>
<groupId>com.vdurmont</groupId>
<artifactId>emoji-java</artifactId>
<version>5.1.1</version>
</dependency>
</dependencies>
</project>
```

Our main class file will be very simple:

```java
import com.vdurmont.emoji.EmojiParser;

public class Main {
public static void main(String[] args) {
String str = "NixOS :grinning: is super cool :smiley:!";
String result = EmojiParser.parseToUnicode(str);
System.out.println(result);
}
}
```

You find this demo project at https://github.com/fzakaria/nixos-maven-example

## Solving for dependencies

### buildMaven with NixOS/mvn2nix-maven-plugin

> ⚠️ Although `buildMaven` is the "blessed" way within nixpkgs, as of 2020, it hasn't seen much activity in quite a while.
`buildMaven` is an alternative method that tries to follow similar patterns of other programming languages by generating a lock file. It relies on the maven plugin [mvn2nix-maven-plugin](https://github.com/NixOS/mvn2nix-maven-plugin).

First you generate a `project-info.json` file using the maven plugin.

> This should be executed in the project's source repository or be told which `pom.xml` to execute with.
```bash
# run this step within the project's source repository
❯ mvn org.nixos.mvn2nix:mvn2nix-maven-plugin:mvn2nix

❯ cat project-info.json | jq | head
{
"project": {
"artifactId": "maven-demo",
"groupId": "org.nixos",
"version": "1.0",
"classifier": "",
"extension": "jar",
"dependencies": [
{
"artifactId": "maven-resources-plugin",
```
This file is then given to the `buildMaven` function, and it returns 2 attributes.
**`repo`**:
A Maven repository that is a symlink farm of all the dependencies found in the `project-info.json`
**`build`**:
A simple derivation that runs through `mvn compile` & `mvn package` to build the JAR. You may use this as inspiration for more complicated derivations.
Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository
```nix
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
(buildMaven ./project-info.json).repo
```
The benefit over the _double invocation_ as we will see below, is that the _/nix/store_ entry is a _linkFarm_ of every package, so that changes to your dependency set doesn't involve downloading everything from scratch.
```bash
❯ tree $(nix-build --no-out-link build-maven-repository.nix) | head
/nix/store/g87va52nkc8jzbmi1aqdcf2f109r4dvn-maven-repository
├── antlr
│   └── antlr
│   └── 2.7.2
│   ├── antlr-2.7.2.jar -> /nix/store/d027c8f2cnmj5yrynpbq2s6wmc9cb559-antlr-2.7.2.jar
│   └── antlr-2.7.2.pom -> /nix/store/mv42fc5gizl8h5g5vpywz1nfiynmzgp2-antlr-2.7.2.pom
├── avalon-framework
│   └── avalon-framework
│   └── 4.1.3
│   ├── avalon-framework-4.1.3.jar -> /nix/store/iv5fp3955w3nq28ff9xfz86wvxbiw6n9-avalon-framework-4.1.3.jar
```
### Double Invocation
> ⚠️ This pattern is the simplest but may cause unnecessary rebuilds due to the output hash changing.
The double invocation is a _simple_ way to get around the problem that `nix-build` may be sandboxed and have no Internet connectivity.
It treats the entire Maven repository as a single source to be downloaded, relying on Maven's dependency resolution to satisfy the output hash. This is similar to fetchers like `fetchgit`, except it has to run a Maven build to determine what to download.
The first step will be to build the Maven project as a fixed-output derivation in order to collect the Maven repository -- below is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/double-invocation-repository.nix).
> Traditionally the Maven repository is at `~/.m2/repository`. We will override this to be the `$out` directory.
```nix
{ stdenv, maven }:
stdenv.mkDerivation {
name = "maven-repository";
buildInputs = [ maven ];
src = ./.; # or fetchFromGitHub, cleanSourceWith, etc
buildPhase = ''
mvn package -Dmaven.repo.local=$out
'';

# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''
find $out -type f \
-name \*.lastUpdated -or \
-name resolver-status.properties -or \
-name _remote.repositories \
-delete
'';

# don't do any fixup
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
# replace this with the correct SHA256
outputHash = stdenv.lib.fakeSha256;
}
```
The build will fail, and tell you the expected `outputHash` to place. When you've set the hash, the build will return with a `/nix/store` entry whose contents are the full Maven repository.
> Some additional files are deleted that would cause the output hash to change potentially on subsequent runs.
```bash
❯ tree $(nix-build --no-out-link double-invocation-repository.nix) | head
/nix/store/8kicxzp98j68xyi9gl6jda67hp3c54fq-maven-repository
├── backport-util-concurrent
│   └── backport-util-concurrent
│   └── 3.1
│   ├── backport-util-concurrent-3.1.pom
│   └── backport-util-concurrent-3.1.pom.sha1
├── classworlds
│   └── classworlds
│   ├── 1.1
│   │   ├── classworlds-1.1.jar
```
If your package uses _SNAPSHOT_ dependencies or _version ranges_; there is a strong likelihood that over-time your output hash will change since the resolved dependencies may change. Hence this method is less recommended then using `buildMaven`.
## Building a JAR
Regardless of which strategy is chosen above, the step to build the derivation is the same.
```nix
{ stdenv, lib, maven, callPackage }:
# pick a repository derivation, here we will use buildMaven
let repository = callPackage ./build-maven-repository.nix { };
in stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
src = builtins.fetchTarball "https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
buildInputs = [ maven ];
buildPhase = ''
echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package;
'';
installPhase = ''
install -Dm644 target/${pname}-${version}.jar $out/share/java
'';
}
```
> We place the library in `$out/share/java` since JDK package has a _stdenv setup hook_ that adds any JARs in the `share/java` directories of the build inputs to the CLASSPATH environment.
```bash
❯ tree $(nix-build --no-out-link build-jar.nix)
/nix/store/7jw3xdfagkc2vw8wrsdv68qpsnrxgvky-maven-demo-1.0
└── share
└── java
└── maven-demo-1.0.jar
2 directories, 1 file
```
## Runnable JAR
The previous example builds a `jar` file but that's not a file one can run.
You need to use it with `java -jar $out/share/java/output.jar` and make sure to provide the required dependencies on the classpath.
The following explains how to use `makeWrapper` in order to make the derivation produce an executable that will run the JAR file you created.
We will use the same repository we built above (either _double invocation_ or _buildMaven_) to setup a CLASSPATH for our JAR.
The following two methods are more suited to Nix then building an [UberJar](https://imagej.net/Uber-JAR) which may be the more traditional approach.
### CLASSPATH
> This is ideal if you are providing a derivation for _nixpkgs_ and don't want to patch the project's `pom.xml`.
We will read the Maven repository and flatten it to a single list. This list will then be concatenated with the _CLASSPATH_ separator to create the full classpath.
We make sure to provide this classpath to the `makeWrapper`.
```nix
{ stdenv, lib, maven, callPackage, makeWrapper, jre }:
let
repository = callPackage ./build-maven-repository.nix { };
in stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
src = builtins.fetchTarball
"https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
buildInputs = [ maven makeWrapper ];
buildPhase = ''
echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package;
'';
installPhase = ''
mkdir -p $out/bin
classpath=$(find ${repository} -name "*.jar" -printf ':%h/%f');
install -Dm644 target/${pname}-${version}.jar $out/share/java
# create a wrapper that will automatically set the classpath
# this should be the paths from the dependency derivation
makeWrapper ${jre}/bin/java $out/bin/${pname} \
--add-flags "-classpath $out/share/java/${pname}-${version}.jar:''${classpath#:}" \
--add-flags "Main"
'';
}
```
### MANIFEST file via Maven Plugin
> This is ideal if you are the project owner and want to change your `pom.xml` to set the CLASSPATH within it.
Augment the `pom.xml` to create a JAR with the following manifest:
```xml
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>../../repository/</classpathPrefix>
<classpathLayoutType>repository</classpathLayoutType>
<mainClass>Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
```
The above plugin instructs the JAR to look for the necessary dependencies in the `lib/` relative folder. The layout of the folder is also in the _maven repository_ style.
```bash
❯ unzip -q -c $(nix-build --no-out-link runnable-jar.nix)/share/java/maven-demo-1.0.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: nixbld
Class-Path: . ../../repository/com/vdurmont/emoji-java/5.1.1/emoji-jav
a-5.1.1.jar ../../repository/org/json/json/20170516/json-20170516.jar
Created-By: Apache Maven 3.6.3
Build-Jdk: 1.8.0_265
Main-Class: Main
```
We will modify the derivation above to add a symlink to our repository so that it's accessible to our JAR during the `installPhase`.
```nix
{ stdenv, lib, maven, callPackage, makeWrapper, jre }:
# pick a repository derivation, here we will use buildMaven
let repository = callPackage ./build-maven-repository.nix { };
in stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
src = builtins.fetchTarball
"https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
buildInputs = [ maven makeWrapper ];
buildPhase = ''
echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package;
'';
installPhase = ''
mkdir -p $out/bin
# create a symbolic link for the repository directory
ln -s ${repository} $out/repository
install -Dm644 target/${pname}-${version}.jar $out/share/java
# create a wrapper that will automatically set the classpath
# this should be the paths from the dependency derivation
makeWrapper ${jre}/bin/java $out/bin/${pname} \
--add-flags "-jar $out/share/java/${pname}-${version}.jar"
'';
}
```
> Our script produces a dependency on `jre` rather than `jdk` to restrict the runtime closure necessary to run the application.
This will give you an executable shell-script that launches your JAR with all the dependencies available.
```bash
❯ tree $(nix-build --no-out-link runnable-jar.nix)
/nix/store/8d4c3ibw8ynsn01ibhyqmc1zhzz75s26-maven-demo-1.0
├── bin
│   └── maven-demo
├── repository -> /nix/store/g87va52nkc8jzbmi1aqdcf2f109r4dvn-maven-repository
└── share
└── java
└── maven-demo-1.0.jar
❯ $(nix-build --no-out-link --option tarball-ttl 1 runnable-jar.nix)/bin/maven-demo
NixOS 😀 is super cool 😃!
```
Loading