mirror of
https://github.com/nix-community/home-manager.git
synced 2025-03-09 18:26:54 +00:00
bat: remove with lib
This commit is contained in:
parent
c90cd85b04
commit
e3baf274f4
1 changed files with 16 additions and 19 deletions
|
@ -1,26 +1,23 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (lib) literalExpression mkEnableOption mkOption mkIf types;
|
||||||
|
|
||||||
cfg = config.programs.bat;
|
cfg = config.programs.bat;
|
||||||
|
|
||||||
toConfigFile = attrs:
|
toConfigFile = attrs:
|
||||||
let
|
let
|
||||||
inherit (builtins) isBool attrNames;
|
inherit (builtins) isBool attrNames;
|
||||||
nonBoolFlags = filterAttrs (_: v: !(isBool v)) attrs;
|
nonBoolFlags = lib.filterAttrs (_: v: !(isBool v)) attrs;
|
||||||
enabledBoolFlags = filterAttrs (_: v: isBool v && v) attrs;
|
enabledBoolFlags = lib.filterAttrs (_: v: isBool v && v) attrs;
|
||||||
|
|
||||||
keyValuePairs = generators.toKeyValue {
|
keyValuePairs = lib.generators.toKeyValue {
|
||||||
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}";
|
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}";
|
||||||
listsAsDuplicateKeys = true;
|
listsAsDuplicateKeys = true;
|
||||||
} nonBoolFlags;
|
} nonBoolFlags;
|
||||||
switches = concatMapStrings (k: ''
|
switches = lib.concatMapStrings (k: ''
|
||||||
--${k}
|
--${k}
|
||||||
'') (attrNames enabledBoolFlags);
|
'') (attrNames enabledBoolFlags);
|
||||||
in keyValuePairs + switches;
|
in keyValuePairs + switches;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
meta.maintainers = with lib.maintainers; [ khaneliman ];
|
||||||
|
|
||||||
|
@ -50,7 +47,7 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
package = mkPackageOption pkgs "bat" { };
|
package = lib.mkPackageOption pkgs "bat" { };
|
||||||
|
|
||||||
themes = mkOption {
|
themes = mkOption {
|
||||||
type = types.attrsOf (types.either types.lines (types.submodule {
|
type = types.attrsOf (types.either types.lines (types.submodule {
|
||||||
|
@ -122,15 +119,15 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (lib.mkMerge [
|
||||||
(mkIf (any isString (attrValues cfg.themes)) {
|
(mkIf (lib.any lib.isString (lib.attrValues cfg.themes)) {
|
||||||
warnings = [''
|
warnings = [''
|
||||||
Using programs.bat.themes as a string option is deprecated and will be
|
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
|
removed in the future. Please change to using it as an attribute set
|
||||||
instead.
|
instead.
|
||||||
''];
|
''];
|
||||||
})
|
})
|
||||||
(mkIf (any isString (attrValues cfg.syntaxes)) {
|
(mkIf (lib.any lib.isString (lib.attrValues cfg.syntaxes)) {
|
||||||
warnings = [''
|
warnings = [''
|
||||||
Using programs.bat.syntaxes as a string option is deprecated and will be
|
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
|
removed in the future. Please change to using it as an attribute set
|
||||||
|
@ -140,18 +137,18 @@ in {
|
||||||
{
|
{
|
||||||
home.packages = [ cfg.package ] ++ cfg.extraPackages;
|
home.packages = [ cfg.package ] ++ cfg.extraPackages;
|
||||||
|
|
||||||
xdg.configFile = mkMerge ([({
|
xdg.configFile = lib.mkMerge ([{
|
||||||
"bat/config" =
|
"bat/config" =
|
||||||
mkIf (cfg.config != { }) { text = toConfigFile cfg.config; };
|
mkIf (cfg.config != { }) { text = toConfigFile cfg.config; };
|
||||||
})] ++ (flip mapAttrsToList cfg.themes (name: val: {
|
}] ++ (lib.flip lib.mapAttrsToList cfg.themes (name: val: {
|
||||||
"bat/themes/${name}.tmTheme" = if isString val then {
|
"bat/themes/${name}.tmTheme" = if lib.isString val then {
|
||||||
text = val;
|
text = val;
|
||||||
} else {
|
} else {
|
||||||
source =
|
source =
|
||||||
if isNull val.file then "${val.src}" else "${val.src}/${val.file}";
|
if isNull val.file then "${val.src}" else "${val.src}/${val.file}";
|
||||||
};
|
};
|
||||||
})) ++ (flip mapAttrsToList cfg.syntaxes (name: val: {
|
})) ++ (lib.flip lib.mapAttrsToList cfg.syntaxes (name: val: {
|
||||||
"bat/syntaxes/${name}.sublime-syntax" = if isString val then {
|
"bat/syntaxes/${name}.sublime-syntax" = if lib.isString val then {
|
||||||
text = val;
|
text = val;
|
||||||
} else {
|
} else {
|
||||||
source =
|
source =
|
||||||
|
@ -162,9 +159,9 @@ in {
|
||||||
# NOTE: run `bat cache --build` in an empty directory to work
|
# NOTE: run `bat cache --build` in an empty directory to work
|
||||||
# around failure when ~/cache exists
|
# around failure when ~/cache exists
|
||||||
# https://github.com/sharkdp/bat/issues/1726
|
# 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"
|
verboseEcho "Rebuilding bat theme cache"
|
||||||
cd "${pkgs.emptyDirectory}"
|
cd "${pkgs.emptyDirectory}"
|
||||||
run ${lib.getExe cfg.package} cache --build
|
run ${lib.getExe cfg.package} cache --build
|
||||||
|
|
Loading…
Add table
Reference in a new issue