sioyek: add startupCommands option

This commit is contained in:
Ayush Pramanik 2026-02-17 13:44:33 -04:00 committed by Matthieu Coudron
parent 2dedeb55b2
commit a0a01d8811
3 changed files with 45 additions and 6 deletions

View file

@ -18,7 +18,6 @@ let
mkKeyValue = key: value: "${key} ${value}";
listsAsDuplicateKeys = true;
};
in
{
meta.maintainers = [ lib.maintainers.podocarp ];
@ -58,24 +57,58 @@ in
{file}`$XDG_CONFIG_HOME/sioyek/prefs_user.config`.
See <https://github.com/ahrm/sioyek/blob/main/pdf_viewer/prefs.config>.
'';
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
{
"background_color" = "1.0 1.0 1.0";
"text_highlight_color" = "1.0 0.0 0.0";
startup_commands = [
"toggle_visual_scroll"
"toggle_dark_mode"
];
}
'';
};
type = types.submodule {
freeformType = types.attrsOf types.str;
options.startup_commands = mkOption {
description = ''
Commands to be run upon startup. Will be written to {file}`$XDG_CONFIG_HOME/sioyek/prefs_user.config`.
See <https://github.com/ahrm/sioyek/blob/a4ce95fd968804fbf6ff3befcbe0d9b972bd754c/pdf_viewer/prefs.config#L116>.
'';
type = types.either types.str (types.listOf types.str);
apply =
x:
lib.warnIf (lib.isString x)
"`programs.sioyek.config.startup_commands` should now be a list of strings instead of a string."
x;
default = [ ];
example = [
"toggle_visual_scroll"
"toggle_dark_mode"
];
};
};
};
};
};
config = mkIf cfg.enable (
let
prefsCfg =
cfg.config
//
lib.optionalAttrs (cfg.config.startup_commands != [ ] && !lib.isString cfg.config.startup_commands)
{
startup_commands = lib.concatStringsSep ";" cfg.config.startup_commands;
};
in
lib.mkMerge [
{ home.packages = [ cfg.package ]; }
(mkIf (cfg.config != { }) {
xdg.configFile."sioyek/prefs_user.config".text = renderConfig cfg.config;
{
home.packages = [ cfg.package ];
}
(mkIf (prefsCfg != { }) {
xdg.configFile."sioyek/prefs_user.config".text = renderConfig prefsCfg;
})
(mkIf (cfg.bindings != { }) {
xdg.configFile."sioyek/keys_user.config".text = renderConfig cfg.bindings;