cosmic: fix doc

This commit is contained in:
atagen 2024-08-01 14:39:29 +10:00
parent a12755f889
commit 70e3671a4f

View file

@ -1,8 +1,22 @@
{ pkgs, lib, config, ... }:
let
inherit (lib)
filterAttrs concatStrings concatStringsSep mapAttrsToList concatLists
foldlAttrs concatMapAttrs mapAttrs' nameValuePair boolToString;
{
pkgs,
lib,
config,
...
}: let
inherit
(lib)
filterAttrs
concatStrings
concatStringsSep
mapAttrsToList
concatLists
foldlAttrs
concatMapAttrs
mapAttrs'
nameValuePair
boolToString
;
inherit (builtins) typeOf toString stringLength;
# build up serialisation machinery from here for various types
@ -14,23 +28,22 @@ let
assoc = a: ''
{
${
concatStringsSep ''
,
'' (concatLists (map _assoc a))
}
concatStringsSep ''
,
'' (concatLists (map _assoc a))
}
}'';
# attrset -> struct
_struct_kv = k: v:
if v == null then
""
else
(concatStringsSep ":" [ k (serialise.${typeOf v} v) ]);
if v == null
then ""
else (concatStringsSep ":" [k (serialise.${typeOf v} v)]);
_struct_concat = s:
foldlAttrs (acc: k: v:
if stringLength acc > 0 then
concatStringsSep ", " [ acc (_struct_kv k v) ]
else
_struct_kv k v) "" s;
if stringLength acc > 0
then concatStringsSep ", " [acc (_struct_kv k v)]
else _struct_kv k v) ""
s;
_struct_filt = s: _struct_concat (filterAttrs (k: v: v != null) s);
struct = s: "(${_struct_filt s})";
toQuotedString = s: ''"${toString s}"'';
@ -51,41 +64,46 @@ let
defineBinding = binding:
struct {
inherit (binding) modifiers;
key = if isNull binding.key then null else toQuotedString binding.key;
key =
if isNull binding.key
then null
else toQuotedString binding.key;
};
# map keybinding from list of attrset to hashmap of (mod,key): action
_mapBindings = bindings:
map (inner: {
"${defineBinding inner}" = maybeToString (checkAction inner.action);
}) bindings;
})
bindings;
mapBindings = bindings: assoc (_mapBindings bindings);
# check a keybinding's action
# escape with quotes if it's a Spawn action
checkAction = a:
if typeOf a == "set" && a.type == "Spawn" then {
if typeOf a == "set" && a.type == "Spawn"
then {
inherit (a) type;
data = toQuotedString a.data;
} else
a;
}
else a;
maybeToString = s:
if typeOf s == "set" then
concatStrings [ s.type "(" (toString s.data) ")" ]
else
s;
if typeOf s == "set"
then concatStrings [s.type "(" (toString s.data) ")"]
else s;
mapCosmicSettings = application: options:
mapAttrs' (k: v:
nameValuePair "cosmic/${application}/v${options.version}/${k}" {
enable = true;
text = serialise.${typeOf v} v;
}) options.option;
})
options.option;
cfg = config.programs.cosmic;
in {
meta.maintainers = [ hm.maintainers.atagen ];
meta.maintainers = [hm.maintainers.atagen];
options.programs.cosmic = {
enable = with lib; mkEnableOption "COSMIC DE";
@ -98,13 +116,13 @@ in {
keybindings = with lib;
mkOption {
default = [ ];
default = [];
type = with types;
listOf (submodule {
options = {
modifiers = mkOption {
type = listOf str;
default = [ ];
default = [];
};
key = mkOption {
type = nullOr str;
@ -113,9 +131,9 @@ in {
action = mkOption {
type = either str (submodule {
options = {
type = mkOption { type = str; };
type = mkOption {type = str;};
data = mkOption {
type = oneOf [ str int ];
type = oneOf [str int];
default = "";
};
};
@ -157,7 +175,7 @@ in {
settings = with lib;
mkOption {
default = { };
default = {};
type = with types;
attrsOf (submodule {
options = {
@ -165,11 +183,11 @@ in {
type = str;
default = "1";
};
option = mkOption { type = attrsOf anything; };
option = mkOption {type = attrsOf anything;};
};
});
description = ''
A list of explicit settings for COSMIC apps, using their full config path.
An attrset of explicit settings for COSMIC apps, using their full config path.
'';
example = literalExpression ''
{
@ -182,14 +200,16 @@ in {
};
config = lib.mkIf cfg.enable {
xdg.configFile = {
"cosmic/com.system76.CosmicSettings.Shortcuts/v1/custom".text =
(lib.mkIf cfg.keybindings != [ ]) mapBindings cfg.keybindings;
"cosmic/com.system76.CosmicSettings.Shortcuts/v1/defaults" = {
text = "{}";
enable = !cfg.defaultKeybindings;
};
} // concatMapAttrs
xdg.configFile =
{
"cosmic/com.system76.CosmicSettings.Shortcuts/v1/custom".text =
(lib.mkIf cfg.keybindings != []) mapBindings cfg.keybindings;
"cosmic/com.system76.CosmicSettings.Shortcuts/v1/defaults" = {
text = "{}";
enable = !cfg.defaultKeybindings;
};
}
// concatMapAttrs
(application: options: mapCosmicSettings application options)
cfg.settings;
};