diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix index 00b01bb..3fa4f64 100644 --- a/nix/nixos-module.nix +++ b/nix/nixos-module.nix @@ -39,6 +39,16 @@ let description = "Environment variables passed to the service."; }; + logLevel = mkOption { + type = types.nullOr (types.enum (builtins.attrValues logLevels)); + default = null; + example = logLevels.info; + description = '' + Log level to pass as RUST_LOG. Leave unset to use the service default or + set a custom RUST_LOG value through environment. + ''; + }; + extraArgs = mkOption { type = types.listOf types.str; default = [ ]; @@ -106,6 +116,19 @@ let cfg = config.services.microcosm; + constellationBackends = { + memory = "memory"; + rocks = "rocks"; + }; + + logLevels = { + error = "error"; + warn = "warn"; + info = "info"; + debug = "debug"; + trace = "trace"; + }; + optionalArg = flag: value: optionals (value != null) [ @@ -117,6 +140,11 @@ let name: args: let service = cfg.${name}; + environment = + service.environment + // lib.optionalAttrs (service.logLevel != null) { + RUST_LOG = service.logLevel; + }; in mkIf service.enable { systemd.services."microcosm-${name}" = { @@ -124,7 +152,7 @@ let wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; - environment = service.environment; + inherit environment; serviceConfig = { DynamicUser = true; @@ -149,11 +177,8 @@ in jetstream = jetstreamOption; dataDir = statePathOption "/var/lib/microcosm/constellation" "Directory for RocksDB data."; backend = mkOption { - type = types.enum [ - "memory" - "rocks" - ]; - default = "rocks"; + type = types.enum (builtins.attrValues constellationBackends); + default = constellationBackends.rocks; description = "Storage backend to use."; }; didWebDomain = mkOption { @@ -250,7 +275,7 @@ in cfg.constellation.backend ] ++ optionalArg "--jetstream" cfg.constellation.jetstream - ++ optionals (cfg.constellation.backend == "rocks") [ + ++ optionals (cfg.constellation.backend == constellationBackends.rocks) [ "--data" cfg.constellation.dataDir ]