mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(flake): deep merge settings with defaults
This commit is contained in:
@@ -110,6 +110,16 @@
|
||||
}:
|
||||
let
|
||||
cfg = config.programs.noctalia-shell;
|
||||
defaultSettings = builtins.fromJSON (builtins.readFile ./Assets/settings-default.json);
|
||||
|
||||
# Deep merge user settings with defaults
|
||||
mergedSettings =
|
||||
if cfg.settings == null then
|
||||
defaultSettings
|
||||
else if builtins.isAttrs cfg.settings then
|
||||
lib.recursiveUpdate defaultSettings cfg.settings
|
||||
else
|
||||
cfg.settings; # Pass through strings/paths as-is
|
||||
in
|
||||
{
|
||||
options.programs.noctalia-shell = {
|
||||
@@ -144,6 +154,8 @@
|
||||
description = ''
|
||||
Noctalia shell configuration settings as an attribute set, string
|
||||
or filepath, to be written to ~/.config/noctalia/settings.json.
|
||||
When provided as an attribute set, it will be deep-merged with
|
||||
the default settings.
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -189,18 +201,16 @@
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
xdg.configFile = {
|
||||
"noctalia/settings.json" = lib.mkIf (cfg.settings != null) (
|
||||
{
|
||||
onChange = restart;
|
||||
}
|
||||
// (
|
||||
if builtins.isAttrs cfg.settings then
|
||||
{ text = builtins.toJSON cfg.settings; }
|
||||
else if builtins.isString cfg.settings then
|
||||
{ text = cfg.settings; }
|
||||
else
|
||||
{ source = cfg.settings; }
|
||||
)
|
||||
"noctalia/settings.json" = {
|
||||
onChange = restart;
|
||||
}
|
||||
// (
|
||||
if builtins.isAttrs mergedSettings then
|
||||
{ text = builtins.toJSON mergedSettings + "\n"; }
|
||||
else if builtins.isString mergedSettings then
|
||||
{ text = mergedSettings; }
|
||||
else
|
||||
{ source = mergedSettings; }
|
||||
);
|
||||
"noctalia/colors.json" = lib.mkIf (cfg.colors != null) (
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user