Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial try to add support for immutable settings #94

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Configuration is broken down into three layers:
```nix
{
programs.plasma = {
configFile."baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
configFile."baloofilerc"."Basic Settings"."Indexing-Enabled".value = false;
};
}
```
Expand All @@ -76,7 +76,7 @@ Configuration is broken down into three layers:
configuration-writing script (which is very similar to
`kwriteconfig5`).

An example is available in the `example` directory.
For some examples see the [example](./example/) directory.

## Capturing Your Current Configuration

Expand Down
9 changes: 7 additions & 2 deletions example/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@
# Some low-level settings:
#
configFile = {
"baloofilerc"."Basic Settings"."Indexing-Enabled" = false;
"kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft" = "SF";
"baloofilerc"."Basic Settings"."Indexing-Enabled".value = false;
"kwinrc"."org.kde.kdecoration2"."ButtonsOnLeft".value = "SF";
"kwinrc"."Desktops"."Number" = {
value = 8;
# Forces kde to not change this value (even through the settings app).
immutable = true;
};
};
};
}
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions lib/types.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ lib, ... }:
let
##############################################################################
# Types for storing settings.
basicSettingsType = (with lib.types;
nullOr (oneOf [ bool float int str ]));
advancedSettingsType = (with lib.types; submodule {
options = {
value = lib.mkOption {
type = basicSettingsType;
default = null;
description = "The value for some key.";
};
immutable = lib.mkOption {
type = bool;
default = false;
description = ''
Whether to make the key immutable. This corresponds to adding [$i] to
the end of the key.
'';
};
shellExpand = lib.mkOption {
type = bool;
default = false;
description = ''
Whether to mark the key for shell expansion. This corresponds to
adding [$e] to the end of the key.
'';
};
};
});
in
{
inherit basicSettingsType;
inherit advancedSettingsType;
}
151 changes: 70 additions & 81 deletions modules/apps/konsole.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
{ config, lib, ... }:

with lib;

{ config, lib, pkgs, ... }:
let
inherit (import ../../lib/types.nix { inherit lib; }) basicSettingsType;

cfg = config.programs.konsole;
profilesSubmodule = {
options = {
name = mkOption {
type = with types; nullOr str;
name = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
Name of the profile. Defaults to the attribute name.
'';
};
colorScheme = mkOption {
type = with types; nullOr str;
default = "Breeze";
colorScheme = lib.mkOption {
type = with lib.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
'';
};
command = mkOption {
type = with types; nullOr str;
default = "/run/current-system/sw/bin/bash";
command = lib.mkOption {
type = with lib.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;
name = lib.mkOption {
type = lib.types.str;
/*
TODO: Set default to null after adding an assertion
Konsole needs to have a font set to be able to change font size
Expand All @@ -46,9 +45,9 @@ let
Name of the font the profile should use.
'';
};
size = mkOption {
size = lib.mkOption {
# The konsole ui gives you a limited range
type = with types; nullOr (ints.between 4 128);
type = (lib.types.ints.between 4 128);
default = 10;
example = 12;
description = ''
Expand All @@ -59,36 +58,16 @@ 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

{
options.programs.konsole = {
enable = mkEnableOption ''
enable = lib.mkEnableOption ''
Enable configuration management for Konsole.
'';
defaultProfile = mkOption {
type = with types; nullOr str;

defaultProfile = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "Catppuccin";
description = ''
Expand All @@ -97,66 +76,76 @@ in
'';
};

profiles = mkOption {
type = with types; nullOr (attrsOf (submodule profilesSubmodule));
default = {};
profiles = lib.mkOption {
type = with lib.types; nullOr (attrsOf (submodule profilesSubmodule));
default = { };
description = ''
Plasma profiles to generate.
'';
};

extraConfig = mkOption {
type = with types; nullOr (attrsOf (submodule settingType));
extraConfig = lib.mkOption {
type = with lib.types; nullOr (attrsOf (attrsOf (basicSettingsType)));
default = null;
description = ''
Extra config to add to konsolerc.
'';
};
};

config = mkIf (cfg.enable) {
programs.plasma.configFile."konsolerc" = mkMerge [
config = lib.mkIf (cfg.enable) {
programs.plasma.configFile."konsolerc" = lib.mkMerge [
(
mkIf (cfg.defaultProfile != null ) {
"Desktop Entry"."DefaultProfile" = cfg.defaultProfile;
lib.mkIf (cfg.defaultProfile != null) {
"Desktop Entry"."DefaultProfile".value = cfg.defaultProfile;
}
)
(
mkIf (cfg.extraConfig != null) cfg.extraConfig
lib.mkIf (cfg.extraConfig != null) (lib.mapAttrs
(groupName: groupAttrs:
(lib.mapAttrs (keyName: keyAttrs: { value = keyAttrs; }) groupAttrs))
cfg.extraConfig)
)
];

xdg.dataFile = mkIf (cfg.profiles != {}) (
mkMerge ([
(
mkMerge (
mapAttrsToList (
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;
fontString = mkIf (profile.font.name != null) "${profile.font.name},${builtins.toString profile.font.size}";
in
{
"konsole/${profileName}.profile".text = lib.generators.toINI {} {
"General" = {
"Command" = (mkIf (profile.command != null) profile.command).content;
"Name" = profileName;
# Konsole generated profiles seem to allways have this
"Parent" = "FALLBACK/";
};
"Appearance" = {
"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" = fontString.content;
};
};
}
) cfg.profiles
xdg.dataFile = lib.mkIf (cfg.profiles != { })
(
lib.mkMerge ([
(
lib.mkMerge (
lib.mapAttrsToList
(
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;
fontString = lib.mkIf (profile.font.name != null) "${profile.font.name},${builtins.toString profile.font.size}";
in
{
"konsole/${profileName}.profile".text = lib.generators.toINI { } {
"General" = (
{
"Name" = profileName;
# Konsole generated profiles seem to always have this
"Parent" = "FALLBACK/";
} //
(lib.optionalAttrs (profile.command != null) { "Command" = profile.command; })
);
"Appearance" = (
{
# 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" = fontString.content;
} //
(lib.optionalAttrs (profile.colorScheme != null) { "ColorScheme" = profile.colorScheme; })
);
};
}
)
cfg.profiles
)
)
)
])
);
])
);
};
}
Loading
Loading