Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos: Allow settings to be omitted with null #207

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions nixos/atticd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
};

Expand All @@ -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`";
};

Expand Down
10 changes: 10 additions & 0 deletions server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct Config {
pub require_proof_of_possession: bool,

/// Database connection.
#[serde(default = "Default::default")]
pub database: DatabaseConfig,

/// Storage.
Expand Down Expand Up @@ -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 {
Expand Down