diff --git a/distro/nix/home.nix b/distro/nix/home.nix index 696be8a0..444f14f0 100644 --- a/distro/nix/home.nix +++ b/distro/nix/home.nix @@ -16,6 +16,12 @@ let dmsPkgs ; }; + hasPluginSettings = lib.any (plugin: plugin.settings != { }) ( + lib.attrValues (lib.filterAttrs (n: v: v.enable) cfg.plugins) + ); + pluginSettings = lib.mapAttrs (name: plugin: { enabled = plugin.enable; } // plugin.settings) ( + lib.filterAttrs (n: v: v.enable) cfg.plugins + ); in { imports = [ @@ -24,25 +30,48 @@ in "programs" "dank-material-shell" "enableNightMode" - ] "Night mode is now always available.") + ] "Night mode is now always available") + (lib.mkRemovedOptionModule [ + "programs" + "dank-material-shell" + "default" + "settings" + ] "Default settings have been removed and been replaced with programs.dank-material-shell.settings") + (lib.mkRemovedOptionModule [ + "programs" + "dank-material-shell" + "default" + "session" + ] "Default session has been removed and been replaced with programs.dank-material-shell.session") (lib.mkRenamedOptionModule [ "programs" "dank-material-shell" "enableSystemd" ] [ "programs" "dank-material-shell" "systemd" "enable" ] ) ]; - options.programs.dank-material-shell = with lib.types; { - default = { - settings = lib.mkOption { - type = jsonFormat.type; - default = { }; - description = "The default settings are only read if the settings.json file don't exist"; - }; - session = lib.mkOption { - type = jsonFormat.type; - default = { }; - description = "The default session are only read if the session.json file don't exist"; - }; + options.programs.dank-material-shell = { + settings = lib.mkOption { + type = jsonFormat.type; + default = { }; + description = "DankMaterialShell configuration settings as an attribute set, to be written to ~/.config/DankMaterialShell/settings.json."; + }; + + clipboardSettings = lib.mkOption { + type = jsonFormat.type; + default = { }; + description = "DankMaterialShell clipboard settings as an attribute set, to be written to ~/.config/DankMaterialShell/clsettings.json."; + }; + + session = lib.mkOption { + type = jsonFormat.type; + default = { }; + description = "DankMaterialShell session settings as an attribute set, to be written to ~/.local/state/DankMaterialShell/session.json."; + }; + + managePluginSettings = lib.mkOption { + type = lib.types.bool; + default = hasPluginSettings; + description = ''Whether to manage plugin settings. Automatically enabled if any plugins have settings configured.''; }; }; @@ -67,22 +96,28 @@ in Install.WantedBy = [ config.wayland.systemd.target ]; }; - xdg.stateFile."DankMaterialShell/default-session.json" = lib.mkIf (cfg.default.session != { }) { - source = jsonFormat.generate "default-session.json" cfg.default.session; + xdg.stateFile."DankMaterialShell/session.json" = lib.mkIf (cfg.session != { }) { + source = jsonFormat.generate "session.json" cfg.session; }; - xdg.configFile = lib.mkMerge [ - (lib.mapAttrs' (name: value: { - name = "DankMaterialShell/plugins/${name}"; - inherit value; - }) common.plugins) - { - "DankMaterialShell/default-settings.json" = lib.mkIf (cfg.default.settings != { }) { - source = jsonFormat.generate "default-settings.json" cfg.default.settings; - }; - } - ]; - + xdg.configFile = { + "DankMaterialShell/settings.json" = lib.mkIf (cfg.settings != { }) { + source = jsonFormat.generate "settings.json" cfg.settings; + }; + "DankMaterialShell/clsettings.json" = lib.mkIf (cfg.clipboardSettings != { }) { + source = jsonFormat.generate "clsettings.json" cfg.clipboardSettings; + }; + "DankMaterialShell/plugin_settings.json" = lib.mkIf cfg.managePluginSettings { + source = jsonFormat.generate "plugin_settings.json" pluginSettings; + }; + } + // (lib.mapAttrs' (name: value: { + name = "DankMaterialShell/plugins/${name}"; + inherit value; + }) common.plugins); + warnings = + lib.optional (!cfg.managePluginSettings && hasPluginSettings) + "You have disabled managePluginSettings but provided plugin settings. These settings will be ignored."; home.packages = common.packages; }; } diff --git a/distro/nix/options.nix b/distro/nix/options.nix index e19358cd..24a82278 100644 --- a/distro/nix/options.nix +++ b/distro/nix/options.nix @@ -10,7 +10,7 @@ let "programs" "dank-material-shell" ]; - + jsonFormat = pkgs.formats.json { }; builtInRemovedMsg = "This is now built-in in DMS and doesn't need additional dependencies."; in { @@ -37,7 +37,7 @@ in }; dgop = { - package = lib.mkPackageOption pkgs "dgop" {}; + package = lib.mkPackageOption pkgs "dgop" { }; }; enableSystemMonitoring = lib.mkOption { @@ -89,6 +89,11 @@ in type = types.either types.package types.path; description = "Source of the plugin package or path"; }; + settings = lib.mkOption { + type = jsonFormat.type; + default = { }; + description = "Plugin settings as an attribute set"; + }; }; } );