Settin : Use module instead of raw nix.

This commit is contained in:
Dmitry Voronin 2024-06-24 13:36:10 +03:00
parent c88f4c2e3f
commit 03500126f8
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
31 changed files with 180 additions and 87 deletions

View file

@ -4,7 +4,6 @@
, style
, util
, key
, setting
, secret
, ... } @args: let
# Path where Termux stores user data.

View file

@ -148,7 +148,10 @@
);
in {
# Here I import everything from those directories.
imports = (lsFiles ./module/common) ++ (lsFiles ./overlay) ++ [ ./user/Root.nix ];
imports = (lsFiles ./module/common) ++ (lsFiles ./overlay) ++ [
./part/Setting.nix
./user/Root.nix
];
};
# Function to create a host. It does basic setup, like adding common modules.
@ -194,7 +197,6 @@
flake = self; # This Flake itself.
inputs = inputs; # Our dependencies.
secret = import ./part/Secret.nix {}; # Secrets (public keys).
setting = import ./part/Setting.nix {}; # My own global settings.
style = import ./part/Style.nix { inherit config; }; # Style abstraction.
util = import ./part/Util.nix { inherit pkgs lib; }; # Util functions.
wallpaper = import ./part/Wallpaper.nix { inherit pkgs; }; # Wallpaper.
@ -347,6 +349,9 @@
# I put all my Android configuration there.
./android
# Common settings.
./part/Setting.nix
];
# SpecialArgs allows you to pass objects down to other configuration.
@ -359,7 +364,6 @@
flake = self; # This Flake itself.
inputs = inputs; # Our dependencies.
secret = import ./part/Secret.nix {}; # Secrets (public keys).
setting = import ./part/Setting.nix {}; # My own global settings.
style = import ./part/Style.nix { config = import ./part/style/Gruvbox.nix {}; }; # Style abstraction. Stylix is not available for Android so I provide static Gruvbox style.
util = import ./part/Util.nix { inherit pkgs lib; }; # Util functions.
};

View file

