1 { config, lib, pkgs, ... }:
4 cfg = config.services.youtrack;
8 (lib.mkRenamedOptionModule [ "services" "youtrack" "baseUrl" ] [ "services" "youtrack" "environmentalParameters" "base-url" ])
9 (lib.mkRenamedOptionModule [ "services" "youtrack" "port" ] [ "services" "youtrack" "environmentalParameters" "listen-port" ])
10 (lib.mkRemovedOptionModule [ "services" "youtrack" "maxMemory" ] "Please instead use `services.youtrack.generalParameters`.")
11 (lib.mkRemovedOptionModule [ "services" "youtrack" "maxMetaspaceSize" ] "Please instead use `services.youtrack.generalParameters`.")
14 options.services.youtrack = {
15 enable = lib.mkEnableOption "YouTrack service";
17 address = lib.mkOption {
19 The interface youtrack will listen on.
21 default = "127.0.0.1";
25 extraParams = lib.mkOption {
28 Extra parameters to pass to youtrack.
29 Use to configure YouTrack 2022.x, deprecated with YouTrack 2023.x. Use `services.youtrack.generalParameters`.
30 https://www.jetbrains.com/help/youtrack/standalone/YouTrack-Java-Start-Parameters.html
33 example = lib.literalExpression ''
35 "jetbrains.youtrack.overrideRootPassword" = "tortuga";
38 type = lib.types.attrsOf lib.types.str;
42 package = lib.mkOption {
46 type = lib.types.package;
48 relatedPackages = [ "youtrack_2022_3" "youtrack" ];
52 statePath = lib.mkOption {
54 Path were the YouTrack state is stored.
55 To this path the base version (e.g. 2023_1) of the used package will be appended.
57 type = lib.types.path;
58 default = "/var/lib/youtrack";
61 virtualHost = lib.mkOption {
63 Name of the nginx virtual host to use and setup.
64 If null, do not setup anything.
67 type = lib.types.nullOr lib.types.str;
70 jvmOpts = lib.mkOption {
72 Extra options to pass to the JVM.
73 Only has a use with YouTrack 2022.x, deprecated with YouTrack 2023.x. Use `serivces.youtrack.generalParameters`.
74 See https://www.jetbrains.com/help/youtrack/standalone/Configure-JVM-Options.html
77 type = lib.types.separatedString " ";
78 example = "--J-XX:MetaspaceSize=250m";
83 autoUpgrade = lib.mkOption {
84 type = lib.types.bool;
86 description = "Whether YouTrack should auto upgrade it without showing the upgrade dialog.";
89 generalParameters = lib.mkOption {
90 type = with lib.types; listOf str;
92 General configuration parameters and other JVM options.
93 Only has an effect for YouTrack 2023.x.
94 See https://www.jetbrains.com/help/youtrack/server/2023.3/youtrack-java-start-parameters.html#general-parameters
97 example = lib.literalExpression ''
99 "-Djetbrains.youtrack.admin.restore=true"
106 environmentalParameters = lib.mkOption {
107 type = lib.types.submodule {
108 freeformType = with lib.types; attrsOf (oneOf [ int str port ]);
110 listen-address = lib.mkOption {
111 type = lib.types.str;
113 description = "The interface YouTrack will listen on.";
115 listen-port = lib.mkOption {
116 type = lib.types.port;
118 description = "The port YouTrack will listen on.";
123 Environmental configuration parameters, set imperatively. The values doesn't get removed, when removed in Nix.
124 Only has an effect for YouTrack 2023.x.
125 See https://www.jetbrains.com/help/youtrack/server/2023.3/youtrack-java-start-parameters.html#environmental-parameters
126 for more information.
128 example = lib.literalExpression ''
137 config = lib.mkIf cfg.enable {
138 warnings = lib.optional (lib.versions.major cfg.package.version <= "2022")
139 "YouTrack 2022.x is deprecated. See https://nixos.org/manual/nixos/unstable/index.html#module-services-youtrack for details on how to upgrade."
140 ++ lib.optional (cfg.extraParams != {} && (lib.versions.major cfg.package.version >= "2023"))
141 "'services.youtrack.extraParams' is deprecated and has no effect on YouTrack 2023.x and newer. Please migrate to 'services.youtrack.generalParameters'"
142 ++ lib.optional (cfg.jvmOpts != "" && (lib.versions.major cfg.package.version >= "2023"))
143 "'services.youtrack.jvmOpts' is deprecated and has no effect on YouTrack 2023.x and newer. Please migrate to 'services.youtrack.generalParameters'";
145 # XXX: Drop all version feature switches at the point when we consider YT 2022.3 as outdated.
146 services.youtrack.package = lib.mkDefault (
147 if lib.versionAtLeast config.system.stateVersion "24.11" then pkgs.youtrack
148 else pkgs.youtrack_2022_3
151 services.youtrack.generalParameters = lib.optional (lib.versions.major cfg.package.version >= "2023")
152 "-Ddisable.configuration.wizard.on.upgrade=${lib.boolToString cfg.autoUpgrade}"
153 ++ (lib.mapAttrsToList (k: v: "-D${k}=${v}") cfg.extraParams);
155 systemd.services.youtrack = let
157 mergeAttrList = lib.foldl' lib.mergeAttrs {};
158 stdParams = mergeAttrList [
159 (lib.optionalAttrs (cfg.environmentalParameters ? base-url && cfg.environmentalParameters.base-url != null) {
160 "jetbrains.youtrack.baseUrl" = cfg.environmentalParameters.base-url;
163 "java.aws.headless" = "true";
164 "jetbrains.youtrack.disableBrowser" = "true";
167 extraAttr = lib.concatStringsSep " " (lib.mapAttrsToList (k: v: "-D${k}=${v}") (stdParams // cfg.extraParams));
169 environment.HOME = cfg.statePath;
170 environment.YOUTRACK_JVM_OPTS = "${extraAttr}";
171 after = [ "network.target" ];
172 wantedBy = [ "multi-user.target" ];
173 path = with pkgs; [ unixtools.hostname ];
178 Restart = "on-failure";
179 ExecStart = ''${cfg.package}/bin/youtrack ${cfg.jvmOpts} ${cfg.environmentalParameters.listen-address}:${toString cfg.environmentalParameters.listen-port}'';
183 jvmoptions = pkgs.writeTextFile {
184 name = "youtrack.jvmoptions";
185 text = (lib.concatStringsSep "\n" cfg.generalParameters);
188 package = cfg.package.override {
189 statePath = cfg.statePath;
192 after = [ "network.target" ];
193 wantedBy = [ "multi-user.target" ];
194 path = with pkgs; [ unixtools.hostname ];
196 # This detects old (i.e. <= 2022.3) installations that were not migrated yet
197 # and migrates them to the new state directory style
198 if [[ -d ${cfg.statePath}/teamsysdata ]] && [[ ! -d ${cfg.statePath}/2022_3 ]]
200 mkdir -p ${cfg.statePath}/2022_3
201 mv ${cfg.statePath}/teamsysdata ${cfg.statePath}/2022_3
202 mv ${cfg.statePath}/.youtrack ${cfg.statePath}/2022_3
204 mkdir -p ${cfg.statePath}/{backups,conf,data,logs,temp}
205 ${pkgs.coreutils}/bin/ln -fs ${jvmoptions} ${cfg.statePath}/conf/youtrack.jvmoptions
206 ${package}/bin/youtrack configure ${lib.concatStringsSep " " (lib.mapAttrsToList (name: value: "--${name}=${toString value}") cfg.environmentalParameters )}
208 serviceConfig = lib.mkMerge [
213 Restart = "on-failure";
214 ExecStart = "${package}/bin/youtrack run";
216 (lib.mkIf (cfg.statePath == "/var/lib/youtrack") {
217 StateDirectory = "youtrack";
221 in if (lib.versions.major cfg.package.version >= "2023") then service_zip else service_jar;
223 users.users.youtrack = {
224 description = "Youtrack service user";
226 home = cfg.statePath;
231 users.groups.youtrack = {};
233 services.nginx = lib.mkIf (cfg.virtualHost != null) {
234 upstreams.youtrack.servers."${cfg.address}:${toString cfg.environmentalParameters.listen-port}" = {};
235 virtualHosts.${cfg.virtualHost}.locations = {
237 proxyPass = "http://youtrack";
239 client_max_body_size 10m;
240 proxy_http_version 1.1;
241 proxy_set_header X-Forwarded-Host $http_host;
242 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
243 proxy_set_header X-Forwarded-Proto $scheme;
247 "/api/eventSourceBus" = {
248 proxyPass = "http://youtrack";
252 proxy_read_timeout 86400s;
253 proxy_send_timeout 86400s;
254 proxy_set_header Connection "";
255 chunked_transfer_encoding off;
256 client_max_body_size 10m;
257 proxy_http_version 1.1;
258 proxy_set_header X-Forwarded-Host $http_host;
259 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
260 proxy_set_header X-Forwarded-Proto $scheme;
267 meta.doc = ./youtrack.md;
268 meta.maintainers = [ lib.maintainers.leona ];