lol

nixos/redmine: Do some cleanups (#410671)

authored by

Arne Keller and committed by
GitHub
550eba04 b1ff2b0d

+83 -124
+3
.git-blame-ignore-revs
··· 266 266 267 267 # treewide: switch instances of lib.teams.*.members to the new meta.teams attribute 268 268 05580f4b4433fda48fff30f60dfd303d6ee05d21 269 + 270 + # nixos/redmine: Get rid of global lib expansions 271 + d7f1102f04c58b2edfc74c9a1d577e3aebfca775
+80 -124
nixos/modules/services/misc/redmine.nix
··· 6 6 }: 7 7 8 8 let 9 - inherit (lib) 10 - mkBefore 11 - mkDefault 12 - mkEnableOption 13 - mkPackageOption 14 - mkIf 15 - mkOption 16 - mkRemovedOptionModule 17 - types 18 - ; 19 - inherit (lib) concatStringsSep literalExpression mapAttrsToList; 20 - inherit (lib) optional optionalAttrs optionalString; 21 - 22 9 cfg = config.services.redmine; 23 10 format = pkgs.formats.yaml { }; 24 11 bundle = "${cfg.package}/share/redmine/bin/bundle"; ··· 30 17 database = 31 18 if cfg.database.type == "sqlite3" then "${cfg.stateDir}/database.sqlite3" else cfg.database.name; 32 19 } 33 - // optionalAttrs (cfg.database.type != "sqlite3") { 20 + // lib.optionalAttrs (cfg.database.type != "sqlite3") { 34 21 host = 35 22 if (cfg.database.type == "postgresql" && cfg.database.socket != null) then 36 23 cfg.database.socket ··· 39 26 port = cfg.database.port; 40 27 username = cfg.database.user; 41 28 } 42 - // optionalAttrs (cfg.database.type != "sqlite3" && cfg.database.passwordFile != null) { 29 + // lib.optionalAttrs (cfg.database.type != "sqlite3" && cfg.database.passwordFile != null) { 43 30 password = "#dbpass#"; 44 31 } 45 - // optionalAttrs (cfg.database.type == "mysql2" && cfg.database.socket != null) { 32 + // lib.optionalAttrs (cfg.database.type == "mysql2" && cfg.database.socket != null) { 46 33 socket = cfg.database.socket; 47 34 }; 48 35 }; ··· 75 62 in 76 63 { 77 64 imports = [ 78 - (mkRemovedOptionModule [ 65 + (lib.mkRemovedOptionModule [ 79 66 "services" 80 67 "redmine" 81 68 "extraConfig" 82 69 ] "Use services.redmine.settings instead.") 83 - (mkRemovedOptionModule [ 70 + (lib.mkRemovedOptionModule [ 84 71 "services" 85 72 "redmine" 86 73 "database" ··· 91 78 # interface 92 79 options = { 93 80 services.redmine = { 94 - enable = mkEnableOption "Redmine, a project management web application"; 81 + enable = lib.mkEnableOption "Redmine, a project management web application"; 95 82 96 - package = mkPackageOption pkgs "redmine" { 83 + package = lib.mkPackageOption pkgs "redmine" { 97 84 example = "redmine.override { ruby = pkgs.ruby_3_2; }"; 98 85 }; 99 86 100 - user = mkOption { 101 - type = types.str; 87 + user = lib.mkOption { 88 + type = lib.types.str; 102 89 default = "redmine"; 103 90 description = "User under which Redmine is ran."; 104 91 }; 105 92 106 - group = mkOption { 107 - type = types.str; 93 + group = lib.mkOption { 94 + type = lib.types.str; 108 95 default = "redmine"; 109 96 description = "Group under which Redmine is ran."; 110 97 }; 111 98 112 - address = mkOption { 113 - type = types.str; 99 + address = lib.mkOption { 100 + type = lib.types.str; 114 101 default = "0.0.0.0"; 115 102 description = "IP address Redmine should bind to."; 116 103 }; 117 104 118 - port = mkOption { 119 - type = types.port; 105 + port = lib.mkOption { 106 + type = lib.types.port; 120 107 default = 3000; 121 108 description = "Port on which Redmine is ran."; 122 109 }; 123 110 124 - stateDir = mkOption { 125 - type = types.path; 111 + stateDir = lib.mkOption { 112 + type = lib.types.path; 126 113 default = "/var/lib/redmine"; 127 114 description = "The state directory, logs and plugins are stored here."; 128 115 }; 129 116 130 - settings = mkOption { 117 + settings = lib.mkOption { 131 118 type = format.type; 132 119 default = { }; 133 120 description = '' ··· 135 122 <https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration> 136 123 for details. 137 124 ''; 138 - example = literalExpression '' 125 + example = lib.literalExpression '' 139 126 { 140 127 email_delivery = { 141 128 delivery_method = "smtp"; ··· 148 135 ''; 149 136 }; 150 137 151 - extraEnv = mkOption { 152 - type = types.lines; 138 + extraEnv = lib.mkOption { 139 + type = lib.types.lines; 153 140 default = ""; 154 141 description = '' 155 142 Extra configuration in additional_environment.rb. ··· 162 149 ''; 163 150 }; 164 151 165 - themes = mkOption { 166 - type = types.attrsOf types.path; 152 + themes = lib.mkOption { 153 + type = lib.types.attrsOf lib.types.path; 167 154 default = { }; 168 155 description = "Set of themes."; 169 - example = literalExpression '' 156 + example = lib.literalExpression '' 170 157 { 171 158 dkuk-redmine_alex_skin = builtins.fetchurl { 172 159 url = "https://bitbucket.org/dkuk/redmine_alex_skin/get/1842ef675ef3.zip"; ··· 176 163 ''; 177 164 }; 178 165 179 - plugins = mkOption { 180 - type = types.attrsOf types.path; 166 + plugins = lib.mkOption { 167 + type = lib.types.attrsOf lib.types.path; 181 168 default = { }; 182 169 description = "Set of plugins."; 183 - example = literalExpression '' 170 + example = lib.literalExpression '' 184 171 { 185 172 redmine_env_auth = builtins.fetchurl { 186 173 url = "https://github.com/Intera/redmine_env_auth/archive/0.6.zip"; ··· 191 178 }; 192 179 193 180 database = { 194 - type = mkOption { 195 - type = types.enum [ 181 + type = lib.mkOption { 182 + type = lib.types.enum [ 196 183 "mysql2" 197 184 "postgresql" 198 185 "sqlite3" ··· 202 189 description = "Database engine to use."; 203 190 }; 204 191 205 - host = mkOption { 206 - type = types.str; 192 + host = lib.mkOption { 193 + type = lib.types.str; 207 194 default = "localhost"; 208 195 description = "Database host address."; 209 196 }; 210 197 211 - port = mkOption { 212 - type = types.port; 198 + port = lib.mkOption { 199 + type = lib.types.port; 213 200 default = if cfg.database.type == "postgresql" then 5432 else 3306; 214 - defaultText = literalExpression "3306"; 201 + defaultText = lib.literalExpression "3306"; 215 202 description = "Database host port."; 216 203 }; 217 204 218 - name = mkOption { 219 - type = types.str; 205 + name = lib.mkOption { 206 + type = lib.types.str; 220 207 default = "redmine"; 221 208 description = "Database name."; 222 209 }; 223 210 224 - user = mkOption { 225 - type = types.str; 211 + user = lib.mkOption { 212 + type = lib.types.str; 226 213 default = "redmine"; 227 214 description = "Database user."; 228 215 }; 229 216 230 - passwordFile = mkOption { 231 - type = types.nullOr types.path; 217 + passwordFile = lib.mkOption { 218 + type = lib.types.nullOr lib.types.path; 232 219 default = null; 233 220 example = "/run/keys/redmine-dbpassword"; 234 221 description = '' ··· 237 224 ''; 238 225 }; 239 226 240 - socket = mkOption { 241 - type = types.nullOr types.path; 227 + socket = lib.mkOption { 228 + type = lib.types.nullOr lib.types.path; 242 229 default = 243 230 if mysqlLocal then 244 231 "/run/mysqld/mysqld.sock" ··· 246 233 "/run/postgresql" 247 234 else 248 235 null; 249 - defaultText = literalExpression "/run/mysqld/mysqld.sock"; 236 + defaultText = lib.literalExpression "/run/mysqld/mysqld.sock"; 250 237 example = "/run/mysqld/mysqld.sock"; 251 238 description = "Path to the unix socket file to use for authentication."; 252 239 }; 253 240 254 - createLocally = mkOption { 255 - type = types.bool; 241 + createLocally = lib.mkOption { 242 + type = lib.types.bool; 256 243 default = true; 257 244 description = "Create the database and database user locally."; 258 245 }; 259 246 }; 260 247 261 248 components = { 262 - subversion = mkOption { 263 - type = types.bool; 264 - default = false; 265 - description = "Subversion integration."; 266 - }; 249 + subversion = lib.mkEnableOption "Subversion integration."; 267 250 268 - mercurial = mkOption { 269 - type = types.bool; 270 - default = false; 271 - description = "Mercurial integration."; 272 - }; 251 + mercurial = lib.mkEnableOption "Mercurial integration."; 273 252 274 - git = mkOption { 275 - type = types.bool; 276 - default = false; 277 - description = "git integration."; 278 - }; 253 + git = lib.mkEnableOption "git integration."; 279 254 280 - cvs = mkOption { 281 - type = types.bool; 282 - default = false; 283 - description = "cvs integration."; 284 - }; 255 + cvs = lib.mkEnableOption "cvs integration."; 285 256 286 - breezy = mkOption { 287 - type = types.bool; 288 - default = false; 289 - description = "bazaar integration."; 290 - }; 257 + breezy = lib.mkEnableOption "bazaar integration."; 291 258 292 - imagemagick = mkOption { 293 - type = types.bool; 294 - default = false; 295 - description = "Allows exporting Gant diagrams as PNG."; 296 - }; 259 + imagemagick = lib.mkEnableOption "exporting Gant diagrams as PNG."; 297 260 298 - ghostscript = mkOption { 299 - type = types.bool; 300 - default = false; 301 - description = "Allows exporting Gant diagrams as PDF."; 302 - }; 261 + ghostscript = lib.mkEnableOption "exporting Gant diagrams as PDF."; 303 262 304 - minimagick_font_path = mkOption { 305 - type = types.str; 263 + minimagick_font_path = lib.mkOption { 264 + type = lib.types.str; 306 265 default = ""; 307 266 description = "MiniMagick font path"; 308 267 example = "/run/current-system/sw/share/X11/fonts/LiberationSans-Regular.ttf"; ··· 312 271 }; 313 272 314 273 # implementation 315 - config = mkIf cfg.enable { 316 - 274 + config = lib.mkIf cfg.enable { 317 275 assertions = [ 318 276 { 319 277 assertion = ··· 345 303 346 304 services.redmine.settings = { 347 305 production = { 348 - scm_subversion_command = optionalString cfg.components.subversion "${pkgs.subversion}/bin/svn"; 349 - scm_mercurial_command = optionalString cfg.components.mercurial "${pkgs.mercurial}/bin/hg"; 350 - scm_git_command = optionalString cfg.components.git "${pkgs.git}/bin/git"; 351 - scm_cvs_command = optionalString cfg.components.cvs "${pkgs.cvs}/bin/cvs"; 352 - scm_bazaar_command = optionalString cfg.components.breezy "${pkgs.breezy}/bin/bzr"; 353 - imagemagick_convert_command = optionalString cfg.components.imagemagick "${pkgs.imagemagick}/bin/convert"; 354 - gs_command = optionalString cfg.components.ghostscript "${pkgs.ghostscript}/bin/gs"; 306 + scm_subversion_command = lib.optionalString cfg.components.subversion "${pkgs.subversion}/bin/svn"; 307 + scm_mercurial_command = lib.optionalString cfg.components.mercurial "${pkgs.mercurial}/bin/hg"; 308 + scm_git_command = lib.optionalString cfg.components.git "${pkgs.git}/bin/git"; 309 + scm_cvs_command = lib.optionalString cfg.components.cvs "${pkgs.cvs}/bin/cvs"; 310 + scm_bazaar_command = lib.optionalString cfg.components.breezy "${pkgs.breezy}/bin/bzr"; 311 + imagemagick_convert_command = lib.optionalString cfg.components.imagemagick "${pkgs.imagemagick}/bin/convert"; 312 + gs_command = lib.optionalString cfg.components.ghostscript "${pkgs.ghostscript}/bin/gs"; 355 313 minimagick_font_path = "${cfg.components.minimagick_font_path}"; 356 314 }; 357 315 }; 358 316 359 - services.redmine.extraEnv = mkBefore '' 317 + services.redmine.extraEnv = lib.mkBefore '' 360 318 config.logger = Logger.new("${cfg.stateDir}/log/production.log", 14, 1048576) 361 319 config.logger.level = Logger::INFO 362 320 ''; 363 321 364 - services.mysql = mkIf mysqlLocal { 322 + services.mysql = lib.mkIf mysqlLocal { 365 323 enable = true; 366 - package = mkDefault pkgs.mariadb; 324 + package = lib.mkDefault pkgs.mariadb; 367 325 ensureDatabases = [ cfg.database.name ]; 368 326 ensureUsers = [ 369 327 { ··· 375 333 ]; 376 334 }; 377 335 378 - services.postgresql = mkIf pgsqlLocal { 336 + services.postgresql = lib.mkIf pgsqlLocal { 379 337 enable = true; 380 338 ensureDatabases = [ cfg.database.name ]; 381 339 ensureUsers = [ ··· 415 373 systemd.services.redmine = { 416 374 after = 417 375 [ "network.target" ] 418 - ++ optional mysqlLocal "mysql.service" 419 - ++ optional pgsqlLocal "postgresql.service"; 376 + ++ lib.optional mysqlLocal "mysql.service" 377 + ++ lib.optional pgsqlLocal "postgresql.service"; 420 378 wantedBy = [ "multi-user.target" ]; 421 379 environment.RAILS_ENV = "production"; 422 380 environment.RAILS_CACHE = "${cfg.stateDir}/cache"; ··· 426 384 with pkgs; 427 385 [ 428 386 ] 429 - ++ optional cfg.components.subversion subversion 430 - ++ optional cfg.components.mercurial mercurial 431 - ++ optional cfg.components.git git 432 - ++ optional cfg.components.cvs cvs 433 - ++ optional cfg.components.breezy breezy 434 - ++ optional cfg.components.imagemagick imagemagick 435 - ++ optional cfg.components.ghostscript ghostscript; 387 + ++ lib.optional cfg.components.subversion subversion 388 + ++ lib.optional cfg.components.mercurial mercurial 389 + ++ lib.optional cfg.components.git git 390 + ++ lib.optional cfg.components.cvs cvs 391 + ++ lib.optional cfg.components.breezy breezy 392 + ++ lib.optional cfg.components.imagemagick imagemagick 393 + ++ lib.optional cfg.components.ghostscript ghostscript; 436 394 437 395 preStart = '' 438 396 rm -rf "${cfg.stateDir}/plugins/"* ··· 453 411 454 412 455 413 # link in all user specified themes 456 - for theme in ${concatStringsSep " " (mapAttrsToList unpackTheme cfg.themes)}; do 414 + for theme in ${lib.concatStringsSep " " (lib.mapAttrsToList unpackTheme cfg.themes)}; do 457 415 ln -fs $theme/* "${cfg.stateDir}/themes" 458 416 done 459 417 ··· 462 420 463 421 464 422 # link in all user specified plugins 465 - for plugin in ${concatStringsSep " " (mapAttrsToList unpackPlugin cfg.plugins)}; do 423 + for plugin in ${lib.concatStringsSep " " (lib.mapAttrsToList unpackPlugin cfg.plugins)}; do 466 424 ln -fs $plugin/* "${cfg.stateDir}/plugins/''${plugin##*-redmine-plugin-}" 467 425 done 468 426 ··· 470 428 # handle database.passwordFile & permissions 471 429 cp -f ${databaseYml} "${cfg.stateDir}/config/database.yml" 472 430 473 - ${optionalString ((cfg.database.type != "sqlite3") && (cfg.database.passwordFile != null)) '' 431 + ${lib.optionalString ((cfg.database.type != "sqlite3") && (cfg.database.passwordFile != null)) '' 474 432 DBPASS="$(head -n1 ${cfg.database.passwordFile})" 475 433 sed -e "s,#dbpass#,$DBPASS,g" -i "${cfg.stateDir}/config/database.yml" 476 434 ''} ··· 527 485 SystemCallArchitectures = "native"; 528 486 UMask = 27; 529 487 }; 530 - 531 488 }; 532 489 533 - users.users = optionalAttrs (cfg.user == "redmine") { 490 + users.users = lib.optionalAttrs (cfg.user == "redmine") { 534 491 redmine = { 535 492 group = cfg.group; 536 493 home = cfg.stateDir; ··· 538 495 }; 539 496 }; 540 497 541 - users.groups = optionalAttrs (cfg.group == "redmine") { 498 + users.groups = lib.optionalAttrs (cfg.group == "redmine") { 542 499 redmine.gid = config.ids.gids.redmine; 543 500 }; 544 - 545 501 }; 546 502 547 503 meta.maintainers = with lib.maintainers; [ felixsinger ];