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 12, 2024
1 parent 70e17e3 commit 0da86ca
Show file tree
Hide file tree
Showing 4 changed files with 84 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-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@

- [Zapret](https://github.com/bol-van/zapret), a DPI bypass tool. Available as [services.zapret](option.html#opt-services.zapret.enable).

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

## Backward Incompatibilities {#sec-release-24.11-incompatibilities}

- Nixpkgs now requires Nix 2.3.17 or newer to allow for zstd compressed binary artifacts.
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 @@ -158,6 +158,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
79 changes: 79 additions & 0 deletions nixos/modules/programs/bat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
pkgs,
config,
lib,
...
}:
let
inherit (lib)
literalExpression
maintainers
mkEnableOption
mkIf
mkOption
mkPackageOption
optionalString
types
;
inherit (types) lines listOf package;
cfg = config.programs.bat;
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;
};
# TODO: Somehow turn this into a structured submodule per RFC 0042.
# `bat`'s configuration syntax translates particularly terribly to
# Nix as some options can be declared multiple times and many options
# are actually aliases to other options and shouldn't be set together.
extraConfig = mkOption {
default = "";
example = ''
--theme="TwoDark"
--italic-text=always
--paging=never
--pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse"
--map-syntax "*.ino:C++"
--map-syntax ".ignore:Git Ignore"
'';
description = ''
Lines to be appended verbatim to the system-wide `bat` configuration file.
'';
type = lines;
};
};
config = mkIf cfg.enable {
environment = {
systemPackages = [ cfg.package ] ++ cfg.extraPackages;
etc."bat/config".text = cfg.extraConfig;
};

# TODO: Source the shell bindings for `bash` and `zsh` in a way that
# doesn't break those shells when they're not the system-wide default.
# This most likely happens due to bat{pipe,man}'s shell recognition
# function, which incorrectly detects the current shell and tries to
# run fish code in bash and vice-versa.
programs.fish.interactiveShellInit =
optionalString (lib.elem pkgs.bat-extras.batpipe cfg.extraPackages) ''
eval (${lib.getExe pkgs.bat-extras.batpipe})
''
+ optionalString (lib.elem pkgs.bat-extras.batman cfg.extraPackages) ''
eval (${lib.getExe pkgs.bat-extras.batman} --export-env)
'';
};
meta.maintainers = with maintainers; [ sigmasquadron ];
}

0 comments on commit 0da86ca

Please sign in to comment.