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:
parent
427c96044f
commit
450f06ec3c
1 changed files with 30 additions and 6 deletions
|
|
@ -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 ])
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue