diff --git a/nixos/modules/services/monitoring/librenms.nix b/nixos/modules/services/monitoring/librenms.nix index 918c01ebaf22c..5275d61ecbdf6 100644 --- a/nixos/modules/services/monitoring/librenms.nix +++ b/nixos/modules/services/monitoring/librenms.nix @@ -5,7 +5,7 @@ let settingsFormat = pkgs.formats.json { }; configJson = settingsFormat.generate "librenms-config.json" cfg.settings; - package = pkgs.librenms.override { + package = cfg.package.override { logDir = cfg.logDir; dataDir = cfg.dataDir; }; @@ -60,6 +60,18 @@ in options.services.librenms = with lib; { enable = mkEnableOption "LibreNMS network monitoring system"; + package = lib.mkPackageOption pkgs "librenms" { }; + + finalPackage = lib.mkOption { + type = lib.types.package; + readOnly = true; + default = package; + defaultText = lib.literalExpression "package"; + description = '' + The final package used by the module. This is the package that has all overrides. + ''; + }; + user = mkOption { type = types.str; default = "librenms"; @@ -526,13 +538,25 @@ in User = cfg.user; Group = cfg.group; ExecStartPre = lib.mkIf cfg.database.createLocally [ - "!${pkgs.writeShellScript "librenms-db-init" '' - DB_PASSWORD=$(cat ${cfg.database.passwordFile} | tr -d '\n') - echo "ALTER USER '${cfg.database.username}'@'localhost' IDENTIFIED BY '$DB_PASSWORD';" | ${pkgs.mariadb}/bin/mysql - ${lib.optionalString cfg.useDistributedPollers '' - echo "ALTER USER '${cfg.database.username}'@'%' IDENTIFIED BY '$DB_PASSWORD';" | ${pkgs.mariadb}/bin/mysql - ''} - ''}" + "!${ + pkgs.writeShellScript "librenms-db-init" ( + if !isNull cfg.database.socket then + '' + echo "ALTER USER '${cfg.database.username}'@'localhost' IDENTIFIED VIA unix_socket;" | ${pkgs.mariadb}/bin/mysql --socket='${cfg.database.socket}' + ${lib.optionalString cfg.useDistributedPollers '' + echo "ALTER USER '${cfg.database.username}'@'%' IDENTIFIED VIA unix_socket;" | ${pkgs.mariadb}/bin/mysql --socket='${cfg.database.socket}' + ''} + '' + else + '' + DB_PASSWORD=$(cat ${cfg.database.passwordFile} | tr -d '\n') + echo "ALTER USER '${cfg.database.username}'@'localhost' IDENTIFIED BY '$DB_PASSWORD';" | ${pkgs.mariadb}/bin/mysql + ${lib.optionalString cfg.useDistributedPollers '' + echo "ALTER USER '${cfg.database.username}'@'%' IDENTIFIED BY '$DB_PASSWORD';" | ${pkgs.mariadb}/bin/mysql + ''} + '' + ) + }" ]; }; script = '' @@ -567,6 +591,7 @@ in then '' # use socket connection echo "DB_SOCKET=${cfg.database.socket}" >> ${cfg.dataDir}/.env + echo "DB_PASSWORD=null" >> ${cfg.dataDir}/.env '' else '' # use TCP connection