@ -1,5 +1,5 @@
# https://github.com/ollama/ollama
{ pkgsStable, lib, setting, ... }: let
{ pkgsStable, lib, config, ... }: let
pkgs = pkgsStable;
in {
environment = {
@ -7,7 +7,7 @@ in {
systemPackages = with pkgs; [ ollama ];
# Specify default model.
variables.OLLAMA_MODEL = setting.ollama.primaryModel;
variables.OLLAMA_MODEL = config.setting.ollama.primaryModel;
};
# Enable Ollama server.
@ -31,7 +31,7 @@ in {
serviceConfig.Type = "simple";
script = ''
sleep 5
${lib.getExe pkgs.ollama} pull ${setting.ollama.primaryModel}
${lib.getExe pkgs.ollama} pull ${config.setting.ollama.primaryModel}
'';
};
}

View file

@ -1,4 +1,4 @@
{ pkgs, setting, ... }: {
{ pkgs, config, ... }: {
environment.systemPackages = with pkgs; [ keyd ];
services.keyd = {
@ -10,7 +10,7 @@
backspace = "delete"; # Delete key on backspace.
capslock = "overload(control, esc)"; # Ctrl/esc combo.
compose = "layer(layer_number)"; # Number input layer.
esc = "${setting.sysctrl}"; # System controls.
esc = "${config.setting.sysctrl}"; # System controls.
leftcontrol = "overload(layer_alternative, leftcontrol)"; # Alternative layer for home, end etc.
rightcontrol = "layer(layer_control)"; # Media and other controls.
rightshift = "backspace"; # Backspace.

View file

@ -1,4 +1,4 @@
{ inputs, pkgs, util, key, setting, ... } @args: let
{ inputs, pkgs, util, key, config, ... } @args: let
nvim = import ./nvim args;
in {
environment = {

View file

@ -1,7 +1,7 @@
{ setting, ... }: {
{ config, ... }: {
text = ''
require("ollama").setup {
model = "${setting.ollama.primaryModel}",
model = "${config.setting.ollama.primaryModel}",
url = "http://127.0.0.1:11434",
-- View the actual default prompts in ./lua/ollama/prompts.lua
prompts = {

View file

@ -1,3 +1,3 @@
{ style, key, util, setting, ... } @args: {
{ style, key, util, config, ... } @args: {
config = util.catText (util.ls ./module) args;
}

View file

@ -1,4 +1,4 @@
{ pkgs, pkgsStable, pkgsMaster, setting, ... } @args: let
{ pkgs, pkgsStable, pkgsMaster, config, ... } @args: let
mangohud = import ./mangohud args;
in {
imports = [
@ -69,7 +69,7 @@ in {
# Terminal settings.
TERM = "xterm-256color";
TERMINAL = setting.terminal.bin;
TERMINAL = config.setting.terminal.bin;
};
};

View file

@ -1,7 +1,7 @@
{ setting, ... }: {
{ config, ... }: {
services.xserver.enable = true;
services.xserver.xkb = {
layout = setting.keyboard.layouts;
options = setting.keyboard.options;
layout = config.setting.keyboard.layouts;
options = config.setting.keyboard.options;
};
}

View file

@ -1,11 +1,11 @@
{ lib, setting, ... }: {
{ lib, config, ... }: {
"org/gnome/desktop/input-sources" = with lib.gvariant; {
current = mkUint32 0;
mru-sources = [ (mkTuple [ "xkb" "us" ]) (mkTuple [ "xkb" "ru" ]) ];
per-window = false;
show-all-sources = true;
sources = [ (mkTuple [ "xkb" "us" ]) (mkTuple [ "xkb" "ru" ]) ];
xkb-options = [ setting.keyboard.options ];
xkb-options = [ config.setting.keyboard.options ];
};
"org/gnome/desktop/peripherals/mouse" = {

View file

@ -1,4 +1,4 @@
{ setting, ... }: let
{ config, ... }: let
mod = "<Super>";
in {
"org/gnome/desktop/wm/keybindings" = {
@ -82,31 +82,31 @@ in {
};
"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1" = {
binding = "${setting.sysctrl}z";
binding = "${config.setting.sysctrl}z";
command = "systemctl suspend -i";
name = "System Sleep";
};
"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2" = {
binding = "${setting.sysctrl}x";
binding = "${config.setting.sysctrl}x";
command = "systemctl poweroff -i";
name = "System Poweroff";
};
"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3" = {
binding = "${setting.sysctrl}c";
binding = "${config.setting.sysctrl}c";
command = "systemctl reboot -i";
name = "System Reboot";
};
"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4" = {
binding = "${setting.sysctrl}p";
binding = "${config.setting.sysctrl}p";
command = "powersave toggle";
name = "Toggle Powersave";
};
"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5" = {
binding = "${setting.sysctrl}l";
binding = "${config.setting.sysctrl}l";
command = "powerlimit toggle";
name = "Toggle Powerlimit";
};

View file

@ -1,4 +1,4 @@
{ pkgs, wallpaper, style, util, setting, ... } @args: let
{ pkgs, wallpaper, style, util, config, ... } @args: let
# Order is required for Sway configuration.
swayRc = util.catText [
./module/Style.nix

View file

@ -1,5 +1,5 @@
{ setting, ... }: let
step = setting.step.brightness;
{ config, ... }: let
step = config.setting.step.brightness;
in {
text = ''
bindsym XF86MonBrightnessDown exec light -U ${toString step}

View file

@ -1,4 +1,4 @@
{ setting, ... }: {
{ config, ... }: {
text = ''
### Input configuration
#
@ -33,11 +33,11 @@
}
input type:keyboard {
xkb_layout ${setting.keyboard.layouts}
xkb_options ${setting.keyboard.options}
xkb_layout ${config.setting.keyboard.layouts}
xkb_options ${config.setting.keyboard.options}
}
# Hide mouse cursor after a period of inactivity.
seat seat0 hide_cursor ${toString setting.timeout.popup}
seat seat0 hide_cursor ${toString config.setting.timeout.popup}
'';
}

View file

@ -1,6 +1,6 @@
{ setting, ... }: let
step_volume = setting.step.volume;
step_music = setting.step.media;
{ config, ... }: let
step_volume = config.setting.step.volume;
step_music = config.setting.step.media;
in {
text = ''
bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +${toString step_volume}%'

View file

@ -1,5 +1,5 @@
{ setting, ... }: let
mod = setting.sysctrl;
{ config, ... }: let
mod = config.setting.sysctrl;
in {
text = ''
bindsym ${mod}+c exec 'systemctl reboot -i'

View file

@ -1,6 +1,6 @@
{ setting, ... }: {
{ config, ... }: {
text = ''
set $term ${setting.terminal.bin}
set $term ${config.setting.terminal.bin}
bindsym $mod+Escape exec $term -e bash -c "tmux new-session -A -s $USER; bash"
'';

View file

@ -1,4 +1,4 @@
{ setting, style, pkgs, ... }: let
{ config, style, pkgs, ... }: let
refreshInterval = 2;
in {
file = (pkgs.formats.json {}).generate "WaybarConfig" {
@ -73,7 +73,7 @@ in {
on-click-right = "powerlimit toggle";
};
pulseaudio = {
scroll-step = setting.step.volume;
scroll-step = config.setting.step.volume;
format = "{volume}% {icon}";
format-muted = "󰸈";
format-icons = {
@ -100,26 +100,26 @@ in {
cpu = {
format = "{usage}% ({load})";
interval = refreshInterval;
on-click = "${setting.terminal.bin} -e bash -c btop";
on-click = "${config.setting.terminal.bin} -e bash -c btop";
on-click-right = "powersave toggle";
tooltip = false;
};
memory = {
format = "{percentage}%";
interval = refreshInterval;
on-click = "${setting.terminal.bin} -e bash -c btop";
on-click = "${config.setting.terminal.bin} -e bash -c btop";
on-click-right = "powersave toggle";
};
temperature = {
format = "{temperatureC}°C";
interval = refreshInterval;
on-click = "${setting.terminal.bin} -e bash -c btop";
on-click = "${config.setting.terminal.bin} -e bash -c btop";
on-click-right = "powersave toggle";
};
"custom/powersave" = {
exec = "powersave waybar";
interval = refreshInterval;
on-click = "${setting.terminal.bin} -e bash -c btop";
on-click = "${config.setting.terminal.bin} -e bash -c btop";
on-click-right = "powersave toggle";
};
"custom/display" = {

View file

@ -1,29 +1,119 @@
# Global settings.
# Just like I can configure each package, here I configure my config! :O)
{ ... }: {
ollama.primaryModel = "llama3";
browser.bin = "firefox-esr";
terminal.bin = "foot";
dpiAware = false;
sysctrl = "print";
keyboard = {
layouts = "us,ru";
options = "grp:toggle";
{ pkgs
, config
,lib
, ... }: {
options.setting = with lib; {
ollama = mkOption {
default = { };
type = types.submodule {
# freeformType = lib.jsonFormat.type;
options = {
primaryModel = mkOption {
default = "llama3";
type = types.str;
};
};
};
};
refresh = {
top = 2000;
browser = mkOption {
default = { };
type = types.submodule {
options = {
bin = mkOption {
default = "firefox-esr";
type = types.str;
};
};
};
};
step = {
brightness = 5;
volume = 5;
media = 10;
terminal = mkOption {
default = { };
type = types.submodule {
options = {
bin = mkOption {
default = "foot";
type = types.str;
};
};
};
};
timeout = {
popup = 5000;
keyd = 150;
dpiAware = mkOption {
default = false;
type = types.bool;
};
sysctrl = mkOption {
default = "print";
type = types.str;
};
keyboard = mkOption {
default = { };
type = types.submodule {
options = {
layouts = mkOption {
default = "us,ru";
type = types.str;
};
options = mkOption {
default = "grp:toggle";
type = types.str;
};
};
};
};
refresh = mkOption {
default = { };
type = types.submodule {
options = {
top = mkOption {
default = 2000;
type = types.int;
};
};
};
};
step = mkOption {
default = { };
type = types.submodule {
options = {
brightness = mkOption {
default = 5;
type = types.int;
};
volume = mkOption {
default = 5;
type = types.int;
};
media = mkOption {
default = 10;
type = types.int;
};
};
};
};
timeout = mkOption {
default = { };
type = types.submodule {
options = {
popup = mkOption {
default = 5000;
type = types.int;
};
keyd = mkOption {
default = 150;
type = types.int;
};
};
};
};
};
}

View file

@ -3,7 +3,7 @@
, style
, pkgs
, lib
, setting
, config
, key
, secret
, ... } @args: {

View file

@ -2,7 +2,7 @@
, util
, style
, pkgs
, setting
, config
, key
, secret
, ... } @args: {

View file

@ -3,7 +3,7 @@
, style
, pkgs
, lib
, setting
, config
, key
, secret
, ... } @args: {

View file

@ -4,7 +4,7 @@
, key
, pkgs
, secret
, setting
, config
, style
, username
, util

View file

@ -1,5 +1,5 @@
{ style, setting, pkgs, ... }: let
dpiAware = if setting.dpiAware then "yes" else "no";
{ style, config, pkgs, ... }: let
dpiAware = if config.setting.dpiAware then "yes" else "no";
fontStep = 1;
in {
file = (pkgs.formats.iniWithGlobalSection {}).generate "FootConfig" {

View file

@ -1,5 +1,5 @@
{ pkgs, style, setting, ... }: let
dpiAware = if setting.dpiAware then "yes" else "no";
{ pkgs, style, config, ... }: let
dpiAware = if config.setting.dpiAware then "yes" else "no";
in {
file = (pkgs.formats.ini {}).generate "FuzzelConfig" {
main = {
@ -8,7 +8,7 @@ in {
lines = 20;
prompt = "\"\"";
show-actions = "yes";
terminal = setting.terminal.bin;
terminal = config.setting.terminal.bin;
width = 40;
# list-executables-in-path = "no";
};

View file

@ -1,4 +1,4 @@
{ setting, pkgs, ... }: {
{ config, pkgs, ... }: {
file = (pkgs.formats.ini {}).generate "KeydDrgConfig" {
steam-app-548430 = {
"alt.1" = "macro(enter 10ms L e t ' s space d o space t h i s space T e x a s space s t y l e ! enter)";
@ -26,7 +26,7 @@
"alt.w" = "macro(enter 10ms r enter)";
"alt.x" = "macro(enter 10ms > space H e r e space < enter)";
"alt.z" = "macro(enter 10ms < space L e f t enter)";
leftshift = "timeout(leftcontrol, ${toString setting.timeout.keyd}, leftshift)";
leftshift = "timeout(leftcontrol, ${toString config.setting.timeout.keyd}, leftshift)";
};
};
}

View file

@ -1,4 +1,4 @@
{ setting, pkgs, ... }: {
{ config, pkgs, ... }: {
file = (pkgs.formats.ini {}).generate "KeydJetbrainsConfig" {
"jetbrains-*" = {
"alt./" = "C-/";
@ -16,7 +16,7 @@
"alt.q" = "A-left";
"alt.r" = "S-f10";
"alt.s" = "C-A-s";
"alt.tab" = "timeout(f8, ${toString setting.timeout.keyd}, macro2(0, 0, f7))";
"alt.tab" = "timeout(f8, ${toString config.setting.timeout.keyd}, macro2(0, 0, f7))";
"alt.v" = "C-q";
"alt.w" = "C-S-A-t";
"alt.x" = "C-f4";

View file

@ -1,4 +1,4 @@
{ style, pkgs, setting, ... }: let
{ style, pkgs, config, ... }: let
alpha = style.opacity.hex;
in {
file = (pkgs.formats.iniWithGlobalSection {}).generate "MakoConfig" {
@ -6,7 +6,7 @@ in {
anchor = "top-center";
background-color = "#${style.color.bg.dark}${alpha}";
border-color = "#${style.color.border}${alpha}";
default-timeout = setting.timeout.popup;
default-timeout = config.setting.timeout.popup;
font = "${style.font.serif.name} ${toString style.font.size.popup}";
height = 120;
icons = 0;

View file

@ -1,4 +1,4 @@
{ setting, util, ... }: {
{ config, util, ... }: {
text = util.trimTabs ''
#? Config file for btop v. 1.3.0
@ -55,7 +55,7 @@
shown_boxes = "cpu mem net proc"
#* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs.
update_ms = ${toString setting.refresh.top}
update_ms = ${toString config.setting.refresh.top}
#* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu direct",
#* "cpu lazy" sorts top process over time (easier to follow), "cpu direct" updates top process directly.

View file

@ -1,4 +1,4 @@
{ pkgs, setting, util, ... } @args: {
{ pkgs, config, util, ... } @args: {
init = (import ./module/Init.nix args).file;
keymap = (import ./module/Keymap.nix args).file;
theme = (import ./module/Theme.nix args).file;

View file

@ -1,4 +1,4 @@
{ pkgs, setting, ... }: {
{ pkgs, config, ... }: {
file = (pkgs.formats.toml {}).generate "YaziYaziConfig" {
manager = {
# linemode = "mtime";
@ -30,7 +30,7 @@
browser = [{
desc = "Browser";
orphan = true;
run = openWith setting.browser.bin;
run = openWith config.setting.browser.bin;
}];
text = [{
desc = "Text";