Skip to content

Commit

Permalink
nixos: Allow settings to be omitted with null
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhaofengli committed Nov 21, 2024
1 parent 79b0ad0 commit 9c5e603
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit 9c5e603

Please sign in to comment.