From 83ed6b4d3bda16f629f71d58b368bb8937ce94d7 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 27 Aug 2024 20:43:29 +0200 Subject: [PATCH] nixos/services.graylog: remove `with lib;` --- nixos/modules/services/logging/graylog.nix | 73 +++++++++++----------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/nixos/modules/services/logging/graylog.nix b/nixos/modules/services/logging/graylog.nix index caeac16815f4..ff1860e99a75 100644 --- a/nixos/modules/services/logging/graylog.nix +++ b/nixos/modules/services/logging/graylog.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.services.graylog; confFile = pkgs.writeText "graylog.conf" '' - is_master = ${boolToString cfg.isMaster} + is_master = ${lib.boolToString cfg.isMaster} node_id_file = ${cfg.nodeIdFile} password_secret = ${cfg.passwordSecret} root_username = ${cfg.rootUsername} root_password_sha2 = ${cfg.rootPasswordSha2} - elasticsearch_hosts = ${concatStringsSep "," cfg.elasticsearchHosts} + elasticsearch_hosts = ${lib.concatStringsSep "," cfg.elasticsearchHosts} message_journal_dir = ${cfg.messageJournalDir} mongodb_uri = ${cfg.mongodbUri} plugin_dir = /var/lib/graylog/plugins @@ -34,49 +31,49 @@ in services.graylog = { - enable = mkEnableOption "Graylog, a log management solution"; + enable = lib.mkEnableOption "Graylog, a log management solution"; - package = mkOption { - type = types.package; - default = if versionOlder config.system.stateVersion "23.05" then pkgs.graylog-3_3 else pkgs.graylog-5_1; - defaultText = literalExpression (if versionOlder config.system.stateVersion "23.05" then "pkgs.graylog-3_3" else "pkgs.graylog-5_1"); + package = lib.mkOption { + type = lib.types.package; + default = if lib.versionOlder config.system.stateVersion "23.05" then pkgs.graylog-3_3 else pkgs.graylog-5_1; + defaultText = lib.literalExpression (if lib.versionOlder config.system.stateVersion "23.05" then "pkgs.graylog-3_3" else "pkgs.graylog-5_1"); description = "Graylog package to use."; }; - user = mkOption { - type = types.str; + user = lib.mkOption { + type = lib.types.str; default = "graylog"; description = "User account under which graylog runs"; }; - isMaster = mkOption { - type = types.bool; + isMaster = lib.mkOption { + type = lib.types.bool; default = true; description = "Whether this is the master instance of your Graylog cluster"; }; - nodeIdFile = mkOption { - type = types.str; + nodeIdFile = lib.mkOption { + type = lib.types.str; default = "/var/lib/graylog/server/node-id"; description = "Path of the file containing the graylog node-id"; }; - passwordSecret = mkOption { - type = types.str; + passwordSecret = lib.mkOption { + type = lib.types.str; description = '' You MUST set a secret to secure/pepper the stored user passwords here. Use at least 64 characters. Generate one by using for example: pwgen -N 1 -s 96 ''; }; - rootUsername = mkOption { - type = types.str; + rootUsername = lib.mkOption { + type = lib.types.str; default = "admin"; description = "Name of the default administrator user"; }; - rootPasswordSha2 = mkOption { - type = types.str; + rootPasswordSha2 = lib.mkOption { + type = lib.types.str; example = "e3c652f0ba0b4801205814f8b6bc49672c4c74e25b497770bb89b22cdeb4e952"; description = '' You MUST specify a hash password for the root user (which you only need to initially set up the @@ -88,40 +85,40 @@ in ''; }; - elasticsearchHosts = mkOption { - type = types.listOf types.str; - example = literalExpression ''[ "http://node1:9200" "http://user:password@node2:19200" ]''; + elasticsearchHosts = lib.mkOption { + type = lib.types.listOf lib.types.str; + example = lib.literalExpression ''[ "http://node1:9200" "http://user:password@node2:19200" ]''; description = "List of valid URIs of the http ports of your elastic nodes. If one or more of your elasticsearch hosts require authentication, include the credentials in each node URI that requires authentication"; }; - dataDir = mkOption { - type = types.str; + dataDir = lib.mkOption { + type = lib.types.str; default = "/var/lib/graylog/data"; description = "Directory used to store Graylog server state."; }; - messageJournalDir = mkOption { - type = types.str; + messageJournalDir = lib.mkOption { + type = lib.types.str; default = "/var/lib/graylog/data/journal"; description = "The directory which will be used to store the message journal. The directory must be exclusively used by Graylog and must not contain any other files than the ones created by Graylog itself"; }; - mongodbUri = mkOption { - type = types.str; + mongodbUri = lib.mkOption { + type = lib.types.str; default = "mongodb://localhost/graylog"; description = "MongoDB connection string. See http://docs.mongodb.org/manual/reference/connection-string/ for details"; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = "Any other configuration options you might want to add"; }; - plugins = mkOption { + plugins = lib.mkOption { description = "Extra graylog plugins"; default = [ ]; - type = types.listOf types.package; + type = lib.types.listOf lib.types.package; }; }; @@ -130,16 +127,16 @@ in ###### implementation - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { - users.users = mkIf (cfg.user == "graylog") { + users.users = lib.mkIf (cfg.user == "graylog") { graylog = { isSystemUser = true; group = "graylog"; description = "Graylog server daemon user"; }; }; - users.groups = mkIf (cfg.user == "graylog") { graylog = {}; }; + users.groups = lib.mkIf (cfg.user == "graylog") { graylog = {}; }; systemd.tmpfiles.rules = [ "d '${cfg.messageJournalDir}' - ${cfg.user} - - -"