From a97e78aa1ab4f2518888a724e4adbd32d53a146c Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Sun, 20 Oct 2024 18:34:31 +0000 Subject: [PATCH] nixos/bat: init bat module Signed-off-by: Fernando Rodrigues --- doc/manpage-urls.json | 3 +- .../manual/release-notes/rl-2411.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/programs/bat.nix | 59 +++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 nixos/modules/programs/bat.nix diff --git a/doc/manpage-urls.json b/doc/manpage-urls.json index e878caf042a45c..ba18e98376f4fd 100644 --- a/doc/manpage-urls.json +++ b/doc/manpage-urls.json @@ -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" } diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index fb92e979484d0e..3cce763f8293e4 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -190,6 +190,8 @@ - [Zapret](https://github.com/bol-van/zapret), a DPI bypass tool. Available as [services.zapret](option.html#opt-services.zapret). +- [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} - The `sound` options have been removed or renamed, as they had a lot of unintended side effects. See [below](#sec-release-24.11-migration-sound) for details. diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index c8678720c29152..de9bbe4b7293a9 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -157,6 +157,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 diff --git a/nixos/modules/programs/bat.nix b/nixos/modules/programs/bat.nix new file mode 100644 index 00000000000000..eadc3f8d0f06f2 --- /dev/null +++ b/nixos/modules/programs/bat.nix @@ -0,0 +1,59 @@ +{ + pkgs, + config, + lib, + ... +}: +let + inherit (lib.options) mkEnableOption mkPackageOption mkOption; + inherit (lib.modules) mkIf; + inherit (lib.lists) optionals; + inherit (lib.types) lines; + inherit (lib) maintainers; + cfg = config.programs.bat; +in +{ + options.programs.bat = { + enable = mkEnableOption "`bat`, a {manpage}`cat(1)` clone with wings"; + package = mkPackageOption pkgs "bat" { }; + enableExtras = mkEnableOption "`bat`'s extra scripts and utilities"; + # 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 ] + ++ optionals cfg.enableExtras ( + with pkgs.bat-extras; + [ + batdiff + batgrep + batman + batpipe + batwatch + prettybat + ] + ); + etc."bat/config".text = cfg.extraConfig; + }; + }; + meta.maintainers = with maintainers; [ sigmasquadron ]; +}