From e3baf274f47678df6289c7482353cb6d38b7be5d Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 30 Jan 2025 13:55:54 -0600 Subject: [PATCH] bat: remove with lib --- modules/programs/bat.nix | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/modules/programs/bat.nix b/modules/programs/bat.nix index 3935e54ae..fce1f5e63 100644 --- a/modules/programs/bat.nix +++ b/modules/programs/bat.nix @@ -1,26 +1,23 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkEnableOption mkOption mkIf types; cfg = config.programs.bat; toConfigFile = attrs: let inherit (builtins) isBool attrNames; - nonBoolFlags = filterAttrs (_: v: !(isBool v)) attrs; - enabledBoolFlags = filterAttrs (_: v: isBool v && v) attrs; + nonBoolFlags = lib.filterAttrs (_: v: !(isBool v)) attrs; + enabledBoolFlags = lib.filterAttrs (_: v: isBool v && v) attrs; - keyValuePairs = generators.toKeyValue { + keyValuePairs = lib.generators.toKeyValue { mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}"; listsAsDuplicateKeys = true; } nonBoolFlags; - switches = concatMapStrings (k: '' + switches = lib.concatMapStrings (k: '' --${k} '') (attrNames enabledBoolFlags); in keyValuePairs + switches; - in { meta.maintainers = with lib.maintainers; [ khaneliman ]; @@ -50,7 +47,7 @@ in { ''; }; - package = mkPackageOption pkgs "bat" { }; + package = lib.mkPackageOption pkgs "bat" { }; themes = mkOption { type = types.attrsOf (types.either types.lines (types.submodule { @@ -122,15 +119,15 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf (any isString (attrValues cfg.themes)) { + config = mkIf cfg.enable (lib.mkMerge [ + (mkIf (lib.any lib.isString (lib.attrValues cfg.themes)) { warnings = ['' Using programs.bat.themes as a string option is deprecated and will be removed in the future. Please change to using it as an attribute set instead. '']; }) - (mkIf (any isString (attrValues cfg.syntaxes)) { + (mkIf (lib.any lib.isString (lib.attrValues cfg.syntaxes)) { warnings = ['' Using programs.bat.syntaxes as a string option is deprecated and will be removed in the future. Please change to using it as an attribute set @@ -140,18 +137,18 @@ in { { home.packages = [ cfg.package ] ++ cfg.extraPackages; - xdg.configFile = mkMerge ([({ + xdg.configFile = lib.mkMerge ([{ "bat/config" = mkIf (cfg.config != { }) { text = toConfigFile cfg.config; }; - })] ++ (flip mapAttrsToList cfg.themes (name: val: { - "bat/themes/${name}.tmTheme" = if isString val then { + }] ++ (lib.flip lib.mapAttrsToList cfg.themes (name: val: { + "bat/themes/${name}.tmTheme" = if lib.isString val then { text = val; } else { source = if isNull val.file then "${val.src}" else "${val.src}/${val.file}"; }; - })) ++ (flip mapAttrsToList cfg.syntaxes (name: val: { - "bat/syntaxes/${name}.sublime-syntax" = if isString val then { + })) ++ (lib.flip lib.mapAttrsToList cfg.syntaxes (name: val: { + "bat/syntaxes/${name}.sublime-syntax" = if lib.isString val then { text = val; } else { source = @@ -162,9 +159,9 @@ in { # NOTE: run `bat cache --build` in an empty directory to work # around failure when ~/cache exists # https://github.com/sharkdp/bat/issues/1726 - home.activation.batCache = hm.dag.entryAfter [ "linkGeneration" ] '' + home.activation.batCache = lib.hm.dag.entryAfter [ "linkGeneration" ] '' ( - export XDG_CACHE_HOME=${escapeShellArg config.xdg.cacheHome} + export XDG_CACHE_HOME=${lib.escapeShellArg config.xdg.cacheHome} verboseEcho "Rebuilding bat theme cache" cd "${pkgs.emptyDirectory}" run ${lib.getExe cfg.package} cache --build