meli: support include statement (#7248)

so one can mix nix generated and manual configs

Instead of using `readFile` on the generated file, we included the generated config to avoid IFD. Because this approach makes ~/.config/meli/config.toml less readable (it referecens another generated file) I disabled it when the user does not "include" personal config. This feels a bit hackish but this is the best way I could find to keep the best of both worlds.
This commit is contained in:
Matthieu Coudron 2025-06-11 09:57:32 +02:00 committed by GitHub
parent 427c96044f
commit 450f06ec3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,10 @@ let
mkIf
;
cfg = config.programs.meli;
tomlFormat = pkgs.formats.toml { };
enabledAccounts = lib.attrsets.filterAttrs (
name: value: value.meli.enable or false
) config.accounts.email.accounts;
@ -72,6 +76,12 @@ in
description = "meli package to use";
};
includes = mkOption {
type = with types; listOf (str);
description = "Paths of the various meli configuration files to include.";
default = [ ];
};
settings = mkOption {
type = types.submodule {
freeformType = (pkgs.formats.toml { }).type;
@ -186,12 +196,26 @@ in
home.packages = [ config.programs.meli.package ];
# Generate meli configuration from email accounts
xdg.configFile."meli/config.toml".source = (pkgs.formats.toml { }).generate "meli-config" (
{
accounts = meliAccounts;
}
// config.programs.meli.settings
);
xdg.configFile."meli/config.toml" =
let
generatedToml = tomlFormat.generate "meli-config" (
{
accounts = meliAccounts;
}
// config.programs.meli.settings
);
in
if cfg.includes == [ ] then
{
source = generatedToml;
}
else
{
text = lib.concatStringsSep "\n" (
map (inc: "include(\"${inc}\")") (cfg.includes ++ [ generatedToml ])
);
};
};
}