Refactor support.nix to be lib

This commit is contained in:
Alexander Bantyev 2021-05-25 14:04:21 +03:00
parent 9dddf85b9f
commit 17d0254ade
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
14 changed files with 106 additions and 81 deletions

View File

@ -1,4 +1,4 @@
{ inputs, lib, config, ... }: { { inputs, lib, config, pkgs, ... }: {
imports = [ ./hardware-configuration.nix inputs.self.nixosProfiles.desktop ]; imports = [ ./hardware-configuration.nix inputs.self.nixosProfiles.desktop ];
deviceSpecific.devInfo = { deviceSpecific.devInfo = {
cpu = { cpu = {
@ -13,7 +13,7 @@
}; };
ram = 16; 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 = { default = {
"backlight backend" = "/sys/class/backlight/intel_backlight"; "backlight backend" = "/sys/class/backlight/intel_backlight";
"refresh interval" = 100; "refresh interval" = 100;

View File

@ -1,5 +1,5 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with import ../support.nix { inherit lib config; }; { {
options.defaultApplications = lib.mkOption { options.defaultApplications = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
description = "Preferred applications"; description = "Preferred applications";

View File

@ -67,6 +67,7 @@ in {
treemacs-projectile treemacs-projectile
dap-mode dap-mode
forge forge
crdt
]; ];
}; };

View File

@ -1,5 +1,4 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with import ../../support.nix { inherit lib config; };
let thm = config.themes.colors; let thm = config.themes.colors;
in { in {
environment.sessionVariables = { environment.sessionVariables = {

View File

@ -1,5 +1,5 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with import ../../support.nix { inherit lib config; }; let let
gearyConfig = { gearyConfig = {
Account = { Account = {
label = ""; label = "";
@ -67,7 +67,7 @@ in {
''; '';
home.activation.geary = '' home.activation.geary = ''
mkdir -p "$XDG_CONFIG_HOME/geary/account_03" 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"
''; '';
}; };
} }

View File

@ -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;
};
};
};
}

View File

@ -41,6 +41,5 @@
gnome3.simple-scan gnome3.simple-scan
shellcheck shellcheck
proselint proselint
inputs.himalaya.defaultPackage.x86_64-linux
]; ];
} }

View File

@ -10,6 +10,7 @@ builtins.listToAttrs (builtins.map (path: {
./applications/emacs ./applications/emacs
./applications/firefox.nix ./applications/firefox.nix
./applications/geary.nix ./applications/geary.nix
./applications/himalaya.nix
./applications/okular.nix ./applications/okular.nix
./applications/packages.nix ./applications/packages.nix
./applications/weechat.nix ./applications/weechat.nix

View File

@ -7,6 +7,21 @@ let
config = config.nixpkgs.config; config = config.nixpkgs.config;
localSystem = { inherit system; }; 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 { in {
nixpkgs.overlays = [ nixpkgs.overlays = [
(import inputs.emacs-overlay) (import inputs.emacs-overlay)
@ -15,6 +30,53 @@ in {
meta = super.nix.meta // { platforms = lib.platforms.unix; }; 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 { nur = (import inputs.NUR {
pkgs = old; pkgs = old;
nurpkgs = pkgs; nurpkgs = pkgs;
@ -32,14 +94,14 @@ in {
nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd; nerdfonts = nur.balsoft.pkgs.roboto-mono-nerd;
weechatScripts.wee-slack = super.weechatScripts.wee-slack.overrideAttrs (oa: { weechatScripts.wee-slack = super.weechatScripts.wee-slack.overrideAttrs
(oa: {
src = inputs.wee-slack; src = inputs.wee-slack;
patches = [ (builtins.elemAt oa.patches 0) ]; patches = [ (builtins.elemAt oa.patches 0) ];
}); });
nix-zsh-completions = super.nix-zsh-completions.overrideAttrs (_: { nix-zsh-completions = super.nix-zsh-completions.overrideAttrs
src = inputs.nix-zsh-completions; (_: { src = inputs.nix-zsh-completions; });
});
}) })
]; ];
nixpkgs.config = { nixpkgs.config = {

View File

@ -1,5 +1,4 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
with import ../../../support.nix { inherit pkgs config lib; };
with lib; with lib;
let scripts = import ./scripts pkgs config; let scripts = import ./scripts pkgs config;
in { in {
@ -54,7 +53,7 @@ in {
in '' in ''
interval=60 interval=60
markup=pango markup=pango
'' + genIniOrdered ([ (scr "email") ] '' + pkgs.my-lib.genIniOrdered ([ (scr "email") ]
++ [ (scrint "weather" 600) (scr "emacs") (scr "nixos") ] ++ [ (scrint "weather" 600) (scr "emacs") (scr "nixos") ]
++ [ (scrint "youtrack-wage" 3600) (scrint "music" 3) (scrint "sound" 1) ] ++ [ (scrint "youtrack-wage" 3600) (scrint "music" 3) (scrint "sound" 1) ]
++ [ ++ [

View File

@ -1,5 +1,6 @@
{ pkgs, lib, config, ... }: { pkgs, lib, config, ... }:
with import ../../../support.nix { inherit lib config; }; { with pkgs.my-lib;
{
xdg.portal.enable = true; xdg.portal.enable = true;
services.dbus.packages = services.dbus.packages =
[ pkgs.firefox pkgs.systemd pkgs.papirus-icon-theme ]; [ pkgs.firefox pkgs.systemd pkgs.papirus-icon-theme ];

View File

@ -7,7 +7,7 @@ let
Restart = "always"; Restart = "always";
}; };
}; };
inherit (import ../../support.nix { inherit lib config; }) genIni; inherit (pkgs.my-lib) genIni;
daemons = names: daemons = names:
builtins.listToAttrs (builtins.map (name: { builtins.listToAttrs (builtins.map (name: {
name = "simple-osd-${name}"; name = "simple-osd-${name}";

View File

@ -14,6 +14,7 @@
emacs emacs
firefox firefox
geary geary
himalaya
packages packages
weechat weechat
yt-utilities yt-utilities

View File

@ -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));
}