From ba628af3d5cf7988a0c513d7558e1198cae6a2ec Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Sun, 11 Feb 2024 20:25:50 +0100 Subject: [PATCH 01/14] Add a module for konsole --- modules/apps/default.nix | 7 +++++++ modules/apps/konsole.nix | 35 +++++++++++++++++++++++++++++++++++ modules/default.nix | 1 + 3 files changed, 43 insertions(+) create mode 100644 modules/apps/default.nix create mode 100644 modules/apps/konsole.nix diff --git a/modules/apps/default.nix b/modules/apps/default.nix new file mode 100644 index 00000000..59f5345e --- /dev/null +++ b/modules/apps/default.nix @@ -0,0 +1,7 @@ +{ lib, ... }: + +{ + imports = [ + ./konsole.nix + ]; +} diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix new file mode 100644 index 00000000..f4254026 --- /dev/null +++ b/modules/apps/konsole.nix @@ -0,0 +1,35 @@ +{ config, lib, ... }: + +with lib; + +let + cfg = config.programs.konsole; +in + +{ + options.programs.konsole = { + enable = mkEnableOption '' + Enable configuration management for Konsole + ''; + + defaultProfile = mkOption { + type = with types; nullOr str; + default = null; + example = "Catppuccin"; + description = '' + The name of the konsole profile file to use by default + To see what options you have, just take a look at ~/.local/share/konsole/ + ''; + }; + }; + + config = mkIf (config.programs.plasma.enable && cfg.enable) { + programs.plasma.configFile."konsolerc" = mkMerge [ + ( + mkIf (cfg.defaultProfile != null ) { + "Desktop entry"."DefaultProfile" = cfg.defaultProfile; + } + ) + ]; + }; +} \ No newline at end of file diff --git a/modules/default.nix b/modules/default.nix index bdd4393c..c872ce76 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -11,6 +11,7 @@ ./kwin.nix ./startup.nix ./panels.nix + ./apps ]; options.programs.plasma.enable = lib.mkEnableOption '' From 6cfee10f8335b0bdfeb82e3201abe209832126d2 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 26 Feb 2024 12:25:03 +0100 Subject: [PATCH 02/14] Add initial support for profiles in konsole module --- modules/apps/konsole.nix | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index f4254026..700d631d 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -4,6 +4,17 @@ with lib; let cfg = config.programs.konsole; + profilesSubmodule = { + options = { + name = mkOption { + type = types.str; + default = null; + description = '' + Name of the profile that will be shown in Konsole + ''; + }; + }; + }; in { @@ -21,6 +32,14 @@ in To see what options you have, just take a look at ~/.local/share/konsole/ ''; }; + + profiles = mkOption { + type = with types; nullOr (attrsOf (submodule profilesSubmodule)); + default = {}; + description = '' + Plasma profiles to generate + ''; + }; }; config = mkIf (config.programs.plasma.enable && cfg.enable) { @@ -31,5 +50,28 @@ in } ) ]; + + # Konsole is fine with using symlinked profiles so I'll use the home-manager way + programs.plasma.dataFile = mkIf (cfg.profiles != {}) ( + mkMerge ([ + ( + mkMerge ( + mapAttrsToList ( + name: profile: { + "konsole/${name}.profile" = { + "General" = { + "Name" = profile.name; + # Konsole generated profiles seem to allways have this + "Parent" = "FALLBACK/"; + }; + # this is for testing only + "Appearance"."ColorScheme" = "Solarized"; + }; + } + ) cfg.profiles + ) + ) + ]) + ); }; -} \ No newline at end of file +} From 817f212f4e641ca2a7cfe478d3cff1119e0b3263 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 26 Feb 2024 12:52:21 +0100 Subject: [PATCH 03/14] Add colorscheme option to konsole profiles --- modules/apps/konsole.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 700d631d..da319ffd 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -13,6 +13,15 @@ let Name of the profile that will be shown in Konsole ''; }; + colorScheme = mkOption { + type = with types; nullOr str; + default = null; + example = "Catppuccin-Mocha"; + description = '' + Color scheme the profile will use. You can check the files you can + use in ~/.local/share/konsole or /run/current-system/share/konsole + ''; + }; }; }; in @@ -64,8 +73,9 @@ in # Konsole generated profiles seem to allways have this "Parent" = "FALLBACK/"; }; - # this is for testing only - "Appearance"."ColorScheme" = "Solarized"; + "Appearance" = { + "ColorScheme" = profile.colorScheme; + }; }; } ) cfg.profiles From 88d25e04786f8fabf0eec01d7dcaf3f1936c60f4 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:18:36 +0100 Subject: [PATCH 04/14] Use name option rather than attribute name in konsole profiles --- modules/apps/konsole.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index da319ffd..51b44a23 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -7,10 +7,10 @@ let profilesSubmodule = { options = { name = mkOption { - type = types.str; + type = with types; nullOr str; default = null; description = '' - Name of the profile that will be shown in Konsole + Name of the profile. Defaults to the attribute name ''; }; colorScheme = mkOption { @@ -66,10 +66,15 @@ in ( mkMerge ( mapAttrsToList ( - name: profile: { + attrName: profile: + let + # Use the name from the name option if it's set + name = if builtins.isString profile.name then profile.name else attrName; + in + { "konsole/${name}.profile" = { "General" = { - "Name" = profile.name; + "Name" = name; # Konsole generated profiles seem to allways have this "Parent" = "FALLBACK/"; }; From a0fba2e9a3368baf0ea490262360ec17e7fa232f Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:17:15 +0100 Subject: [PATCH 05/14] Add font settings to konsole profiles --- modules/apps/konsole.nix | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 51b44a23..111592ae 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -22,6 +22,26 @@ let use in ~/.local/share/konsole or /run/current-system/share/konsole ''; }; + font = { + name = mkOption { + type = with types; nullOr str; + default = null; + example = "Hack"; + description = '' + Name of the font the profile should use + ''; + }; + size = mkOption { + # The konsole ui gives you a limited range + type = with types; nullOr (ints.between 4 128); + default = null; + example = 12; + description = '' + Size of the font. + Needs a font to be set due to konsole limitations + ''; + }; + }; }; }; in @@ -69,17 +89,18 @@ in attrName: profile: let # Use the name from the name option if it's set - name = if builtins.isString profile.name then profile.name else attrName; + profileName = if builtins.isString profile.name then profile.name else attrName; in { - "konsole/${name}.profile" = { + "konsole/${profileName}.profile" = { "General" = { - "Name" = name; + "Name" = profileName; # Konsole generated profiles seem to allways have this "Parent" = "FALLBACK/"; }; "Appearance" = { "ColorScheme" = profile.colorScheme; + "Font" = with profile.font; "${name},${builtins.toString size}"; }; }; } From 6ee9a1f353f8472dce4cff1d518923fe7cd189c7 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 26 Feb 2024 23:20:03 +0100 Subject: [PATCH 06/14] Remove old comment --- modules/apps/konsole.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 111592ae..7cd8fe4d 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -80,7 +80,6 @@ in ) ]; - # Konsole is fine with using symlinked profiles so I'll use the home-manager way programs.plasma.dataFile = mkIf (cfg.profiles != {}) ( mkMerge ([ ( From da3b372bac6c749a70fd95a259a3671f194eb639 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:38:30 +0100 Subject: [PATCH 07/14] Add default font for konsole profiles --- modules/apps/konsole.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 7cd8fe4d..b54f33c7 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -25,7 +25,14 @@ let font = { name = mkOption { type = with types; nullOr str; - default = null; + /* + TODO: Set default to null after adding an assertion + Konsole needs to have a font set to be able to change font size + Since I couldn't get that to work I'll just set a default font + Not ideal since IMO we should only write things that are set explicitly + by the user but ehh it is what it is + */ + default = "Hack"; example = "Hack"; description = '' Name of the font the profile should use @@ -99,6 +106,8 @@ in }; "Appearance" = { "ColorScheme" = profile.colorScheme; + # If the font size is not set we leave a comma a the end after the name + # We should fix this probs but konsole doesn't seem to care ¯\_(ツ)_/¯ "Font" = with profile.font; "${name},${builtins.toString size}"; }; }; From 8f3aaa9d96bcd1f848a3d22a2dd869b892948c48 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:59:32 +0100 Subject: [PATCH 08/14] Add command setting to konsole profiles --- modules/apps/konsole.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index b54f33c7..e681d3eb 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -22,6 +22,14 @@ let use in ~/.local/share/konsole or /run/current-system/share/konsole ''; }; + command = mkOption { + type = with types; nullOr str; + default = null; + example = "''${pkgs.zsh}/bin/zsh"; + description = '' + The command to run on new sessions + ''; + }; font = { name = mkOption { type = with types; nullOr str; @@ -100,6 +108,7 @@ in { "konsole/${profileName}.profile" = { "General" = { + "Command" = profile.command; "Name" = profileName; # Konsole generated profiles seem to allways have this "Parent" = "FALLBACK/"; From da0a65be4cc3201d0b8228f337431bf4dd6857ef Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:08:17 +0100 Subject: [PATCH 09/14] Add konsole extra config option --- modules/apps/konsole.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index e681d3eb..76333c31 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -59,6 +59,26 @@ let }; }; }; + + # A module for storing settings. + settingType = { name, ... }: { + freeformType = with lib.types; + attrsOf (nullOr (oneOf [ bool float int str ])); + + options = { + configGroupNesting = lib.mkOption { + type = lib.types.nonEmptyListOf lib.types.str; + # We allow escaping periods using \\. + default = (map + (e: builtins.replaceStrings [ "\\u002E" ] [ "." ] e) + (lib.splitString "." + (builtins.replaceStrings [ "\\." ] [ "\\u002E" ] name) + ) + ); + description = "Group name, and sub-group names."; + }; + }; + }; in { @@ -84,6 +104,14 @@ in Plasma profiles to generate ''; }; + + extraConfig = mkOption { + type = with types; nullOr (attrsOf (submodule settingType)); + default = null; + description = '' + Extra config to add to konsolerc + ''; + }; }; config = mkIf (config.programs.plasma.enable && cfg.enable) { @@ -93,6 +121,9 @@ in "Desktop entry"."DefaultProfile" = cfg.defaultProfile; } ) + ( + mkIf (cfg.extraConfig != null) cfg.extraConfig + ) ]; programs.plasma.dataFile = mkIf (cfg.profiles != {}) ( From 095d7b698944ead485b650a4b33d29cde6ceeb0c Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Mon, 4 Mar 2024 00:51:21 +0100 Subject: [PATCH 10/14] Generate konsole profiles using generators.toINI --- modules/apps/konsole.nix | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 76333c31..eaf6d276 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -5,6 +5,7 @@ with lib; let cfg = config.programs.konsole; profilesSubmodule = { + # TODO: don't set null as the defaults, toINI doesn't like it options = { name = mkOption { type = with types; nullOr str; @@ -126,7 +127,7 @@ in ) ]; - programs.plasma.dataFile = mkIf (cfg.profiles != {}) ( + xdg.dataFile = mkIf (cfg.profiles != {}) ( mkMerge ([ ( mkMerge ( @@ -134,21 +135,22 @@ in attrName: profile: let # Use the name from the name option if it's set - profileName = if builtins.isString profile.name then profile.name else attrName; + profileName = if builtins.isString profile.name then profile.name else attrName; + fontString = mkIf (profile.font.name != null) "${profile.font.name},${builtins.toString profile.font.size}"; in { - "konsole/${profileName}.profile" = { + "konsole/${profileName}.profile".text = lib.generators.toINI {} { "General" = { - "Command" = profile.command; + "Command" = (mkIf (profile.command != null) profile.command).content; "Name" = profileName; # Konsole generated profiles seem to allways have this "Parent" = "FALLBACK/"; }; "Appearance" = { - "ColorScheme" = profile.colorScheme; + "ColorScheme" = (mkIf (profile.colorScheme != null) profile.colorScheme).content; # If the font size is not set we leave a comma a the end after the name # We should fix this probs but konsole doesn't seem to care ¯\_(ツ)_/¯ - "Font" = with profile.font; "${name},${builtins.toString size}"; + "Font" = fontString.content; }; }; } From e99e0788a903c1243b5728e8df120cbb6015faf5 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:40:29 +0100 Subject: [PATCH 11/14] Add default values to konsole profile defaults --- modules/apps/konsole.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index eaf6d276..697cb94d 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -5,7 +5,6 @@ with lib; let cfg = config.programs.konsole; profilesSubmodule = { - # TODO: don't set null as the defaults, toINI doesn't like it options = { name = mkOption { type = with types; nullOr str; @@ -16,7 +15,7 @@ let }; colorScheme = mkOption { type = with types; nullOr str; - default = null; + default = "Breeze"; example = "Catppuccin-Mocha"; description = '' Color scheme the profile will use. You can check the files you can @@ -25,7 +24,7 @@ let }; command = mkOption { type = with types; nullOr str; - default = null; + default = "/run/current-system/sw/bin/bash"; example = "''${pkgs.zsh}/bin/zsh"; description = '' The command to run on new sessions @@ -50,7 +49,7 @@ let size = mkOption { # The konsole ui gives you a limited range type = with types; nullOr (ints.between 4 128); - default = null; + default = 10; example = 12; description = '' Size of the font. From f4550b3722fc3a2088d4ab8cbffcc4b66c4e9c79 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:02:23 +0100 Subject: [PATCH 12/14] Remove unused lib --- modules/apps/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/default.nix b/modules/apps/default.nix index 06a874cc..96833b65 100644 --- a/modules/apps/default.nix +++ b/modules/apps/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ ... }: { imports = [ From acfc4724262bbbc1b162c329d1ffc555d15b15b3 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:03:34 +0100 Subject: [PATCH 13/14] Don't require enabling plasma to configure konsole --- modules/apps/konsole.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index 697cb94d..af6e5095 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -114,7 +114,7 @@ in }; }; - config = mkIf (config.programs.plasma.enable && cfg.enable) { + config = mkIf (cfg.enable) { programs.plasma.configFile."konsolerc" = mkMerge [ ( mkIf (cfg.defaultProfile != null ) { From 261bfd9383166ba15b7aa42323e92c68c6d70572 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:08:19 +0100 Subject: [PATCH 14/14] Add missing periods to konsole option descriptions --- modules/apps/konsole.nix | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/apps/konsole.nix b/modules/apps/konsole.nix index af6e5095..b68a46c9 100644 --- a/modules/apps/konsole.nix +++ b/modules/apps/konsole.nix @@ -10,7 +10,7 @@ let type = with types; nullOr str; default = null; description = '' - Name of the profile. Defaults to the attribute name + Name of the profile. Defaults to the attribute name. ''; }; colorScheme = mkOption { @@ -27,7 +27,7 @@ let default = "/run/current-system/sw/bin/bash"; example = "''${pkgs.zsh}/bin/zsh"; description = '' - The command to run on new sessions + The command to run on new sessions. ''; }; font = { @@ -43,7 +43,7 @@ let default = "Hack"; example = "Hack"; description = '' - Name of the font the profile should use + Name of the font the profile should use. ''; }; size = mkOption { @@ -53,7 +53,7 @@ let example = 12; description = '' Size of the font. - Needs a font to be set due to konsole limitations + Needs a font to be set due to konsole limitations. ''; }; }; @@ -84,7 +84,7 @@ in { options.programs.konsole = { enable = mkEnableOption '' - Enable configuration management for Konsole + Enable configuration management for Konsole. ''; defaultProfile = mkOption { @@ -92,7 +92,7 @@ in default = null; example = "Catppuccin"; description = '' - The name of the konsole profile file to use by default + The name of the konsole profile file to use by default. To see what options you have, just take a look at ~/.local/share/konsole/ ''; }; @@ -101,7 +101,7 @@ in type = with types; nullOr (attrsOf (submodule profilesSubmodule)); default = {}; description = '' - Plasma profiles to generate + Plasma profiles to generate. ''; }; @@ -109,7 +109,7 @@ in type = with types; nullOr (attrsOf (submodule settingType)); default = null; description = '' - Extra config to add to konsolerc + Extra config to add to konsolerc. ''; }; };