Skip to content

Commit

Permalink
nixos/bat: init bat module
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Rodrigues <[email protected]>
  • Loading branch information
SigmaSquadron committed Nov 20, 2024
1 parent 8c6ead6 commit f36897e
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/manpage-urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,6 @@
"nix-shell(1)": "https://nixos.org/manual/nix/stable/command-ref/nix-shell.html",
"mksquashfs(1)": "https://man.archlinux.org/man/extra/squashfs-tools/mksquashfs.1.en",
"curl(1)": "https://curl.se/docs/manpage.html",
"netrc(5)": "https://man.cx/netrc"
"netrc(5)": "https://man.cx/netrc",
"cat(1)": "https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html"
}
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- [Bat](https://github.com/sharkdp/bat), a {manpage}`cat(1)` clone with wings. Available as [programs.bat](options.html#opt-programs.bat).

- [Kimai](https://www.kimai.org/), a web-based multi-user time-tracking application. Available as [services.kimai](option.html#opt-services.kimai).

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
./programs/bash/blesh.nix
./programs/bash/ls-colors.nix
./programs/bash/undistract-me.nix
./programs/bat.nix
./programs/bcc.nix
./programs/benchexec.nix
./programs/browserpass.nix
Expand Down
121 changes: 121 additions & 0 deletions nixos/modules/programs/bat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
pkgs,
config,
lib,
...
}:
let
inherit (builtins) isList elem mapAttrs';
inherit (lib)
getExe
literalExpression
maintainers
mkEnableOption
mkIf
mkOption
mkPackageOption
nameValuePair
optionalString
types
;
inherit (types) listOf package;

cfg = config.programs.bat;

settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
inherit (settingsFormat) generate type;

initScript =
{
program,
shell,
flags ? [ ],
}:
if (shell != "fish") then
''
eval "$(${getExe program} ${toString flags})"
''
else
''
${getExe program} ${toString flags} | source
'';

shellInit =
shell:
optionalString (elem pkgs.bat-extras.batpipe cfg.extraPackages) (initScript {
program = pkgs.bat-extras.batpipe;
inherit shell;
})
+ optionalString (elem pkgs.bat-extras.batman cfg.extraPackages) (initScript {
program = pkgs.bat-extras.batman;
inherit shell;
flags = [ "--export-env" ];
});
in
{
options.programs.bat = {
enable = mkEnableOption "`bat`, a {manpage}`cat(1)` clone with wings";

package = mkPackageOption pkgs "bat" { };

extraPackages = mkOption {
default = [ ];
example = literalExpression ''
with pkgs.bat-extras; [
batdiff
batman
prettybat
];
'';
description = ''
Extra `bat` scripts to be added to the system configuration.
'';
type = listOf package;
};

settings = mkOption {
default = { };
example = {
theme = "TwoDark";
italic-text = "always";
paging = "never";
pager = "less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse";
map-syntax = [
"*.ino:C++"
".ignore:Git Ignore"
];
};
description = ''
Parameters to be written to the system-wide `bat` configuration file.
'';
type = type;
};
};

config = mkIf cfg.enable {
environment = {
systemPackages = [ cfg.package ] ++ cfg.extraPackages;
etc."bat/config".source = generate "bat-config" (
mapAttrs' (
name: value:
nameValuePair ("--" + name) (
if (isList value) then map (str: "\"${str}\"") value else "\"${value}\""
)
) cfg.settings
);
};

programs = {
bash = mkIf (!config.programs.fish.enable) {
interactiveShellInit = shellInit "bash";
};
fish = mkIf config.programs.fish.enable {
interactiveShellInit = shellInit "fish";
};
zsh = mkIf (!config.programs.fish.enable && config.programs.zsh.enable) {
interactiveShellInit = shellInit "zsh";
};
};
};
meta.maintainers = with maintainers; [ sigmasquadron ];
}

0 comments on commit f36897e

Please sign in to comment.