From 3f6cb409cadf38e71d73f43af52ce27b6ee70214 Mon Sep 17 00:00:00 2001 From: t4ccer <64430288+t4ccer@users.noreply.github.com> Date: Tue, 29 Jun 2021 21:02:43 +0200 Subject: [PATCH] xmobar: add module (#2120) * xmobar: Add module * xmobar: Add test case xmobar: Add test default.nix * xmobar: Order lists alphabetically * xmobar: Change colon to comma in description * xmobar: Fix macos tests * xmobar: Remove extra line * xmobar: Add literalExample Co-authored-by: Sumner Evans * xmobar: Update extraConfig description Co-authored-by: Sumner Evans --- .github/CODEOWNERS | 3 + modules/modules.nix | 1 + modules/programs/xmobar.nix | 59 +++++++++++++++++++ tests/default.nix | 1 + .../xmobar/basic-configuration.expected | 19 ++++++ .../programs/xmobar/basic-configuration.nix | 39 ++++++++++++ tests/modules/programs/xmobar/default.nix | 1 + 7 files changed, 123 insertions(+) create mode 100644 modules/programs/xmobar.nix create mode 100644 tests/modules/programs/xmobar/basic-configuration.expected create mode 100644 tests/modules/programs/xmobar/basic-configuration.nix create mode 100644 tests/modules/programs/xmobar/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6ff2a0976..f7deb577f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -194,6 +194,9 @@ /modules/programs/waybar.nix @berbiche /tests/modules/programs/waybar @berbiche +/modules/programs/xmobar.nix @t4ccer +/tests/modules/programs/xmobar @t4ccer + /modules/programs/z-lua.nix @marsam /modules/programs/zathura.nix @rprospero diff --git a/modules/modules.nix b/modules/modules.nix index 30e7fecdd..6d6cff5db 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -146,6 +146,7 @@ let (loadModule ./programs/vscode.nix { }) (loadModule ./programs/vscode/haskell.nix { }) (loadModule ./programs/waybar.nix { condition = hostPlatform.isLinux; }) + (loadModule ./programs/xmobar.nix { }) (loadModule ./programs/z-lua.nix { }) (loadModule ./programs/zathura.nix { }) (loadModule ./programs/zoxide.nix { }) diff --git a/modules/programs/xmobar.nix b/modules/programs/xmobar.nix new file mode 100644 index 000000000..0ad5d7c19 --- /dev/null +++ b/modules/programs/xmobar.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.programs.xmobar; +in { + options.programs.xmobar = { + enable = mkEnableOption "Xmobar, a minimalistic status bar"; + + package = mkOption { + default = pkgs.haskellPackages.xmobar; + defaultText = literalExample "pkgs.haskellPackages.xmobar"; + type = types.package; + description = '' + Package providing the xmobar binary. + ''; + }; + + extraConfig = mkOption { + default = ""; + example = literalExample '' + Config + { font = "Fira Code" + , borderColor = "#d0d0d0" + , border = FullB + , borderWidth = 3 + , bgColor = "#222" + , fgColor = "grey" + , position = TopSize C 99 30 + , commands = + [ Run Cpu ["-t", "cpu: %"] 10 + , Run Network "enp3s0" ["-S", "True", "-t", "eth: /"] 10 + , Run Memory ["-t","mem: %"] 10 + , Run Date "date: %a %d %b %Y %H:%M:%S " "date" 10 + , Run StdinReader + ] + , sepChar = "%" + , alignSep = "}{" + , template = " %StdinReader% | %cpu% | %memory% | %enp3s0% }{%date% " + } + ''; + type = types.lines; + description = '' + Extra configuration lines to add to + $XDG_CONFIG_HOME/xmobar/.xmobarrc. + See + + for options. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile."xmobar/.xmobarrc".text = cfg.extraConfig; + }; + + meta.maintainers = with maintainers; [ t4ccer ]; +} diff --git a/tests/default.nix b/tests/default.nix index ef49cc397..130eab4c0 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -112,6 +112,7 @@ import nmt { ./modules/programs/rofi-pass ./modules/programs/terminator ./modules/programs/waybar + ./modules/programs/xmobar ./modules/services/barrier ./modules/services/dropbox ./modules/services/emacs diff --git a/tests/modules/programs/xmobar/basic-configuration.expected b/tests/modules/programs/xmobar/basic-configuration.expected new file mode 100644 index 000000000..51b06a7ef --- /dev/null +++ b/tests/modules/programs/xmobar/basic-configuration.expected @@ -0,0 +1,19 @@ +Config + { font = "Fira Code" + , borderColor = "#d0d0d0" + , border = FullB + , borderWidth = 3 + , bgColor = "#222" + , fgColor = "grey" + , position = TopSize C 99 30 + , commands = + [ Run Cpu ["-t", "cpu: %"] 10 + , Run Network "enp3s0" ["-S", "True", "-t", "eth: /"] 10 + , Run Memory ["-t","mem: %"] 10 + , Run Date "date: %a %d %b %Y %H:%M:%S " "date" 10 + , Run StdinReader + ] + , sepChar = "%" + , alignSep = "}{" + , template = " %StdinReader% | %cpu% | %memory% | %enp3s0% }{%date% " + } diff --git a/tests/modules/programs/xmobar/basic-configuration.nix b/tests/modules/programs/xmobar/basic-configuration.nix new file mode 100644 index 000000000..360cc4c3d --- /dev/null +++ b/tests/modules/programs/xmobar/basic-configuration.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.xmobar = { + enable = true; + extraConfig = '' + Config + { font = "Fira Code" + , borderColor = "#d0d0d0" + , border = FullB + , borderWidth = 3 + , bgColor = "#222" + , fgColor = "grey" + , position = TopSize C 99 30 + , commands = + [ Run Cpu ["-t", "cpu: %"] 10 + , Run Network "enp3s0" ["-S", "True", "-t", "eth: /"] 10 + , Run Memory ["-t","mem: %"] 10 + , Run Date "date: %a %d %b %Y %H:%M:%S " "date" 10 + , Run StdinReader + ] + , sepChar = "%" + , alignSep = "}{" + , template = " %StdinReader% | %cpu% | %memory% | %enp3s0% }{%date% " + } + ''; + }; + + nmt.script = '' + assertFileExists home-files/.config/xmobar/.xmobarrc + assertFileContent \ + home-files/.config/xmobar/.xmobarrc \ + ${./basic-configuration.expected} + ''; + }; +} diff --git a/tests/modules/programs/xmobar/default.nix b/tests/modules/programs/xmobar/default.nix new file mode 100644 index 000000000..f1a314890 --- /dev/null +++ b/tests/modules/programs/xmobar/default.nix @@ -0,0 +1 @@ +{ xmobar-basic-configuration = ./basic-configuration.nix; }