From 7390d759240785f660cbdb0ca55898732aa12c98 Mon Sep 17 00:00:00 2001 From: refaelsh Date: Tue, 8 Oct 2024 18:14:23 +0100 Subject: nix flake Author: refaelsh Date: Tue Oct 8 18:14:23 2024 +0100 --- nix/default.nix | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ nix/flake.lock | 95 +++++++++++++++++++++++++++++++++++++++++ nix/flake.nix | 64 ++++++++++++++++++++++++++++ nix/readme.org | 80 ++++++++++++++++++++++++++++++++++ 4 files changed, 369 insertions(+) create mode 100644 nix/default.nix create mode 100644 nix/flake.lock create mode 100644 nix/flake.nix create mode 100644 nix/readme.org (limited to 'nix') diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..aea52ed --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,130 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.programs.nixmobar; +in +{ + options.programs.nixmobar = { + enable = mkEnableOption (mdDoc "Xmobar, a minimalistic status bar"); + + font = mkOption { + type = types.str; + default = "Fira Code 13"; + description = mdDoc "Main font for Xmobar."; + }; + + additionalFonts = mkOption { + type = types.listOf types.str; + default = [ "Fira Code 22" ]; + description = mdDoc "Additional fonts for use in Xmobar."; + }; + + bgColor = mkOption { + type = types.str; + default = "#282a36"; + description = mdDoc "Background color of Xmobar."; + }; + + fgColor = mkOption { + type = types.str; + default = "#f8f8f2"; + description = mdDoc "Foreground (text) color of Xmobar."; + }; + + textOffset = mkOption { + type = types.int; + default = 2; + description = mdDoc "Offset of the text from the edge."; + }; + + verbose = mkOption { + type = types.bool; + default = true; + description = mdDoc "Enable verbose mode for Xmobar."; + }; + + allDesktops = mkOption { + type = types.bool; + default = true; + description = mdDoc "Show Xmobar on all desktops."; + }; + + lowerOnStart = mkOption { + type = types.bool; + default = true; + description = mdDoc "Whether Xmobar should be lowered on start."; + }; + + overrideRedirect = mkOption { + type = types.bool; + default = true; + description = mdDoc "If true, Xmobar will bypass window manager redirection."; + }; + + position = mkOption { + type = types.str; + default = "BottomH 26"; + description = mdDoc "Position of Xmobar on the screen."; + }; + + alpha = mkOption { + type = types.int; + default = 200; + description = mdDoc "Transparency level of Xmobar (0-255)."; + }; + + commands = mkOption { + type = types.lines; + default = '' + Run XMonadLog + Run DiskU ["/", "\\xf0a0 "] [] 50 + Run DiskIO ["/", " R W "] ["-t", "", "-w", "4"] 10 + Run Date "%a %_d %b %H:%M:%S" "date" 10 + # Add more commands here, one per line + ''; + description = mdDoc "List of commands to run in Xmobar, each on a new line."; + }; + + alignSep = mkOption { + type = types.str; + default = "}{"; + description = mdDoc "Separators for alignment left and right."; + }; + + template = mkOption { + type = types.str; + default = "%XMonadLog% }{ %load%|%disku%|%diskio%|%wifi_signal%|%dynnetwork%|󰈐%cat0%|%multicoretemp%|%cpufreq%|%multicpu%|%kbd%|%memory% %swap%|%battery%|%alsa:default:Master%|%kernel_version%|%date%|%_XMONAD_TRAYPAD%"; + description = mdDoc "Template string for Xmobar layout."; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.xmobar ]; + xdg.configFile."xmobar/.xmobarrc" = { + text = # haskell + '' + Config { + font = "${cfg.font}", + additionalFonts = [${lib.concatMapStringsSep ", " (s: "\"" + s + "\"") cfg.additionalFonts}], + bgColor = "${cfg.bgColor}", + fgColor = "${cfg.fgColor}", + textOffset = ${toString cfg.textOffset}, + verbose = ${if cfg.verbose then "True" else "False"}, + allDesktops = ${if cfg.allDesktops then "True" else "False"}, + lowerOnStart = ${if cfg.lowerOnStart then "True" else "False"}, + overrideRedirect = ${if cfg.overrideRedirect then "True" else "False"}, + position = ${cfg.position}, + alpha = ${toString cfg.alpha}, + commands = [${cfg.commands}], + alignSep = "${cfg.alignSep}", + template = "${cfg.template}" + } + ''; + }; + }; +} diff --git a/nix/flake.lock b/nix/flake.lock new file mode 100644 index 0000000..3f272ee --- /dev/null +++ b/nix/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "git-ignore-nix": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "ref": "master", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1666603677, + "narHash": "sha256-apAEIj+z1iwMaMJ4tB21r/VTetfGDLDzuhXRHJknIAU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "074da18a72269cc5a6cf444dce42daea5649b2fe", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728018373, + "narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bc947f541ae55e999ffdb4013441347d83b00feb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "git-ignore-nix": "git-ignore-nix", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..b422c9a --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,64 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + git-ignore-nix.url = "github:hercules-ci/gitignore.nix/master"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = + { + self, + nixpkgs, + flake-utils, + git-ignore-nix, + }: + let + overlay = final: prev: { + haskellPackages = prev.haskellPackages.override (old: { + overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) ( + hself: hsuper: { + xmobar = prev.haskell.lib.compose.dontCheck ( + hself.callCabal2nix "xmobar" (git-ignore-nix.lib.gitignoreSource ./.) { } + ); + } + ); + }); + }; + overlays = [ overlay ]; + + homeModules.mainmodule = import ./default.nix; + in + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system overlays; }; + dynamicLibraries = with pkgs; [ + xorg.libX11 + xorg.libXrandr + xorg.libXrender + xorg.libXScrnSaver + xorg.libXext + xorg.libXft + xorg.libXpm.out + xorg.libXrandr + xorg.libXrender + ]; + in + { + devShell = pkgs.haskellPackages.shellFor { + packages = p: [ p.xmobar ]; + buildInputs = + with pkgs; + [ + haskellPackages.cabal-install + ] + ++ dynamicLibraries; + + LD_LIBRARY_PATH = pkgs.lib.strings.makeLibraryPath dynamicLibraries; + }; + defaultPackage = pkgs.haskellPackages.xmobar; + } + ) + // { + inherit overlay overlays homeModules; + }; +} diff --git a/nix/readme.org b/nix/readme.org new file mode 100644 index 0000000..d83d232 --- /dev/null +++ b/nix/readme.org @@ -0,0 +1,80 @@ +* Nix flake for Xmobar +This flake exposes a module to use with home-manager. +Here is how to set it up: + +1. Add the nixmobar flake as an input to your NiOS flake: + #+BEGIN_SRC nix + inputs = { + nixmobar.url = "git+https://codeberg.org/xmobar/xmobar.git/?dir=nix"; + }; + #+END_SRC + +2. And then, where you import your `home.nix`, add `extraSpecialArgs` like this: + #+BEGIN_SRC nix + home-manager = { + extraSpecialArgs = { + inherit inputs nixmobar; + }; + users.refaelsh = import ./home.nix; + }; + #+END_SRC + +3. Final step, use the module in `home.nix`: + #+BEGIN_SRC nix + { + inputs, + ... + }: + { + home.stateversion = "24.05"; + + imports = [ + inputs.nixmobar.homemodules.mainmodule + # Other imports go here. + ]; + + } + #+END_SRC + +* Example usage +#+BEGIN_SRC haskell +{ + programs.nixmobar = { + enable = true; + font = "Fira Code 13"; + additionalFonts = [ "Fira Code 22" ]; + bgColor = "#282A36"; + fgColor = "#F8F8F2"; + textOffset = 2; + verbose = true; + allDesktops = true; + lowerOnStart = true; + overrideRedirect = true; + position = "BottomH 26"; + alpha = 200; + alignSep = "}{"; + template = "%XMonadLog% }{ %load%|%disku%|%diskio%|%wifi_signal%|%dynnetwork%|󰈐%cat0%|%multicoretemp%|%cpufreq%|%multicpu%|%kbd%|%memory% %swap%|%battery%|%alsa:default:Master%|%kernel_version%|%date%|%_XMONAD_TRAYPAD%"; + commands = # haskell + '' + Run XMonadLog, + Run DiskU [("/", "\xf0a0 ")] [] 50, + Run DiskIO [("/", " R W ")] ["-t", "", "-w", "4"] 10, + Run DynNetwork ["-t", "KB/s\x1F89B\x1F899KB/s", "-w", "5"] 10, + Run Memory ["-t", "\xE266%"] 10, + Run Swap ["-t", "S%"] 10, + Run Kbd [], + Run CpuFreq ["-t", "GHz"] 50, + Run MultiCoreTemp ["-t", "\xf2c9°", "-L", "60", "-H", "95", "-l", "white", "-n", "white", "-h", "red"] 50, + Run CatInt 0 "/sys/class/hwmon/hwmon4/fan1_input" [] 50, + Run MultiCpu ["-t", "\xf4bc ", "-w", "99", "-L", "3", "-H", "50", "--normal", "green", "--high", "red"] 10, + Run BatteryP ["BAT0"] ["-t", "󱊣%", "-L", "10", "-H", "80", "-p", "3", "--", "-O", "On - ", "-i", "", "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green", "-a", "notify-send -u critical 'Battery running out!!'", "-A", "3"] 600, + Run Alsa "default" "Master" ["-t", "\xf028 %"], + Run Date "%a %_d %b %H:%M:%S" "date" 10, + Run Load ["-t", "L", "-L", "1", "-H", "3", "-d", "2"] 300, + Run ComX "nmcli" ["-t", "-f", "SIGNAL", "dev", "wifi"] "N/A" "wifi_signal" 50, + Run Com "uname" ["-r"] "kernel_version" 3600, + Run XPropertyLog "_XMONAD_TRAYPAD" + ''; + }; +} +#+END_SRC -- cgit v1.2.3