~ruther/nixos-config

56a89c495930fe5dea4870a10329f2b5d16b842b — Frantisek Bohacek a year ago a6a97b7
feat(home): use themes as option of the module system
M home/modules/default.nix => home/modules/default.nix +1 -0
@@ 3,5 3,6 @@
    ./home-config.nix
    ./profiles/default.nix
    ./programs/default.nix
    ./themes.nix
  ];
}

M home/modules/profiles/desktop/qtile/autorandr.nix => home/modules/profiles/desktop/qtile/autorandr.nix +1 -12
@@ 1,16 1,5 @@
{ inputs, config, lib, pkgs, ... }:
{ config, lib, pkgs, ... }:

let
  inherit (config.lib.formats.rasi) mkLiteral;        # Theme.rasi alternative. Add Theme here
  colors = import "${inputs.self}/themes/colors.nix";

  themes-collection = pkgs.fetchFromGitHub {
    owner = "newmanls";
    repo = "rofi-themes-collection";
    rev = "f87e08300cb1c984994efcaf7d8ae26f705226fd";
    hash = "sha256-A6zIAQvjfe/XB5GZefs4TWgD+eGICQP2Abz/sQynJPo=";
  };
in
{
  config = lib.mkIf config.profiles.desktop.qtile.enable {
    programs.autorandr = {

M home/modules/profiles/desktop/qtile/config/bars.py => home/modules/profiles/desktop/qtile/config/bars.py +25 -25
@@ 3,7 3,7 @@ import re
from libqtile import layout, bar, qtile
from qtile_extras.widget.decorations import BorderDecoration, PowerLineDecoration, RectDecoration
import qtile_extras.widget as widget
from styling import colors
from nixenvironment import nixConfig
from libqtile.widget import Mpris2, Bluetooth
from tasklist import TaskList



@@ 15,13 15,13 @@ def create_top_bar(systray = False):
    }

    widgets = [
        widget.Sep(padding = 5, size_percent = 0, background = colors['background_secondary']),
        widget.Sep(padding = 5, size_percent = 0, background = nixConfig.theme.background.secondary,
        widget.CurrentScreen(
            active_text = 'I',
            active_color = colors['active'],
            active_color = nixConfig.theme.foreground.active,
            padding = 3,
            fontsize = 16,
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
        ),
        widget.GroupBox(
            markup = False,


@@ 30,22 30,22 @@ def create_top_bar(systray = False):
            margin_x = 2,
            disable_drag = True,
            use_mouse_wheel = True,
            active = colors['white'],
            inactive = colors['grey'],
            active = nixConfig.theme.foreground.activeAlt,
            inactive = nixConfig.theme.foreground.inactive,
            urgent_alert_method = 'line',
            urgent_border = colors['urgent'],
            this_current_screen_border = colors['active'],
            this_screen_border = colors['secondary'],
            other_screen_border = colors['inactive'],
            urgent_border = nixConfig.theme.urgent,
            this_current_screen_border = nixConfig.theme.foreground.active,
            this_screen_border = nixConfig.theme.foreground.secondary,
            other_screen_border = nixConfig.theme.background.inactive,
            other_current_screen_border = '6989c0',
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
        ),
        widget.CurrentScreen(
            active_text = 'I',
            active_color = colors['active'],
            active_color = nixConfig.theme.foreground.active,
            padding = 3,
            fontsize = 16,
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
            decorations = [
                PowerLineDecoration(path = 'forward_slash'),
            ],


@@ 57,14 57,14 @@ def create_top_bar(systray = False):
        ),
        widget.Prompt(),
        widget.WindowName(
            foreground = colors['primary'],
            foreground = nixConfig.theme.foreground.primary,
            width = bar.CALCULATED,
            padding = 10,
            empty_group_string = 'Desktop',
            max_chars = 160,
            decorations = [
                RectDecoration(
                    colour = colors['black'],
                    colour = nixConfig.theme.background.box,
                    radius = 0,
                    padding_y = 4,
                    padding_x = 0,


@@ 78,7 78,7 @@ def create_top_bar(systray = False):
            padding = 15,
            decorations = [
                RectDecoration(
                    colour = colors['black'],
                    colour = nixConfig.theme.background.box,
                    radius = 0,
                    padding_y = 4,
                    padding_x = 6,


@@ 91,7 91,7 @@ def create_top_bar(systray = False):
        #     interface = 'enp24s0',
        #     prefix='M',
        #     format = '{down:6.2f} {down_suffix:<2}↓↑{up:6.2f} {up_suffix:<2}',
        #     background = colors['background_secondary'],
        #     background = nixConfig.theme.background.secondary,
        #     **powerline,
        # ),
        widget.Memory(


@@ 102,7 102,7 @@ def create_top_bar(systray = False):
        widget.CPU(
            format = '{load_percent} %',
            fmt = '   {}',
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
            **powerline,
        ),
        widget.DF(


@@ 122,16 122,16 @@ def create_top_bar(systray = False):
        ),
        widget.Clock(
            timezone='Europe/Prague',
            foreground = colors['primary'],
            foreground = nixConfig.theme.foreground.primary,
            format='%A, %B %d - %H:%M:%S',
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
            **powerline
        ),
        widget.Volume(
            fmt = '🕫  {}',
        ),
        widget.Sep(
            foreground = colors['background_secondary'],
            foreground = nixConfig.theme.background.secondary,
            size_percent = 70,
            linewidth = 3,
        ),


@@ 149,7 149,7 @@ def create_top_bar(systray = False):

    if systray:
        widgets.append(widget.Sep(
            foreground = colors['background_secondary'],
            foreground = nixConfig.theme.background.secondary,
            size_percent = 70,
            linewidth = 2,
        ))


@@ 184,7 184,7 @@ def create_bottom_bar():
            padding = 10,
            decorations = [
                RectDecoration(
                    colour = colors['black'],
                    colour = nixConfig.theme.background.box,
                    radius = 0,
                    padding_y = 4,
                    padding_x = 5,


@@ 202,7 202,7 @@ def create_bottom_bar():
            padding = 10,
            decorations = [
                RectDecoration(
                    colour = colors['black'],
                    colour = nixConfig.theme.background.box,
                    radius = 0,
                    padding_y = 4,
                    padding_x = 5,


@@ 219,7 219,7 @@ def create_bottom_bar():
        widget.Wttr(
            location = {'Odolena_Voda': ''},
            format = '%t %c',
            background = colors['background_secondary'],
            background = nixConfig.theme.background.secondary,
            **powerline,
        ),
    ], 30)

M home/modules/profiles/desktop/qtile/config/config.py => home/modules/profiles/desktop/qtile/config/config.py +4 -5
@@ 16,7 16,6 @@ from nixenvironment import nixConfig
import functions
import utils
from screens import init_screens, observe_monitors, init_navigation_keys
from styling import colors
import time

# #####################################


@@ 25,8 24,8 @@ mod = 'mod4'
terminal = nixConfig.defaults.terminal

layout_theme = {
    'border_focus': colors['active'],
    'border_normal': colors['inactive'],
    'border_focus': nixConfig.theme.foreground.active,
    'border_normal': nixConfig.theme.background.inactive,
    'border_width': 1,
    'margin': 3,
}


@@ 41,8 40,8 @@ widget_defaults = dict(
    font = 'Roboto Bold',
    fontsize = 13,
    padding = 3,
    background = colors['background_primary'],
    foreground = colors['white'],
    background = nixConfig.theme.background.primary,
    foreground = nixConfig.theme.foreground.activeAlt,
)
extension_defaults = widget_defaults.copy()


D home/modules/profiles/desktop/qtile/config/styling.py => home/modules/profiles/desktop/qtile/config/styling.py +0 -12
@@ 1,12 0,0 @@
colors = {
    'primary': '51afef',
    'active': '8babf0',
    'inactive': '555e60',
    'secondary': '55eddc',
    'background_primary': '222223',
    'background_secondary': '444444',
    'urgent': 'c45500',
    'white': 'd5d5d5',
    'grey': '737373',
    'black': '121212',
}

M home/modules/profiles/desktop/qtile/default.nix => home/modules/profiles/desktop/qtile/default.nix +1 -1
@@ 3,6 3,7 @@
let
  configFormat = pkgs.formats.json {};
  configJson = configFormat.generate "qtile-config.json" {
    theme = config.themes.default;
    scripts = {
      brightness = ./config/brightness.sh;
      notifications = {


@@ 68,7 69,6 @@ in {
    xdg.configFile."qtile/functions.py".source = ./config/functions.py;
    xdg.configFile."qtile/bars.py".source = ./config/bars.py;
    xdg.configFile."qtile/screens.py".source = ./config/screens.py;
    xdg.configFile."qtile/styling.py".source = ./config/styling.py;

    xdg.configFile."qtile/tasklist.py".source = ./config/tasklist.py;
    xdg.configFile."qtile/xmonadcustom.py".source = ./config/xmonadcustom.py;

M home/modules/profiles/desktop/qtile/launcher.nix => home/modules/profiles/desktop/qtile/launcher.nix +10 -9
@@ 1,8 1,7 @@
{ inputs,  config, lib, pkgs, ... }:
{ config, lib, pkgs, ... }:

let
  inherit (config.lib.formats.rasi) mkLiteral;        # Theme.rasi alternative. Add Theme here
  colors = import "${inputs.self}/themes/colors.nix";

  themes-collection = pkgs.fetchFromGitHub {
    owner = "newmanls";


@@ 26,17 25,17 @@ in
        terminal = "${config.home-config.defaultTerminalExe}";
        location = "center";
        font = "${config.home-config.defaultFont} 11";
        theme =  with colors.scheme.doom; {
        theme = with config.themes.default; {
          # Based on spotlight theme
          "*" = {
            font =  "Montserrat 12";

            bg0 = mkLiteral "#222223e6";
            bg1 = mkLiteral "#44444480";
            bg2 = mkLiteral "#51afefe6";
            fg0 = mkLiteral "#${text}";
            fg1 = mkLiteral "#d5d5d5";
            fg2 = mkLiteral "#${fg}";
            bg0 = mkLiteral "#${background.primary}e6";
            bg1 = mkLiteral "#${background.secondary}80";
            bg2 = mkLiteral "#${background.active}e6";
            fg0 = mkLiteral "#${foreground.text}";
            fg1 = mkLiteral "#${foreground.activeAlt}";
            fg2 = mkLiteral "#${foreground.inactive}";

            background-color = mkLiteral "transparent";
            text-color = mkLiteral "@fg0";


@@ 48,6 47,8 @@ in

          "window" = {
            background-color = mkLiteral "@bg0";
            border = mkLiteral "2px 0 0";
            border-color = mkLiteral "@bg2";

            location = mkLiteral "center";
            width = mkLiteral "640";

M home/modules/profiles/desktop/qtile/services.nix => home/modules/profiles/desktop/qtile/services.nix +11 -11
@@ 1,7 1,6 @@
{ inputs, config, lib, pkgs, ... }:

let
  colors = import "${inputs.self}/themes/colors.nix";
  mpris-ctl = inputs.self.packages.${pkgs.system}.mpris-ctl;
  sequence-detector = inputs.self.packages.${pkgs.system}.sequence-detector;
in {


@@ 26,7 25,7 @@ in {
          package = pkgs.papirus-icon-theme;
          size = "16x16";
        };
        settings = with colors.scheme.doom; {               # Settings
        settings = with config.themes.default; {               # Settings
          global = {
            monitor = 0;
            follow = "keyboard";


@@ 39,9 38,10 @@ in {
            shrink = "yes";
            transparency = 10;
            padding = 16;
            gap_size = 5;
            horizontal_padding = 16;
            frame_width = 3;
            frame_color = "#${bg}";
            frame_width = 2;
            frame_color = "#${background.active}";
            separator_color = "frame";
            font = "FiraCode Nerd Font 10";
            line_height = 4;


@@ 60,19 60,19 @@ in {
            hide_duplicate_count = true;
          };
          urgency_low = {                                   # Colors
            background = "#${bg}";
            foreground = "#${text}";
            background = "#${background.primary}";
            foreground = "#${foreground.text}";
            timeout = 4;
          };
          urgency_normal = {
            background = "#${bg}";
            foreground = "#${text}";
            background = "#${background.primary}";
            foreground = "#${foreground.text}";
            timeout = 4;
          };
          urgency_critical = {
            background = "#${bg}";
            foreground = "#${text}";
            frame_color = "#${red}";
            background = "#${background.primary}";
            foreground = "#${foreground.text}";
            frame_color = "#${urgent}";
            timeout = 10;
          };
        };

A home/modules/themes.nix => home/modules/themes.nix +57 -0
@@ 0,0 1,57 @@
{ lib, ... }:

let
  mkColorOption = description: lib.mkOption {
    inherit description;
    type = lib.types.str;
  };
in {
  options = {
    themes = lib.mkOption {
      type = lib.types.attrsOf (lib.types.submodule ({config, ...}: {
        options = {
          foreground = {
            primary = mkColorOption "Primary color for foreground (text)";
            secondary = mkColorOption "Secondary color for foreground (text)";
            text = mkColorOption "Basic text color for stuff that's not primary, secondary etc.";

            active = mkColorOption "Color for foreground (text) when element is active";
            activeAlt = mkColorOption "Color for foreground when element is active, and `active` color is used as background instead";

            inactive = mkColorOption "Color for foreground (text) when element is inactive";
          };
          background = {
            primary = mkColorOption "Primary color for background";
            secondary = mkColorOption "Primary color for background";
            box = mkColorOption "Color for box elements";
            inactive = mkColorOption "Color for foreground (text) when element is inactive";
            active = mkColorOption "Color for background when element is active. When this is in use, use `foreground.activeAlt` for text.";
          };

          urgent = mkColorOption "Urgent windows";
        };
      }));
    };
  };

  config = {
    themes.default = {
      foreground = {
        primary = "51afef";
        secondary = "55eddc";
        activeAlt = "d5d5d5";
        text = "cccccc";
        active = "8babf0";
        inactive = "737373";
      };
      background = {
        primary = "222223";
        secondary = "444444";
        active = "8babf0";
        inactive = "555e60";
        box = "121212";
      };
      urgent = "c45500";
    };
  };
}

A scratch => scratch +2 -0
@@ 0,0 1,2 @@
themes to proper options
defaultTerminal and editor to session variables

D themes/colors.nix => themes/colors.nix +0 -48
@@ 1,48 0,0 @@
#
# System themes
#

{
  scheme = {
    doom = {
      scheme    = "Doom One Dark";
      black     = "000000";
      red       = "ff6c6b";
      orange    = "da8548";
      yellow    = "ecbe7b";
      green     = "95be65";
      teal      = "4db5bd";
      blue      = "6eaafb";
      dark-blue = "2257a0";
      magenta   = "c678dd";
      violet    = "a9a1e1";
      cyan      = "6cdcf7";
      dark-cyan = "5699af";
      emphasis  = "50536b";
      text      = "dfdfdf";
      text-alt  = "b2b2b2";
      fg        = "abb2bf";
      bg        = "282c34";
    };

    dracula = {
      scheme = "Dracula";
      base00 = "282936"; #background
      base01 = "3a3c4e";
      base02 = "4d4f68";
      base03 = "626483";
      base04 = "62d6e8";
      base05 = "e9e9f4"; #foreground
      base06 = "f1f2f8";
      base07 = "f7f7fb";
      base08 = "ea51b2";
      base09 = "b45bcf";
      base0A = "00f769";
      base0B = "ebff87";
      base0C = "a1efe4";
      base0D = "62d6e8";
      base0E = "b45bcf";
      base0F = "00f769";
    };
  };
}

Do not follow this link