From 17d0254adef19f7db4941181a815e2f772017569 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Tue, 25 May 2021 14:04:21 +0300 Subject: [PATCH] Refactor support.nix to be lib --- machines/X2100-Laptop/default.nix | 4 +- modules/applications.nix | 2 +- modules/applications/emacs/default.nix | 1 + modules/applications/firefox.nix | 1 - modules/applications/geary.nix | 6 +- modules/applications/himalaya.nix | 24 ++++++++ modules/applications/packages.nix | 1 - modules/default.nix | 1 + modules/overlay.nix | 76 +++++++++++++++++++++--- modules/workspace/i3blocks/default.nix | 3 +- modules/workspace/kde/default.nix | 3 +- modules/workspace/simple-osd-daemons.nix | 2 +- profiles/desktop.nix | 1 + support.nix | 62 ------------------- 14 files changed, 106 insertions(+), 81 deletions(-) create mode 100644 modules/applications/himalaya.nix delete mode 100755 support.nix diff --git a/machines/X2100-Laptop/default.nix b/machines/X2100-Laptop/default.nix index 651fdf1..d1418c5 100644 --- a/machines/X2100-Laptop/default.nix +++ b/machines/X2100-Laptop/default.nix @@ -1,4 +1,4 @@ -{ inputs, lib, config, ... }: { +{ inputs, lib, config, pkgs, ... }: { imports = [ ./hardware-configuration.nix inputs.self.nixosProfiles.desktop ]; deviceSpecific.devInfo = { cpu = { @@ -13,7 +13,7 @@ }; ram = 16; }; - home-manager.users.balsoft.xdg.configFile."simple-osd/brightness".text = (import ../../support.nix { inherit lib config; }).genIni { + home-manager.users.balsoft.xdg.configFile."simple-osd/brightness".text = pkgs.my-lib.genIni { default = { "backlight backend" = "/sys/class/backlight/intel_backlight"; "refresh interval" = 100; diff --git a/modules/applications.nix b/modules/applications.nix index 63f246e..85142d9 100755 --- a/modules/applications.nix +++ b/modules/applications.nix @@ -1,5 +1,5 @@ { pkgs, config, lib, ... }: -with import ../support.nix { inherit lib config; }; { +{ options.defaultApplications = lib.mkOption { type = lib.types.attrs; description = "Preferred applications"; diff --git a/modules/applications/emacs/default.nix b/modules/applications/emacs/default.nix index 78119b0..ae9c36b 100644 --- a/modules/applications/emacs/default.nix +++ b/modules/applications/emacs/default.nix @@ -67,6 +67,7 @@ in { treemacs-projectile dap-mode forge + crdt ]; }; diff --git a/modules/applications/firefox.nix b/modules/applications/firefox.nix index 07bd0e5..5ab36ef 100644 --- a/modules/applications/firefox.nix +++ b/modules/applications/firefox.nix @@ -1,5 +1,4 @@ { config, pkgs, lib, ... }: -with import ../../support.nix { inherit lib config; }; let thm = config.themes.colors; in { environment.sessionVariables = { diff --git a/modules/applications/geary.nix b/modules/applications/geary.nix index cc7d30b..9808b2c 100644 --- a/modules/applications/geary.nix +++ b/modules/applications/geary.nix @@ -1,5 +1,5 @@ { config, pkgs, lib, ... }: -with import ../../support.nix { inherit lib config; }; let +let gearyConfig = { Account = { label = ""; @@ -57,7 +57,7 @@ in { home-manager.users.balsoft = { xdg.configFile."geary/user-style.css".text = '' *, html, body, body.plain div, body.plain a, body.plain p, body.plain span { - background: ${config.themes.colors .bg} !important; + background: ${config.themes.colors.bg} !important; color: ${config.themes.colors.fg} !important; font-family: 'IBM Plex Mono', monospace !important; } @@ -67,7 +67,7 @@ in { ''; home.activation.geary = '' mkdir -p "$XDG_CONFIG_HOME/geary/account_03" - $DRY_RUN_CMD ln -sf $VERBOSE_ARG ${builtins.toFile "geary.ini" (genIni gearyConfig)} "$XDG_CONFIG_HOME/geary/account_03/geary.ini" + $DRY_RUN_CMD ln -sf $VERBOSE_ARG ${builtins.toFile "geary.ini" (pkgs.my-lib.genIni gearyConfig)} "$XDG_CONFIG_HOME/geary/account_03/geary.ini" ''; }; } diff --git a/modules/applications/himalaya.nix b/modules/applications/himalaya.nix new file mode 100644 index 0000000..6ac8490 --- /dev/null +++ b/modules/applications/himalaya.nix @@ -0,0 +1,24 @@ +{ config, pkgs, inputs, lib, ... }: { + environment.systemPackages = [ inputs.himalaya.defaultPackage.x86_64-linux ]; + home-manager.users.balsoft = { + xdg.configFile."himalaya/config.toml".text = pkgs.my-lib.genIni { + default = { + name = "Alexander Bantyev"; + signature = "Regards,"; + downloads-dir = "'/home/balsoft/Downloads/mail'"; + }; + maiol = { + default = true; + email = "balsoft@balsoft.ru"; + imap-host = "balsoft.ru"; + imap-login = "balsoft@balsoft.ru"; + imap-passwd-cmd = "cat ${config.secrets.email.decrypted}"; + imap-port = 993; + smtp-host = "balsoft.ru"; + smtp-login = "balsoft@balsoft.ru"; + smtp-passwd-cmd = "cat ${config.secrets.email.decrypted}"; + smtp-port = 465; + }; + }; + }; +} diff --git a/modules/applications/packages.nix b/modules/applications/packages.nix index bbfdd00..39a9615 100644 --- a/modules/applications/packages.nix +++ b/modules/applications/packages.nix @@ -41,6 +41,5 @@ gnome3.simple-scan shellcheck proselint - inputs.himalaya.defaultPackage.x86_64-linux ]; } diff --git a/modules/default.nix b/modules/default.nix index b2fb57c..792bedd 100755 --- a/modules/default.nix +++ b/modules/default.nix @@ -10,6 +10,7 @@ builtins.listToAttrs (builtins.map (path: { ./applications/emacs ./applications/firefox.nix ./applications/geary.nix + ./applications/himalaya.nix ./applications/okular.nix ./applications/packages.nix ./applications/weechat.nix diff --git a/modules/overlay.nix b/modules/overlay.nix index f89af32..77093a3 100644 --- a/modules/overlay.nix +++ b/modules/overlay.nix @@ -7,6 +7,21 @@ let config = config.nixpkgs.config; localSystem = { inherit system; }; }); + mkKeyValue = key: value: + let + mvalue = if builtins.isBool value then + (if value then "true" else "false") + else if (builtins.isString value && key != "include-file") then + value + else + builtins.toString value; + in "${key}=${mvalue}"; + attrsToList = with builtins; + x: + (map (key: { + name = key; + value = getAttr key x; + }) (attrNames x)); in { nixpkgs.overlays = [ (import inputs.emacs-overlay) @@ -15,6 +30,53 @@ in { meta = super.nix.meta // { platforms = lib.platforms.unix; }; }; + my-lib = rec { + genIni = lib.generators.toINI { inherit mkKeyValue; }; + genIniOrdered = lst: + (builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs: + builtins.concatStringsSep "\n" ([ "[${name}]" ] + ++ (map ({ name, value }: mkKeyValue name value) + (attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst)) + + "\n"; + thm = config.themes.colors; + splitHex = hexStr: + map (x: builtins.elemAt x 0) (builtins.filter (a: a != "" && a != [ ]) + (builtins.split "(.{2})" (builtins.substring 1 6 hexStr))); + hex2decDigits = rec { + "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; + A = a; + B = b; + C = c; + D = d; + E = e; + F = f; + }; + + doubleDigitHexToDec = hex: + 16 * hex2decDigits."${builtins.substring 0 1 hex}" + + hex2decDigits."${builtins.substring 1 2 hex}"; + thmDec = builtins.mapAttrs (name: color: colorHex2Dec color) thm; + colorHex2Dec = color: + builtins.concatStringsSep "," + (map (x: toString (doubleDigitHexToDec x)) (splitHex color)); + + }; + nur = (import inputs.NUR { pkgs = old; nurpkgs = pkgs; @@ -32,14 +94,14 @@ in { nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd; - weechatScripts.wee-slack = super.weechatScripts.wee-slack.overrideAttrs (oa: { - src = inputs.wee-slack; - patches = [(builtins.elemAt oa.patches 0)]; - }); + weechatScripts.wee-slack = super.weechatScripts.wee-slack.overrideAttrs + (oa: { + src = inputs.wee-slack; + patches = [ (builtins.elemAt oa.patches 0) ]; + }); - nix-zsh-completions = super.nix-zsh-completions.overrideAttrs (_: { - src = inputs.nix-zsh-completions; - }); + nix-zsh-completions = super.nix-zsh-completions.overrideAttrs + (_: { src = inputs.nix-zsh-completions; }); }) ]; nixpkgs.config = { diff --git a/modules/workspace/i3blocks/default.nix b/modules/workspace/i3blocks/default.nix index 20516e2..4cefa16 100644 --- a/modules/workspace/i3blocks/default.nix +++ b/modules/workspace/i3blocks/default.nix @@ -1,5 +1,4 @@ { pkgs, config, lib, ... }: -with import ../../../support.nix { inherit pkgs config lib; }; with lib; let scripts = import ./scripts pkgs config; in { @@ -54,7 +53,7 @@ in { in '' interval=60 markup=pango - '' + genIniOrdered ([ (scr "email") ] + '' + pkgs.my-lib.genIniOrdered ([ (scr "email") ] ++ [ (scrint "weather" 600) (scr "emacs") (scr "nixos") ] ++ [ (scrint "youtrack-wage" 3600) (scrint "music" 3) (scrint "sound" 1) ] ++ [ diff --git a/modules/workspace/kde/default.nix b/modules/workspace/kde/default.nix index 1cf0060..63dbe88 100644 --- a/modules/workspace/kde/default.nix +++ b/modules/workspace/kde/default.nix @@ -1,5 +1,6 @@ { pkgs, lib, config, ... }: -with import ../../../support.nix { inherit lib config; }; { +with pkgs.my-lib; +{ xdg.portal.enable = true; services.dbus.packages = [ pkgs.firefox pkgs.systemd pkgs.papirus-icon-theme ]; diff --git a/modules/workspace/simple-osd-daemons.nix b/modules/workspace/simple-osd-daemons.nix index fe60013..3b1e567 100644 --- a/modules/workspace/simple-osd-daemons.nix +++ b/modules/workspace/simple-osd-daemons.nix @@ -7,7 +7,7 @@ let Restart = "always"; }; }; - inherit (import ../../support.nix { inherit lib config; }) genIni; + inherit (pkgs.my-lib) genIni; daemons = names: builtins.listToAttrs (builtins.map (name: { name = "simple-osd-${name}"; diff --git a/profiles/desktop.nix b/profiles/desktop.nix index c8d2aec..649743c 100644 --- a/profiles/desktop.nix +++ b/profiles/desktop.nix @@ -14,6 +14,7 @@ emacs firefox geary + himalaya packages weechat yt-utilities diff --git a/support.nix b/support.nix deleted file mode 100755 index e9a3d72..0000000 --- a/support.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ lib, config, ... }: -let - mkKeyValue = key: value: - let - mvalue = if builtins.isBool value then - (if value then "true" else "false") - else if (builtins.isString value && key != "include-file") then - value - else - builtins.toString value; - in "${key}=${mvalue}"; - attrsToList = with builtins; - x: - (map (key: { - name = key; - value = getAttr key x; - }) (attrNames x)); -in rec { - genIni = lib.generators.toINI { inherit mkKeyValue; }; - genIniOrdered = lst: - (builtins.concatStringsSep "\n" (map ({ name ? "widget", ... }@attrs: - builtins.concatStringsSep "\n" ([ "[${name}]" ] - ++ (map ({ name, value }: mkKeyValue name value) - (attrsToList (builtins.removeAttrs attrs [ "name" ]))))) lst)) + "\n"; - thm = config.themes.colors; - splitHex = hexStr: - map (x: builtins.elemAt x 0) (builtins.filter (a: a != "" && a != [ ]) - (builtins.split "(.{2})" (builtins.substring 1 6 hexStr))); - hex2decDigits = rec { - "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; - A = a; - B = b; - C = c; - D = d; - E = e; - F = f; - }; - - doubleDigitHexToDec = hex: - 16 * hex2decDigits."${builtins.substring 0 1 hex}" - + hex2decDigits."${builtins.substring 1 2 hex}"; - thmDec = builtins.mapAttrs (name: color: colorHex2Dec color) thm; - colorHex2Dec = color: - builtins.concatStringsSep "," - (map (x: toString (doubleDigitHexToDec x)) (splitHex color)); - -}