From ef5b48d142e34368fb1f6faff48a05ac819078be Mon Sep 17 00:00:00 2001 From: Filippo Berto Date: Fri, 11 Jun 2021 00:20:03 +0200 Subject: [PATCH] Palette library integrated + polybar and alacritty --- extra/color/default.nix | 303 +++++++++++++++++++++++++++++++++++++ extra/default.nix | 15 ++ extra/float/default.nix | 45 ++++++ extra/hex/default.nix | 46 ++++++ extra/palette/default.nix | 111 ++++++++++++++ home.nix | 161 ++++++++++++-------- modules/alacritty.nix | 72 +++------ modules/direnv.nix | 1 + modules/grobi.nix | 19 +++ modules/kakoune.nix | 101 ++++++++----- modules/kitty.nix | 3 + modules/lorri.nix | 3 + modules/polybar.nix | 307 ++++++++++++++++++++++++++++++++++++++ modules/screen_locker.nix | 13 +- modules/sxhkd.nix | 82 +++++----- modules/tmux.nix | 5 +- modules/zsh.nix | 17 ++- 17 files changed, 1090 insertions(+), 214 deletions(-) create mode 100644 extra/color/default.nix create mode 100644 extra/default.nix create mode 100644 extra/float/default.nix create mode 100644 extra/hex/default.nix create mode 100644 extra/palette/default.nix create mode 100644 modules/grobi.nix create mode 100644 modules/lorri.nix create mode 100644 modules/polybar.nix diff --git a/extra/color/default.nix b/extra/color/default.nix new file mode 100644 index 0000000..d839677 --- /dev/null +++ b/extra/color/default.nix @@ -0,0 +1,303 @@ +{ pkgs, lib ? pkgs.lib, hex, float, ... }: +let + inherit (builtins) isInt isString isFloat trace div isAttrs hasAttr; + inherit (lib.trivial) min max; + inherit (lib.lists) head tail drop last; + inherit (lib.strings) concatMapStrings fixedWidthString match toLower toInt; + + ## OPERATORS + # Module operator implementation for floats + div' = n: d: float.floor (div (float.ensureFloat n) (float.ensureFloat d)); + mod' = n: d: + let + f = div' n d; + in + n - (float.fromInt f) * d; + + # Absolute operator implementation + _abs = v: if v < 0 then (-v) else v; + + # Check if `v` is between `a` and `b` + _inRange = a: b: v: (v <= max a b) && (v >= min a b); + + # Clamp `v` between `a` and `v` + _clamp = a: b: v: min (max v (min a b)) (max a b); + + ## 8BIT + # Check if `v` is in 8Bit format + _is8Bit = v: _inRange 0.0 255.0 v; + + # Clamp 8bit value + _clamp8Bit = _clamp 0.0 255.0; + + # Apply function to 8bit value and clamp the result + _tclamp8Bit = f: v: _clamp8Bit (f v); + + ## UNARY + # Check if input is in [0, 1] + _isUnary = _inRange 0.0 1.0; + + # Clamp input to [0, 1] + _clampUnary = _clamp 0.0 1.0; + + # Apply function to unary value and clamp the result + _tclampUnary = f: v: _clampUnary (f v); + + + # Check if input is in [0, 360] + _isHue = _inRange 0.0 360.0; + + # Apply function to hue value and map the result in [0, 360) + _tHue = f: v: mod' (f v) 360.0; + + # RGB constructor + _rgba = { r, g, b, a ? 255.0 }: + assert (_is8Bit r); + assert (_is8Bit g); + assert (_is8Bit b); + { inherit r g b a; }; + + # HSLA constructor + _hsla = { h, l, s ? 1.0, a ? 255.0 }: + assert (_inRange 0.0 360.0 h); + assert (_isUnary s); + assert (_isUnary l); + assert (_isUnary a); + { inherit h s l a; }; + +in +rec { + + inherit div' mod' _abs _inRange _clamp _is8Bit _clamp8Bit _tclamp8Bit _isUnary _clampUnary _tclampUnary _tHue _rgba _hsla; + + rgba = _rgba; + + isRgba = c: if isAttrs c && hasAttr "r" c && hasAttr "g" c && hasAttr "b" c && hasAttr "a" c then + 0 <= c.r && c.r <= 255 && 0 <= c.g && c.g <= 255 && 0 <= c.b && c.b <= 255 && 0 <= c.a && c.a <= 255 + else false; + + hsla = _hsla; + + isHsla = c: if isAttrs c hasAttr "h" c && hasAttr "s" c && hasAttr "l" c && hasAttr "a" c then + 0 <= c.h && c.h <= 255 && 0 <= c.s && c.s <= 255 && 0 <= c.l && c.l <= 255 && 0 <= c.a && c.a <= 255 + else false; + + ## CONVERSION + # RGB to HSL + rgbaToHsla = color: + let + c_color = _rgba color; + r = c_color.r / 255.0; + g = c_color.g / 255.0; + b = c_color.b / 255.0; + a = c_color.a / 255.0; + c_min = min (min r g) b; + c_max = max (max r g) b; + delta = c_max - c_min; + + hue = ( + if delta == 0.0 then 0.0 else + if r == c_max then (mod' (((g - b) / delta) + 6) 6) else + if g == c_max then (b - r) / delta + 2 else + assert b == c_max; (r - g) / delta + 4 + ) * 60; + lightness = (c_min + c_max) / 2.0; + saturation = + if delta == 0.0 then 0.0 else + delta / (1 - _abs (2.0 * lightness - 1.0)); + in + assert (isRgba color); + _hsla { + l = _clampUnary lightness; + s = _clampUnary saturation; + h = mod' hue 360.0; + a = _clampUnary a; + }; + + # HSL to RGB + hslToRgb = color: + let + # check if `v` is in [a, b) + _checkRange = a: b: v: a <= v && v < b; + c_color = _hsla color; + h = c_color.h; + s = c_color.s; + l = c_color.l; + a = c_color.a; + c = (1 - (_abs (2 * l - 1))) * s; + x = c * (1 - _abs ((mod' (h / 60) 2) - 1)); + m = l - (c / 2.0); + + r' = if _inRange 120 240 h then 0 else + if _inRange 60 300 h then x else + c; + g' = if _inRange 60 180 h then c else + if _inRange 0 240 h then x else + 0; + b' = if _inRange 180 300 h then c else + if _inRange 120 360 h then x else + 0; + in + assert (isHsla); + _rgba { + r = _clamp8Bit ((r' + m) * 255.0); + g = _clamp8Bit ((g' + m) * 255.0); + b = _clamp8Bit ((b' + m) * 255.0); + a = _clamp8Bit (a * 255.0); + }; + + ## TRANSFORM + + tRedRgba = f: color: assert (isRgba color); color // { r = _tclamp8Bit f color.r; }; + tGreenRgba = f: color: assert (isRgba color); color // { g = _tclamp8Bit f color.g; }; + tBlueRgba = f: color: assert (isRgba color); color // { b = _tclamp8Bit f color.b; }; + tAlphaRgba = f: color: assert (isRgba color); color // { a = _tclamp8Bit f color.a; }; + + setRedRgba = r: color: tGreenRgba (v: r) color; + setGreenRgba = g: color: tBlueRgba (v: g) color; + setBlueRgba = b: color: tAlphaRgba (v: b) color; + setAlphaRgba = a: color: tRedRgba (v: a) color; + + tRedHsla = f: color: assert (isHsla color); color // { h = _tHue f color.h; }; + tGreenHsla = f: color: assert (isHsla color); color // { s = _tclampUnary f color.s; }; + tBlueHsla = f: color: assert (isHsla color); color // { l = _tclampUnary f color.l; }; + tAlphaHsla = f: color: assert (isHsla color); color // { a = _tclampUnary f color.a; }; + + setRedHsla = h: color: tGreenHsla (v: h) color; + setGreenHsla = s: color: tBlueHsla (v: s) color; + setBlueHsla = l: color: tAlphaHsla (v: l) color; + setAlphaHsla = a: color: tRedHsla (v: a) color; + + ## RGB TRANSFORM + # Add brightness value as integer value or percent value + brighten = color: value: + let + directValue = if isInt value || isFloat value then value else null; + positiveMatches = match "([[:digit:]]+)%" value; + negativeMatches = match "-([[:digit:]]+)%" value; + percentValue = + if positiveMatches != null then toInt (head positiveMatches) + else if negativeMatches != null then (-toInt (head negativeMatches)) + else null; + valueTransform = v: + if directValue != null then _clamp8Bit (v + directValue) + else _clamp8Bit (v * (100.0 + percentValue) / 100.0); + in + tBlueRgba valueTransform (tGreenRgba valueTransform (tRedRgba valueTransform color)); + + darken = color: value: + let + directValue = if isInt value || isFloat value then value else null; + positiveMatches = match "([[:digit:]]+)%" value; + negativeMatches = match "-([[:digit:]]+)%" value; + percentValue = + if positiveMatches != null then toInt (head positiveMatches) + else if negativeMatches != null then (-toInt (head negativeMatches)) + else null; + valueTransform = v: + if directValue != null then _clamp8Bit (v - directValue) + else _clamp8Bit (v * (100.0 - percentValue) / 100.0); + in + tBlueRgba valueTransform (tGreenRgba valueTransform (tRedRgba valueTransform color)); + + ## DESERIALIZATION + # Parse a hex color string to a RGBA color + hexToRgba = s: + let + rgba = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; + rgb = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; + hex_list = (if isNull rgb then rgba else rgb ++ [ "FF" ]); + values = map (s: float.fromInt (hex.toDec s)) hex_list; + in + _rgba { + r = head values; + g = head (tail values); + b = head (drop 2 values); + a = last values; + }; + + # Parse a hex color string to a HSLA color + hexToHsla = s: + let + hsla = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; + hsl = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; + hex_list = (if isNull hsl then hsla else hsl ++ [ "FF" ]); + values = map (s: float.fromInt (hex.toDec s)) hex_list; + in + _hsla { + h = head values; + s = head (tail values); + l = head (drop 2 values); + a = last values; + }; + + + ## SERIALIZATION + # Print RGB color as uppercase hex string + toRGBHex = color: + let + inherit (color) r g b; + in + assert (isRgba color); + ''#${concatMapStrings (v: fixedWidthString 2 "0" (hex.fromDec (float.round v))) [ r g b ]}''; + + # Print RGBA color as uppercase hex string + toRGBAHex = color: + let + inherit (color) r g b a; + in + assert (isRgba color); + ''#${concatMapStrings (v: fixedWidthString 2 "0" (hex.fromDec (float.round v))) [ r g b a ]}''; + + # Print RGBA color as uppercase hex string in the form ARGB (Polybar uses this format) + toARGBHex = color: + let + inherit (color) r g b a; + in + assert (isRgba color); + ''#${concatMapStrings (v: fixedWidthString 2 "0" (hex.fromDec (float.round v))) [ a r g b ]}''; + + + # Print RGB color as lowercase hex string + toRgbHex = color: toLower (toRGBHex color); + + # Print RGBA color as lowercase hex string + toRgbaHex = color: toLower (toRGBAHex color); + + # Print RGBA color as lowercase hex string in the form argb (Polybar uses this format) + toArgbHex = color: toLower (toArgbHex color); + + # Print RGB color as uppercase hex string + toHSLHex = color: + let + inherit (color) h s l; + in + assert (isHsla color); + ''#${concatMapStrings (v: fixedWidthString 2 "0" (hex.fromDec (float.round v))) [ h s l ]}''; + + # Print HSLA color as uppercase hex string + toHSLAHex = color: + let + inherit (color) h s l a; + in + assert (isHsla color); + ''#${concatMapStrings (v: fixedWidthString 2 "0" (hex.fromDec (float.round v))) [ h s l a ]}''; + + # Print HSL color as lowercase hex string + toHslHex = color: toLower (toHSLHex color); + + # Print HSLA color as lowercase hex string + toHslaHex = color: toLower (toHSLAHex color); + + + ## CONSTANTS + black = hexToRgba "#000000"; # RGB (0,0,0) HSL (0°,0%,0%) + white = hexToRgba "#FFFFFF"; # RGB (255,255,255) HSL (0°,0%,100%) + red = hexToRgba "#FF0000"; # RGB (255,0,0) HSL (0°,100%,50%) + green = hexToRgba "#00FF00"; # RGB (0,255,0) HSL (120°,100%,50%) + blue = hexToRgba "#0000FF"; # RGB (0,0,255) HSL (240°,100%,50%) + yellow = hexToRgba "#FFFF00"; # RGB (255,255,0) HSL (60°,100%,50%) + cyan = hexToRgba "#00FFFF"; # RGB (0,255,255) HSL (180°,100%,50%) + magenta = hexToRgba "#FF00FF"; # RGB (255,0,255) HSL (300°,100%,50%) + transparent = hexToRgba "#00000000"; # RGBA (0,0,0,0) HSLA (0°,0%,0%,0%) +} diff --git a/extra/default.nix b/extra/default.nix new file mode 100644 index 0000000..61751df --- /dev/null +++ b/extra/default.nix @@ -0,0 +1,15 @@ +{ system ? builtins.currentSystem +, pkgs ? import {} +, lib ? pkgs.lib +, ... +}: +let + callPackage = lib.callPackageWith (pkgs // self); + self = rec { + float = callPackage ./float {}; + hex = callPackage ./hex {}; + color = callPackage ./color {}; + palette = callPackage ./palette {}; + }; +in +(self) diff --git a/extra/float/default.nix b/extra/float/default.nix new file mode 100644 index 0000000..6df72be --- /dev/null +++ b/extra/float/default.nix @@ -0,0 +1,45 @@ +{ pkgs, lib ? pkgs.lib, ... }: +let + inherit (builtins) head tail isFloat isInt; + inherit (lib.strings) toInt match splitString; + floatComponents = f: splitString "." (toString f); +in +rec { + + # Force a number to be a float (hacky but works) + ensureFloat = v: + assert (isInt v || isFloat v); + v + 0.1 - 0.1; + + # Convert integer to float (hacky but it works) + fromInt = i: + assert isInt i; + ensureFloat i; + + # Round float to upper integer + ceil = f: + let + comp = floatComponents f; + int = toInt (head comp); + inc = if match "[1-9][[:digit:]]*" (head (tail comp)) != null then 1 else 0; + in + assert(isFloat f); + int + inc; + + # Round float to lower integer + floor = f: + let + int = toInt (head (floatComponents f)); + in + assert(isFloat f); + int; + + # Round float to closest integer + round = f: + let + comp = floatComponents (ensureFloat f); + int = toInt (head comp); + inc = if match "[5-9][[:digit:]]*" (head (tail comp)) != null then 1 else 0; + in + int + inc; +} diff --git a/extra/hex/default.nix b/extra/hex/default.nix new file mode 100644 index 0000000..0001f49 --- /dev/null +++ b/extra/hex/default.nix @@ -0,0 +1,46 @@ +{ pkgs, lib ? pkgs.lib, ... }: +let + inherit (lib.trivial) toHexString; + inherit (lib.strings) match toUpper stringToCharacters; + inherit (lib.lists) foldl; + + # Parse a single hexadecimal digit to an integer + _parseDigit = c: + let + v = toUpper c; + in + assert(match "[0-9A-F]" v != null); + { + "0" = 0; + "1" = 1; + "2" = 2; + "3" = 3; + "4" = 4; + "5" = 5; + "6" = 6; + "7" = 7; + "8" = 8; + "9" = 9; + "A" = 10; + "B" = 11; + "C" = 12; + "D" = 13; + "E" = 14; + "F" = 15; + }."${v}"; + +in +rec { + + # Convert an hexadecimal string to an integer + toDec = s: + let + characters = stringToCharacters s; + values = map _parseDigit characters; + in + foldl (acc: n: acc * 16 + n) 0 values; + + # Convert an integer to a decimal string + fromDec = toHexString; + +} diff --git a/extra/palette/default.nix b/extra/palette/default.nix new file mode 100644 index 0000000..3383564 --- /dev/null +++ b/extra/palette/default.nix @@ -0,0 +1,111 @@ +{ pkgs, color, lib, ... }: +let + inherit (builtins) isString; + inherit (lib.attrsets) mapAttrsRecursiveCond; +in +rec{ + + # Palette constructor + # Produces a palette of colors starting from sane defaults + # Override the inputs with your favorite colors + palette = + { black ? color.black + , red ? color.red + , green ? color.green + , yellow ? color.yellow + , blue ? color.blue + , magenta ? color.magenta + , cyan ? color.cyan + , white ? color.white + , bright-black ? color.brighten black "10%" + , bright-red ? color.brighten red "10%" + , bright-green ? color.brighten green "10%" + , bright-yellow ? color.brighten yellow "10%" + , bright-blue ? color.brighten blue "10%" + , bright-magenta ? color.brighten magenta "10%" + , bright-cyan ? color.brighten cyan "10%" + , bright-white ? color.brighten white "10%" + , dim-black ? color.darken black "10%" + , dim-red ? color.darken red "10%" + , dim-green ? color.darken green "10%" + , dim-yellow ? color.darken yellow "10%" + , dim-blue ? color.darken blue "10%" + , dim-magenta ? color.darken magenta "10%" + , dim-cyan ? color.darken cyan "10%" + , dim-white ? color.darken white "10%" + , primary-background ? black + , primary-foreground ? white + , primary-dim_foreground ? color.darken primary-foreground "10%" + , cursor-text ? primary-background + , cursor-cursor ? primary-foreground + , vi-cursor-text ? cursor-text + , vi-cursor-cursor ? cursor-cursor + }: { + normal = { + black = assert(color.isRgba black); black; + red = assert(color.isRgba red); red; + green = assert(color.isRgba green); green; + yellow = assert(color.isRgba yellow); yellow; + blue = assert(color.isRgba blue); blue; + magenta = assert(color.isRgba magenta); magenta; + cyan = assert(color.isRgba cyan); cyan; + white = assert(color.isRgba white); white; + }; + bright = { + black = assert(color.isRgba bright-black); bright-black; + red = assert(color.isRgba bright-red); bright-red; + green = assert(color.isRgba bright-green); bright-green; + yellow = assert(color.isRgba bright-yellow); bright-yellow; + blue = assert(color.isRgba bright-blue); bright-blue; + magenta = assert(color.isRgba bright-magenta); bright-magenta; + cyan = assert(color.isRgba bright-cyan); bright-cyan; + white = assert(color.isRgba bright-white); bright-white; + }; + dim = { + black = assert(color.isRgba dim-black); dim-black; + red = assert(color.isRgba dim-red); dim-red; + green = assert(color.isRgba dim-green); dim-green; + yellow = assert(color.isRgba dim-yellow); dim-yellow; + blue = assert(color.isRgba dim-blue); dim-blue; + magenta = assert(color.isRgba dim-magenta); dim-magenta; + cyan = assert(color.isRgba dim-cyan); dim-cyan; + white = assert(color.isRgba dim-white); dim-white; + }; + primary = { + background = assert(color.isRgba primary-background); primary-background; + foreground = assert(color.isRgba primary-foreground); primary-foreground; + dim_foreground = assert(color.isRgba primary-dim_foreground);primary-dim_foreground; + }; + cursor = { + cursor = assert(color.isRgba cursor-cursor); cursor-cursor; + text = assert(color.isRgba cursor-text); cursor-text; + }; + vi_mode_cursor = { + cursor = assert(color.isRgba cursor-cursor); cursor-cursor; + text = assert(color.isRgba cursor-text); cursor-text; + }; + }; + + + ## TRANSFORM + tPalette = f: p: mapAttrsRecursiveCond (v: !color.isRgba v) (a: v: f v) p; + + ## SERIALIZATION + # Try to convert input colors to a lowercase hex encoded RGBA color + toRgbaHex = tPalette color.toRgbaHex; + + # Try to convert input colors to a uppercase hex encoded RGBA color + toRGBAHex = tPalette color.toRGBAHex; + + # Try to convert input colors to a lowercase hex encoded RGB color + toRgbHex = tPalette color.toRgbHex; + + # Try to convert input colors to a lowercase hex encoded RGB color + toRGBHex = tPalette color.toRGBHex; + + # Try to convert input colors to a uppercase hex encoded RGB color in the form ARGB (Polybar uses this format) + toARGBHex = tPalette color.toARGBHex; + + # Try to convert input colors to a lowercase hex encoded RGB color in the form argb (Polybar uses this format) + toArgbHex = tPalette color.toArgbHex; +} diff --git a/home.nix b/home.nix index d9a0f56..15b45da 100644 --- a/home.nix +++ b/home.nix @@ -2,77 +2,106 @@ let callPackage = pkgs.lib.callPackageWith pkgs; - nixpkgs = import {}; custom = import ./custom/default.nix {}; - colorscheme.theme = import ./packages/nord.nix; -in { + nord = import ./configs/themes/nord.nix; + extra = callPackage ./extra/default.nix {}; +in +{ fonts.fontconfig = { enable = true; }; + nixpkgs.overlays = [ + (final: prev: { extra = (prev.lib.callPackageWith prev) ./extra/default.nix {}; }) + ( + final: prev: { + extra = prev.extra // { + colorTheme = import ./configs/themes/nord.nix; + colorPalette = with extra; palette.palette { + black = color.hexToRgba nord.n0; + red = color.hexToRgba nord.n11; + green = color.hexToRgba nord.n14; + yellow = color.hexToRgba nord.n13; + blue = color.hexToRgba nord.n10; + magenta = color.hexToRgba nord.n15; + cyan = color.hexToRgba nord.n8; + white = color.hexToRgba nord.n4; + + bright-white = color.hexToRgba nord.n6; + bright-red = color.hexToRgba nord.n12; + cursor-cursor = color.hexToRgba nord.n4; + }; + }; + } + ) + ]; + home = { language.base = "it_IT.UTF-8"; keyboard.layout = "it"; - keyboard.options = ["terminate:ctrl_alt_bksp" "compose:rctrl"]; - packages = (with pkgs; [ - authy - blender - discord - evolution - firefox - gallery-dl - gnome3.dconf-editor - gnome3.easytag - gnome3.eog - gnome3.evince - gnome3.file-roller - gnome3.ghex - gnome3.gitg - gnome3.gnome-screenshot - gnome3.gnome-system-monitor - gnome3.gnome-tweaks - gnome3.nautilus - gnome3.seahorse - gnome3.sushi - htop - jetbrains.datagrip - keepassxc - krita - libreoffice-fresh - lutris - megasync - mpv - neofetch - nerdfonts - nix-prefetch-git - obsidian - openvpn - pavucontrol - pcmanfm - pentablet-driver - polybarFull - procps-ng - shotwell - slack - spotify - tdesktop - teams - transmission-gtk - wireguard - zotero - ]) ++ (with nixpkgs; [ - # steam - skypeforlinux - ]) ++ (with custom; [ - gallery-tagger - ]); + keyboard.options = [ "terminate:ctrl_alt_bksp" "compose:rctrl" ]; + packages = ( + with pkgs; [ + audacity + authy + blender + discord + evolution + firefox + gallery-dl + gnome3.dconf-editor + gnome3.easytag + gnome3.eog + gnome3.evince + gnome3.file-roller + gnome3.ghex + gnome3.gitg + gnome3.gnome-screenshot + gnome3.gnome-system-monitor + gnome3.gnome-tweaks + gnome3.nautilus + gnome3.seahorse + gnome3.sushi + google-chrome + htop + jetbrains.datagrip + keepassxc + krita + libreoffice-fresh + lutris + megasync + mpv + neofetch + nerdfonts + nix-prefetch-git + obsidian + openvpn + pavucontrol + pcmanfm + pentablet-driver + # polybarFull + procps-ng + shotwell + skypeforlinux + slack + spotify + tdesktop + teams + transmission-gtk + wireguard + zoom-us + zotero + ] + ) ++ ( + with custom; [ + gallery-tagger + ] + ); }; programs.zsh.enable = true; imports = [ - ./extralib.nix - ./modules/configurations.nix ./modules/alacritty.nix @@ -81,23 +110,27 @@ in { ./modules/bottom.nix ./modules/broot.nix ./modules/dircolors.nix + ./modules/direnv.nix ./modules/dunst.nix # ./modules/fzf.nix ./modules/git.nix ./modules/go.nix ./modules/gpg.nix + ./modules/grobi.nix ./modules/info.nix ./modules/jq.nix ./modules/kakoune.nix ./modules/keychain.nix # ./modules/kitty.nix ./modules/lf.nix + ./modules/lorri.nix ./modules/man.nix # ./modules/nix-index.nix ./modules/noti.nix ./modules/obs-studio.nix # ./modules/pazi.nix ./modules/picom.nix + ./modules/polybar.nix ./modules/qogir_theme.nix ./modules/rofi.nix ./modules/screen_locker.nix @@ -123,9 +156,13 @@ in { # }; }; - services.gnome-keyring.enable = true; - services.blueman-applet.enable = true; - services.network-manager-applet.enable = true; + services = { + blueman-applet.enable = true; + caffeine.enable = true; + cbatticon.enable = true; + gnome-keyring.enable = true; + playerctld.enable = true; + network-manager-applet.enable = true; + }; xsession.numlock.enable = true; } - diff --git a/modules/alacritty.nix b/modules/alacritty.nix index 823ed58..cdc73c4 100644 --- a/modules/alacritty.nix +++ b/modules/alacritty.nix @@ -1,12 +1,11 @@ -{ pkgs, ... }: -let - nord = import ../configs/themes/nord.nix; -in { +{ pkgs, lib, ... }: +{ # Include fonts packages home.packages = with pkgs; [ nerdfonts ]; programs.alacritty = { enable = true; settings = { + env.TERM = "xterm-256color"; scrolling.history = 3000; font = { normal.family = "FuraCode Nerd Font Mono"; @@ -18,65 +17,28 @@ in { hints.modifiers = "Control"; }; - # NORD Theme: https://github.com/arcticicestudio/nord-alacritty - colors = { - primary = { - background = nord.n0; - foreground = nord.n6; - dim_foreground = nord.n4; - }; - cursor = { - text = nord.n0; - cursor = nord.n4; - }; - vi_mode_cursor = { - text = nord.n0; - cursor = nord.n4; - }; + colors = with pkgs.extra; { + + primary = palette.toRgbHex colorPalette.primary; + cursor = palette.toRgbHex colorPalette.cursor; + vi_mode_cursor = palette.toRgbHex colorPalette.vi_mode_cursor; selection = { text = "CellForeground"; - background = nord.n3; + background = color.toRgbHex colorPalette.dim.blue; }; search = { - matches = { + matches = { foreground = "CellForeground"; - background = nord.n8; - }; + background = color.toRgbHex colorPalette.dim.cyan; + }; bar = { - background = nord.n2; - foreground = nord.n4; + # foreground = "CellForeground"; + background = color.toRgbHex colorPalette.dim.yellow; }; }; - normal = { - black = nord.n0; - red = nord.n11; - green = nord.n14; - yellow = nord.n13; - blue = nord.n9; - magenta = nord.n15; - cyan = nord.n9; - white = nord.n5; - }; - bright = { - black = nord.n3; - red = nord.n11; - green = nord.n14; - yellow = nord.n13; - blue = nord.n9; - magenta = nord.n15; - cyan = nord.n8; - white = nord.n6; - }; - dim = { - black = "#373e4d"; - red = "#94545d"; - green = "#809575"; - yellow = "#b29e75"; - blue = "#68809a"; - magenta = "#8c738c"; - cyan = "#6d96a5"; - white = nord.n4; - }; + normal = palette.toRgbHex colorPalette.normal; + bright = palette.toRgbHex colorPalette.bright; + dim = palette.toRgbHex colorPalette.dim; }; }; }; diff --git a/modules/direnv.nix b/modules/direnv.nix index 593881d..7b7ea65 100644 --- a/modules/direnv.nix +++ b/modules/direnv.nix @@ -3,5 +3,6 @@ enable = true; enableBashIntegration = true; enableZshIntegration = true; + enableNixDirenvIntegration = true; }; } diff --git a/modules/grobi.nix b/modules/grobi.nix new file mode 100644 index 0000000..5a87b34 --- /dev/null +++ b/modules/grobi.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: +{ + services.grobi = { + enable = true; + rules = [ + { + name = "Home"; + outputs_connected = [ "HDMI-0" "eDP-1-1" ]; + configure_row = [ "eDP-1-1" "HDMI-0" ]; + primary = "HDMI-0"; + } + { + name = "Fallback"; + configure_single = "eDP-1-1"; + } + ]; + }; + +} diff --git a/modules/kakoune.nix b/modules/kakoune.nix index 2ef59ca..276e979 100644 --- a/modules/kakoune.nix +++ b/modules/kakoune.nix @@ -2,7 +2,34 @@ let nixpkgs = import {}; kakCmd = "kak"; -in { + + rustPlugins = with pkgs; [ + cargo + cargo-watch + clippy + rust-analyzer + rustup + ]; + pythonPlugins = with pkgs.python38Packages; [ + pyls-black + python-language-server + ]; + nixPlugins = with pkgs; [ + rnix-lsp + ]; + spellingPlugins = with pkgs; [ + aspell + aspellDicts.en + aspellDicts.en-computers + aspellDicts.en-science + aspellDicts.it + ]; + dataFormats = with pkgs; [ + # yaml-language-server + ]; + +in +{ home.sessionVariables = { EDITOR = kakCmd; VISUAL = kakCmd; @@ -11,8 +38,8 @@ in { programs.zsh.shellAliases = { k = kakCmd; }; programs.kakoune = { - enable = true; - config = { + enable = true; + config = { colorScheme = "nord"; tabStop = 2; indentWidth = 2; @@ -36,54 +63,58 @@ in { }; keyMappings = [ { mode = "normal"; docstring = "Open file"; key = ""; effect = ":edit"; } + { mode = "user"; docstring = "Code actions"; key = "a"; effect = ":lsp-code-actions"; } { mode = "user"; docstring = "Comment block"; key = "b"; effect = ":comment-block"; } { mode = "user"; docstring = "Comment line"; key = "l"; effect = ":comment-line"; } - { mode = "user"; docstring = "Show hover info"; key = "q"; effect = ":lsp-hover"; } - { mode = "user"; docstring = "Jump to definition"; key = "d"; effect = ":lsp-definition"; } - { mode = "user"; docstring = "List project diagnostics"; key = "i"; effect = ":lsp-diagnostics"; } - { mode = "user"; docstring = "Jump to type definition"; key = "t"; effect = ":lsp-type-definition"; } - { mode = "user"; docstring = "Code actions"; key = "a"; effect = ":lsp-code-actions"; } - { mode = "user"; docstring = "Format code"; key = "F"; effect = ":lsp-formatting-sync"; } - { mode = "user"; docstring = "Spellcheck"; key = "s"; effect = ":spell "; } - { mode = "user"; docstring = "Spellcheck English"; key = "S"; effect = ":spell en"; } { mode = "user"; docstring = "Copy to clipboard"; key = "y"; effect = "${pkgs.xclip}/bin/xclip -i -selection clipboard"; } - { mode = "user"; docstring = "Paste from clipboard (before)"; key = "p"; effect = "!${pkgs.xclip}/bin/xclip -selection clipboard -o"; } + { mode = "user"; docstring = "Format code"; key = "F"; effect = ":lsp-formatting-sync"; } + { mode = "user"; docstring = "Jump to definition"; key = "d"; effect = ":lsp-definition"; } + { mode = "user"; docstring = "Jump to type definition"; key = "t"; effect = ":lsp-type-definition"; } + { mode = "user"; docstring = "List project diagnostics"; key = "i"; effect = ":lsp-diagnostics"; } { mode = "user"; docstring = "Paste from clipboard (after)"; key = "P"; effect = "${pkgs.xclip}/bin/xclip -selection clipboard -o"; } + { mode = "user"; docstring = "Paste from clipboard (before)"; key = "p"; effect = "!${pkgs.xclip}/bin/xclip -selection clipboard -o"; } + { mode = "user"; docstring = "Show hover info"; key = "q"; effect = ":lsp-hover"; } + { mode = "user"; docstring = "Spellcheck English"; key = "S"; effect = ":spell en"; } + { mode = "user"; docstring = "Spellcheck"; key = "s"; effect = ":spell "; } ]; hooks = [ - { name = "WinSetOption"; option = "filetype=(rust|python|c|cpp|latex|javascript|go|nix)"; commands = builtins.concatStringsSep "\n" [ "lsp-enable-window" ]; } - # { name = "BufCreate"; option = ".*"; commands = "editorconfig-load"; } - { name = "ModuleLoaded"; option = "powerline"; commands = builtins.concatStringsSep "\n" [ "powerline-enable" ]; } - { name = "ModuleLoaded"; option = "auto-pairs"; commands = "auto-pairs-enable"; } - { name = "InsertCompletionShow"; option = ".*"; commands = builtins.concatStringsSep "\n" [ "map window insert " "map window insert " ]; } + { name = "BufCreate"; option = ".*"; commands = "editorconfig-load"; } { name = "InsertCompletionHide"; option = ".*"; commands = builtins.concatStringsSep "\n" [ "unmap window insert " "unmap window insert " ]; } + { name = "InsertCompletionShow"; option = ".*"; commands = builtins.concatStringsSep "\n" [ "map window insert " "map window insert " ]; } + { name = "ModuleLoaded"; option = "auto-pairs"; commands = "auto-pairs-enable"; } + { name = "ModuleLoaded"; option = "powerline"; commands = builtins.concatStringsSep "\n" [ "powerline-enable" ]; } + { name = "WinSetOption"; option = "filetype=(rust|python|c|cpp|latex|javascript|go|nix)"; commands = builtins.concatStringsSep "\n" [ "lsp-enable-window" ]; } ]; }; - extraConfig = builtins.concatStringsSep "\n" [ + extraConfig = builtins.concatStringsSep "\n" [ "# Custom commands" "define-command -docstring 'save and quit' x 'write-all; quit' # Save and quit with 'x'" "add-highlighter global/ regex \\h+$ 0:Error # Highlight trailing spaces" "eval %sh{kak-lsp --kakoune -s \$kak_session} # Start kak-lsp" + "require-module prelude" "# require-module auto-pairs" + "require-module connect" + "require-module connect-broot" + "require-module connect-lf" + "require-module connect-rofi" "require-module powerline" - ]; - plugins = (with pkgs; [ - aspell - aspellDicts.en - aspellDicts.en-computers - aspellDicts.en-science - aspellDicts.it - kak-lsp - kakounePlugins.powerline-kak - rnix-lsp - ]) ++ (with nixpkgs; [ - # kakounePlugins.kak-lsp - # kakounePlugins.prelude-kak - # kakounePlugins.auto-pairs-kak - ]); + ]; + plugins = ( + with pkgs; [ + broot + lf + editorconfig-core-c + kakounePlugins.auto-pairs-kak + kakounePlugins.kak-lsp + kakounePlugins.powerline-kak + kakounePlugins.prelude-kak + ] + ) ++ ( + with nixpkgs; [ + kakounePlugins.connect-kak + ] + ) ++ rustPlugins ++ pythonPlugins ++ nixPlugins ++ spellingPlugins ++ dataFormats; }; xdg.configFile."kak-lsp/kak-lsp.toml".source = ../configs/kak-lsp/kak-lsp.toml; } - - diff --git a/modules/kitty.nix b/modules/kitty.nix index bef212e..76b4085 100644 --- a/modules/kitty.nix +++ b/modules/kitty.nix @@ -13,5 +13,8 @@ in { # }; font = "FuraCode Nerd Font Mono 10"; }; + extraConfig = '' +backround_opacity = 0.95; + ''; }; } diff --git a/modules/lorri.nix b/modules/lorri.nix new file mode 100644 index 0000000..ea26f6c --- /dev/null +++ b/modules/lorri.nix @@ -0,0 +1,3 @@ +{ + services.lorri.enable = true; +} diff --git a/modules/polybar.nix b/modules/polybar.nix new file mode 100644 index 0000000..aed06f5 --- /dev/null +++ b/modules/polybar.nix @@ -0,0 +1,307 @@ +{ config, lib, pkgs, ... }: +let + grep = "${pkgs.gnugrep}/bin/grep"; + cut = "${pkgs.coreutils}/bin/cut"; + pavucontrol = "${pkgs.pavucontrol}/bin/pavucontrol"; + pgrep = "${pkgs.procps}/bin/pgrep"; + pkill = "${pkgs.procps}/bin/pkill"; + playerCtl = "${pkgs.playerctl}/bin/playerctl"; + playerStatus = "${playerCtl} -f '{{emoji(status)}} {{title}} - {{artist}}' metadata"; + colors = with pkgs.extra; palette.toARGBHex rec { + + normal = { + foreground = colorPalette.normal.white; + background = color.tAlphaRgba (v: 240) colorPalette.normal.black; + underline = colorPalette.normal.blue; + }; + + active = palette.tPalette (c: color.brighten c "50%") normal; + + selected = { + foreground = colorPalette.bright.white; + background = color.tAlphaRgba (v: 240) colorPalette.dim.blue; + underline = colorPalette.dim.white; + }; + + alert = colorPalette.bright.red; + + green = colorPalette.normal.green; + yellow = colorPalette.normal.yellow; + orange = colorPalette.bright.red; + red = colorPalette.normal.red; + + transparent = color.transparent; + }; + + commonBar = { + locale = config.home.language.base; + monitor = "\${env:MONITOR}"; + width = "100%"; + height = 20; + radius = 6.0; + fixed-center = false; + background = colors.normal.background; + foreground = colors.normal.foreground; + line-size = 2; + line-color = colors.normal.underline; + padding = { + left = 0; + right = 0; + }; + module.margin = { left = 0; right = 0; }; + separator = " "; + border = { + color = colors.transparent; + left.size = 2; + righ.sizet = 2; + top.size = 2; + bottom.size = 0; + }; + font = [ "FuraCode Nerd Font Mono:pixelsize=10;2" "unifont:fontformat=truetype:size=8:antialias=false;0" "siji:pixelsize=10;1" ]; + tray = { + position = "right"; + padding = 0; + }; + wm-restack = "bspwm"; + }; +in +{ + home.packages = with pkgs; [ nerdfonts ]; + services.polybar = { + enable = true; + package = pkgs.polybarFull; + script = + '' + monitor=`polybar -m | ${grep} primary | ${cut} -d":" -f1` + MONITOR=$monitor polybar primary & + monitors=(`polybar -m | ${grep} -v primary | ${cut} -d":" -f1`) + for monitor in "''${monitors[@]}"; do + MONITOR=$monitor polybar secondary & + done + ''; + + settings = { + "settings" = { + screenchange-reload = false; + }; + + "bar/primary" = commonBar // { + modules-left = "bspwm"; + # modules-center = + modules-right = "player pulseaudio temperature cpu memory battery date powermenu"; + enable-ipc = true; + }; + + "bar/secondary" = commonBar // { + modules-left = "bspwm"; + # modules-center = + modules-right = "player pulseaudio temperature cpu memory battery date powermenu"; + enable-ipc = true; + }; + + "module/battery" = { + type = "internal/battery"; + + adapter = "AC"; + battery = "BAT0"; + full.at = 98; + + animation = { + charging = { + text = [ "" "" "" ]; + framerate = "750"; + }; + discharging = { + text = [ "" "" "" ]; + framerate = "750"; + }; + }; + + format = { + charging = colors.selected // { + text = " "; + }; + discharging = colors.active // { + text = " "; + }; + full = colors.normal // { + text = " "; + }; + }; + + label = { + chargin = "%percentage%%"; + dischargin = "%percentage%%"; + full = "%percentage%%"; + }; + }; + + "module/bspwm" = { + type = "internal/bspwm"; + format = ""; + + label = let + common = { + padding = 1; + separator = " "; + text = "%name%"; + }; + in + { + focused = colors.selected // common; + occupied = colors.active // common; + urgent = colors.active // common // { background = colors.alert; }; + empty = colors.normal // common; + }; + }; + + "module/cpu" = { + type = "internal/cpu"; + format = colors.normal // { + prefix = "▣ "; + padding = 1; + }; + interval = 2; + label = "%percentage-sum%%"; + }; + + "module/date" = { + type = "internal/date"; + date = { + alt = "%Y-%m-%d"; + text = "%a %d/%m/%y"; + }; + interval = "1"; + label = "%date% %time%"; + time = { + alt = "%H:%M:%S"; + text = "%H:%M"; + }; + format = colors.normal // { + padding = 1; + }; + }; + + "module/memory" = { + type = "internal/memory"; + format = colors.normal // { + prefix = "▨ "; + padding = 1; + }; + interval = 2; + label = "%percentage_used%% ~ %percentage_swap_used%%"; + }; + + "module/pulseaudio" = { + bar.volume = { + empty = { + font = "2"; + text = "─"; + }; + fill = { + text = "─"; + font = "2"; + }; + foreground = [ + colors.green + colors.green + colors.green + colors.green + colors.green + colors.yellow + colors.orange + colors.red + ]; + indicator = { + text = "|"; + font = "2"; + }; + width = "10"; + }; + click.right = "${pgrep} pavucontrol && ${pkill} pavucontrol || ${pavucontrol}"; + format = { + padding = 1; + muted = colors.active; + volume = colors.normal // { + text = " "; + }; + }; + label.muted = { + text = "VOL muted"; + }; + label.volume = { + text = "VOL %percentage%%"; + }; + type = "internal/pulseaudio"; + }; + + "module/temperature" = { + format = colors.normal // { + padding = 1; + text = "