modules: refac functions

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-16 17:59:16 +03:00
parent e0ded86454
commit 001a2d909c
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 15 additions and 22 deletions

View file

@ -41,13 +41,13 @@ let
projectStartHook = projectStartHook =
do do
let workdir = "${workdir}" let workdir = "${workdir}"
${lib.concatStringsSep "\n" (map mkXmonadProjectSpawnProgram spawnPrograms)} ${lib.concatMapStringsSep "\n" mkXmonadProjectSpawnProgram spawnPrograms}
${lib.concatStringsSep "\n" (map mkXmonadProjectTerminalCommand terminalCommands)} ${lib.concatMapStringsSep "\n" mkXmonadProjectTerminalCommand terminalCommands}
replicateM_ ${toString windowCount} $ spawn $ terminal workdir replicateM_ ${toString windowCount} $ spawn $ terminal workdir
} }
''; '';
xmonadProjects = lib.concatStringsSep " , " (map mkXmonadProject cfg.projects); xmonadProjects = lib.concatMapStringsSep " , " mkXmonadProject cfg.projects;
in in
{ {
options.local.window-manager.xmonad = with lib; { options.local.window-manager.xmonad = with lib; {

View file

@ -24,13 +24,11 @@ let
}; };
}); });
inherit (builtins) concatStringsSep;
# See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79 # See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79
lanMouseConfig = pkgs.writeText "config.toml" ( lanMouseConfig = pkgs.writeText "config.toml" (
let let
# List[str] -> str # List[str] -> str
listOfStr = l: concatStringsSep "," (map (val: "\"${val}\"") l); listOfStr = lib.concatMapStringsSep "," (val: "\"${val}\"");
in in
'' ''
port = ${toString cfg.settings.port} port = ${toString cfg.settings.port}
@ -39,22 +37,17 @@ let
+ lib.optionalString (cfg.settings.releaseBind != [ ]) '' + lib.optionalString (cfg.settings.releaseBind != [ ]) ''
release_bind = [${listOfStr cfg.settings.releaseBind}] release_bind = [${listOfStr cfg.settings.releaseBind}]
'' ''
+ (concatStringsSep "\n" + (builtins.concatStringsSep "\n"
(lib.attrValues (lib.flip lib.mapAttrstoList cfg.settings.connections (key: value: ''
(lib.mapAttrs [${key}]
(key: value: '' ips = [${listOfStr value.ips}]
[${key}] ${lib.optionalString (value.hostname != "") ''
ips = [${listOfStr value.ips}] hostname = "${value.hostname}"
${lib.optionalString (value.hostname != "") '' ''}
hostname = "${value.hostname}" port = ${toString value.port}
''} activate_on_startup = ${if value.activateOnStartup then "true" else "false"}
port = ${toString value.port} ''
activate_on_startup = ${if value.activateOnStartup then "true" else "false"} ))
''
)
cfg.settings.connections
)
)
) )
); );
in in