Refactor support.nix to be lib
This commit is contained in:
parent
9dddf85b9f
commit
17d0254ade
@ -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;
|
||||
|
@ -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";
|
||||
|
@ -67,6 +67,7 @@ in {
|
||||
treemacs-projectile
|
||||
dap-mode
|
||||
forge
|
||||
crdt
|
||||
];
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
with import ../../support.nix { inherit lib config; };
|
||||
let thm = config.themes.colors;
|
||||
in {
|
||||
environment.sessionVariables = {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
with import ../../support.nix { inherit lib config; }; let
|
||||
let
|
||||
gearyConfig = {
|
||||
Account = {
|
||||
label = "";
|
||||
@ -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"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
24
modules/applications/himalaya.nix
Normal file
24
modules/applications/himalaya.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
@ -41,6 +41,5 @@
|
||||
gnome3.simple-scan
|
||||
shellcheck
|
||||
proselint
|
||||
inputs.himalaya.defaultPackage.x86_64-linux
|
||||
];
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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: {
|
||||
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 = {
|
||||
|
@ -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) ]
|
||||
++ [
|
||||
|
@ -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 ];
|
||||
|
@ -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}";
|
||||
|
@ -14,6 +14,7 @@
|
||||
emacs
|
||||
firefox
|
||||
geary
|
||||
himalaya
|
||||
packages
|
||||
weechat
|
||||
yt-utilities
|
||||
|
62
support.nix
62
support.nix
@ -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));
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user