From 001a2d909c40465e6b4218bed2323de32326f7ca Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 16 Apr 2024 17:59:16 +0300 Subject: [PATCH] modules: refac functions --- .../configs/window-manager/xmonad.nix | 6 ++-- .../services/lan-mouse/default.nix | 31 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/modules/home-manager/configs/window-manager/xmonad.nix b/modules/home-manager/configs/window-manager/xmonad.nix index 4553f02..7620028 100644 --- a/modules/home-manager/configs/window-manager/xmonad.nix +++ b/modules/home-manager/configs/window-manager/xmonad.nix @@ -41,13 +41,13 @@ let projectStartHook = do let workdir = "${workdir}" - ${lib.concatStringsSep "\n" (map mkXmonadProjectSpawnProgram spawnPrograms)} - ${lib.concatStringsSep "\n" (map mkXmonadProjectTerminalCommand terminalCommands)} + ${lib.concatMapStringsSep "\n" mkXmonadProjectSpawnProgram spawnPrograms} + ${lib.concatMapStringsSep "\n" mkXmonadProjectTerminalCommand terminalCommands} replicateM_ ${toString windowCount} $ spawn $ terminal workdir } ''; - xmonadProjects = lib.concatStringsSep " , " (map mkXmonadProject cfg.projects); + xmonadProjects = lib.concatMapStringsSep " , " mkXmonadProject cfg.projects; in { options.local.window-manager.xmonad = with lib; { diff --git a/modules/home-manager/services/lan-mouse/default.nix b/modules/home-manager/services/lan-mouse/default.nix index 980d2e7..e7b096e 100644 --- a/modules/home-manager/services/lan-mouse/default.nix +++ b/modules/home-manager/services/lan-mouse/default.nix @@ -24,13 +24,11 @@ let }; }); - inherit (builtins) concatStringsSep; - # See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79 lanMouseConfig = pkgs.writeText "config.toml" ( let # List[str] -> str - listOfStr = l: concatStringsSep "," (map (val: "\"${val}\"") l); + listOfStr = lib.concatMapStringsSep "," (val: "\"${val}\""); in '' port = ${toString cfg.settings.port} @@ -39,22 +37,17 @@ let + lib.optionalString (cfg.settings.releaseBind != [ ]) '' release_bind = [${listOfStr cfg.settings.releaseBind}] '' - + (concatStringsSep "\n" - (lib.attrValues - (lib.mapAttrs - (key: value: '' - [${key}] - ips = [${listOfStr value.ips}] - ${lib.optionalString (value.hostname != "") '' - hostname = "${value.hostname}" - ''} - port = ${toString value.port} - activate_on_startup = ${if value.activateOnStartup then "true" else "false"} - '' - ) - cfg.settings.connections - ) - ) + + (builtins.concatStringsSep "\n" + (lib.flip lib.mapAttrstoList cfg.settings.connections (key: value: '' + [${key}] + ips = [${listOfStr value.ips}] + ${lib.optionalString (value.hostname != "") '' + hostname = "${value.hostname}" + ''} + port = ${toString value.port} + activate_on_startup = ${if value.activateOnStartup then "true" else "false"} + '' + )) ) ); in