cosmic: fix doc
This commit is contained in:
parent
a12755f889
commit
70e3671a4f
|
@ -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
|
||||
|
@ -21,16 +35,15 @@ let
|
|||
}'';
|
||||
# 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,37 +64,42 @@ 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 {
|
||||
|
@ -169,7 +187,7 @@ in {
|
|||
};
|
||||
});
|
||||
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 = {
|
||||
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
|
||||
}
|
||||
// concatMapAttrs
|
||||
(application: options: mapCosmicSettings application options)
|
||||
cfg.settings;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue