From 79b0ad05535da9c36437cb71df744d0ac6b4986b Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Thu, 21 Nov 2024 13:29:00 -0700 Subject: [PATCH 1/2] server/config: Allow omitting database section entirely --- server/src/config.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/config.rs b/server/src/config.rs index 11e1f8d..3c04dd9 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -105,6 +105,7 @@ pub struct Config { pub require_proof_of_possession: bool, /// Database connection. + #[serde(default = "Default::default")] pub database: DatabaseConfig, /// Storage. @@ -418,6 +419,15 @@ fn load_database_url_from_env() -> String { )) } +impl Default for DatabaseConfig { + fn default() -> Self { + Self { + url: load_database_url_from_env(), + heartbeat: default_db_heartbeat(), + } + } +} + impl Default for JWTConfig { fn default() -> Self { Self { From 9c5e603e4b5077fdbed57136a49765772eb6bc41 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Thu, 21 Nov 2024 13:29:00 -0700 Subject: [PATCH 2/2] nixos: Allow settings to be omitted with null This allows for suppressing the default database.url setting in the NixOS module. In the future, we need to rethink about the precedence of configuration sources. It makes sense for the environment variables to take precedence over configuration files. --- nixos/atticd.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nixos/atticd.nix b/nixos/atticd.nix index e676fb1..4b2e8f4 100644 --- a/nixos/atticd.nix +++ b/nixos/atticd.nix @@ -15,6 +15,9 @@ let overlay = flake.defaultNix.overlays.default; format = pkgs.formats.toml { }; + filteredSettings = lib.converge + (lib.filterAttrsRecursive (_: v: ! lib.elem v [{ } null])) + cfg.settings; checkedConfigFile = pkgs.runCommand "checked-attic-server.toml" @@ -113,7 +116,17 @@ in description = '' Structured configurations of atticd. ''; - type = format.type; + type = let + valueType = with types; nullOr (oneOf [ + bool + int + float + str + path + (attrsOf valueType) + (listOf valueType) + ]); + in types.attrsOf valueType; default = { }; # setting defaults here does not compose well }; @@ -124,7 +137,7 @@ in By default, it's generated from `services.atticd.settings`. ''; type = types.path; - default = format.generate "server.toml" cfg.settings; + default = format.generate "server.toml" filteredSettings; defaultText = "generated from `services.atticd.settings`"; };