Skip to content

Commit

Permalink
module: add options for configs in HOME, XDG_CONFIG_HOME, XDG_DATA_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCash authored and pjones committed Jul 31, 2023
1 parent 16c437e commit b6241a2
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Configuration is broken down into three layers:
```nix
{
programs.plasma = {
files."baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
configFile."baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
};
}
```
Expand Down
2 changes: 1 addition & 1 deletion example/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
};

# A low-level setting:
files."baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
configFile."baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
};
}
2 changes: 1 addition & 1 deletion lib/kwriteconfig.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let
lib.concatStringsSep "\n" (lib.mapAttrsToList
(key: value: ''
${pkgs.libsForQt5.kconfig}/bin/kwriteconfig5 \
--file ''${XDG_CONFIG_HOME:-$HOME/.config}/${lib.escapeShellArg file} \
--file ${lib.escapeShellArg file} \
${lib.concatMapStringsSep " " (g: "--group " + lib.escapeShellArg g) groups} \
--key ${lib.escapeShellArg key} \
${toKdeValue value}
Expand Down
51 changes: 42 additions & 9 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ let
inherit (import ../lib/kwriteconfig.nix { inherit lib pkgs; })
kWriteConfig;

cfg = config.programs.plasma.files;
# Helper function to prepend the appropriate path prefix (e.g. XDG_CONFIG_HOME) to file
prependPath = prefix: attrset:
lib.attrsets.mapAttrs'
(path: config: { name = "${prefix}/${path}"; value = config; })
attrset;
plasmaCfg = config.programs.plasma;
cfg =
(prependPath config.home.homeDirectory plasmaCfg.file) //
(prependPath config.xdg.configHome plasmaCfg.configFile) //
(prependPath config.xdg.dataHome plasmaCfg.dataFile);

##############################################################################
# A module for storing settings.
Expand Down Expand Up @@ -41,16 +50,40 @@ let
cfg));
in
{
options.programs.plasma.files = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (submodule settingType));
default = { };
description = ''
An attribute set where the keys are file names (relative to
XDG_CONFIG_HOME) and the values are attribute sets that
represent configuration groups and settings inside those groups.
'';
options.programs.plasma = {
file = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (submodule settingType));
default = { };
description = ''
An attribute set where the keys are file names (relative to
HOME) and the values are attribute sets that represent
configuration groups and settings inside those groups.
'';
};
configFile = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (submodule settingType));
default = { };
description = ''
An attribute set where the keys are file names (relative to
XDG_CONFIG_HOME) and the values are attribute sets that
represent configuration groups and settings inside those groups.
'';
};
dataFile = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (submodule settingType));
default = { };
description = ''
An attribute set where the keys are file names (relative to
XDG_DATA_HOME) and the values are attribute sets that
represent configuration groups and settings inside those groups.
'';
};
};

imports = [
(lib.mkRenamedOptionModule [ "programs" "plasma" "files" ] [ "programs" "plasma" "configFile" ])
];

config = lib.mkIf (builtins.length (builtins.attrNames cfg) > 0) {
home.activation.configure-plasma = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
$DRY_RUN_CMD ${script}
Expand Down
2 changes: 1 addition & 1 deletion modules/hotkeys.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ in
config = lib.mkIf
(cfg.enable && builtins.length (builtins.attrNames cfg.hotkeys.commands) != 0)
{
programs.plasma.files.khotkeysrc = hotkeys;
programs.plasma.configFile.khotkeysrc = hotkeys;
};
}
2 changes: 1 addition & 1 deletion modules/shortcuts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ in
};

config = lib.mkIf (cfg.enable && builtins.attrNames cfg.shortcuts != 0) {
programs.plasma.files."kglobalshortcutsrc" =
programs.plasma.configFile."kglobalshortcutsrc" =
shortcutsToSettings cfg.shortcuts;
};
}
2 changes: 1 addition & 1 deletion modules/windows.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ in
};

config = lib.mkIf cfg.enable {
programs.plasma.files = {
programs.plasma.configFile = {
kdeglobals = {
General.AllowKDEAppsToRememberWindowPositions =
lib.mkDefault cfg.windows.allowWindowsToRememberPositions;
Expand Down
2 changes: 1 addition & 1 deletion modules/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ in
};

config = lib.mkIf cfg.enable {
programs.plasma.files.kdeglobals = {
programs.plasma.configFile.kdeglobals = {
KDE.SingleClick = lib.mkDefault (cfg.workspace.clickItemTo == "open");
};
};
Expand Down
2 changes: 1 addition & 1 deletion script/rc2nix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def run
puts(" shortcuts = {")
pp_shortcuts(settings["kglobalshortcutsrc"], 6)
puts(" };")
puts(" files = {")
puts(" configFile = {")
pp_settings(settings, 6)
puts(" };")
puts(" };")
Expand Down

0 comments on commit b6241a2

Please sign in to comment.