feat: better modules aragement.

This commit is contained in:
CronyAkatsuki 2025-03-23 20:01:51 +01:00
parent de11ee0676
commit 6e967a751f
49 changed files with 27 additions and 19 deletions

View file

@ -0,0 +1,17 @@
{
config,
lib,
...
}: {
imports = [
./graphics-tablet.nix
];
options = {
crony.additional-hardware.enable = lib.mkEnableOption "Enable additional hardware modules.";
};
config = lib.mkIf config.crony.additional-hardware.enable {
crony.additional-hardware.otd.enable = lib.mkDefault true;
};
}

View file

@ -0,0 +1,14 @@
{
config,
lib,
...
}: {
options = {
crony.additional-hardware.otd.enable = lib.mkEnableOption "Enable OpenTabletDriver";
};
config = lib.mkIf config.crony.additional-hardware.otd.enable {
# Setup OpenTabletDriver graphic tablet driver
hardware.opentabletdriver.enable = true;
};
}

View file

@ -0,0 +1,15 @@
{
config,
lib,
...
}: {
options = {
crony.amdgpu.enable = lib.mkEnableOption "Load amdgpu modules at boot.";
};
config = lib.mkIf config.crony.amdgpu.enable {
# Try to fix amdgpu
boot.initrd.kernelModules = ["amdgpu"];
services.xserver.videoDrivers = ["amdgpu"];
};
}

View file

@ -0,0 +1,28 @@
{
config,
lib,
...
}: {
options = {
crony.auto-cpufreq.enable = lib.mkEnableOption "Enable auto-cpufreq and set it up for my laptop.";
};
config = lib.mkIf config.crony.auto-cpufreq.enable {
# Setup auto-cpufreq
programs.auto-cpufreq = {
enable = true;
settings = {
battery = {
governor = "powersave";
turbo = "never";
};
charger = {
governor = "performance";
turbo = "auto";
};
};
};
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View file

@ -0,0 +1,15 @@
{
lib,
config,
...
}: {
# Enable bluetooth
options = {
crony.bluetooth.enable = lib.mkEnableOption "enable bluetooth";
};
config = lib.mkIf config.crony.bluetooth.enable {
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
};
}

View file

@ -0,0 +1,43 @@
{lib, ...}: {
imports = [
./bluetooth.nix
./nvidia.nix
./plasma.nix
./disable-hibernation.nix
./gaming.nix
./zsh.nix
./stylix.nix
./nbfc.nix
./ryzenadj.nix
./qemu.nix
./amdgpu.nix
./nfs-share.nix
./auto-cpufreq.nix
./wireguard.nix
./hyprland.nix
./sddm.nix
./watchdog.nix
./general-services.nix
./additional-hardware
];
crony.bluetooth.enable = lib.mkDefault true;
crony.nvidia.enable = lib.mkDefault true;
crony.plasma.enable = lib.mkDefault false;
crony.hibernation.disable = lib.mkDefault true;
crony.gaming.enable = lib.mkDefault true;
crony.zsh.enable = lib.mkDefault true;
crony.stylix.enable = lib.mkDefault true;
crony.nbfc.enable = lib.mkDefault true;
crony.ryzenadj.enable = lib.mkDefault true;
crony.qemu.enable = lib.mkDefault true;
crony.amdgpu.enable = lib.mkDefault false;
crony.nfs-share.enable = lib.mkDefault true;
crony.auto-cpufreq.enable = lib.mkDefault true;
crony.wireguard.enable = lib.mkDefault true;
crony.hyprland-nixos.enable = lib.mkDefault true;
crony.sddm.enable = lib.mkDefault true;
crony.watchdog.disable = lib.mkDefault true;
crony.general-services.enable = lib.mkDefault true;
crony.additional-hardware.enable = lib.mkDefault true;
}

View file

@ -0,0 +1,30 @@
{
config,
lib,
...
}: {
options = {
crony.hibernation.disable = lib.mkEnableOption "disable hibernation and friends";
};
config = lib.mkIf config.crony.hibernation.disable {
# Disable hibernation, sleep and other friends
systemd.targets = {
sleep = {
enable = false;
unitConfig.DefaultDependencies = "no";
};
suspend = {
enable = false;
unitConfig.DefaultDependencies = "no";
};
hibernate = {
enable = false;
unitConfig.DefaultDependencies = "no";
};
"hybrid-sleep" = {
enable = false;
unitConfig.DefaultDependencies = "no";
};
};
};
}

View file

@ -0,0 +1,50 @@
{
config,
pkgs,
lib,
...
}: {
# Getting gaming setup
options = {
crony.gaming.enable = lib.mkEnableOption "enable gaming related stuff, like steam and gamemode";
};
config = lib.mkIf config.crony.gaming.enable {
environment.systemPackages = with pkgs; [
mangohud
];
# Install steam
programs.steam = {
enable = true;
};
# Enable gamescope
programs.gamescope = {
enable = true;
capSysNice = true;
};
# Install gamemode
programs.gamemode = {
enable = true;
enableRenice = true;
settings = {
general = {
softrealtime = "on";
renice = 10;
};
custom = {
start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'";
end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
};
};
};
# Setup esync
systemd.extraConfig = "DefaultLimitNOFILE=1048576";
security.pam.loginLimits = [
{
domain = "*";
type = "hard";
item = "nofile";
value = "1048576";
}
];
};
}

View file

@ -0,0 +1,25 @@
{
config,
pkgs,
lib,
...
}: {
options = {
crony.general-services.enable = lib.mkEnableOption "Enable general services that just should be enabled by default.";
};
config = lib.mkIf config.crony.general-services.enable {
# Enable upower
services.upower.enable = true;
# Setup udev for android rules
services.udev.packages = [
pkgs.android-udev-rules
];
# Enable firmware updater
services.fwupd.enable = true;
# Enable zram swap device
zramSwap.enable = true;
};
}

View file

@ -0,0 +1,30 @@
{
config,
lib,
...
}: {
options = {
crony.hyprland-nixos.enable = lib.mkEnableOption "Enable hyprland globally";
};
config = lib.mkIf config.crony.hyprland-nixos.enable {
programs.uwsm = {
enable = true;
waylandCompositors = {
hyprland = {
prettyName = "Hyprland";
comment = "Hyprland compositor managed by UWSM";
binPath = "/run/current-system/sw/bin/Hyprland";
};
};
};
programs.hyprland = {
enable = true;
withUWSM = true;
};
security.pam.services.hyprlock = {};
};
}

View file

@ -0,0 +1,30 @@
{
config,
inputs,
pkgs,
lib,
...
}: {
options = {
crony.nbfc.enable = lib.mkEnableOption "enable nbfc and set it up for my laptop";
};
config = lib.mkIf config.crony.nbfc.enable {
# Install nbfc-linux
environment.systemPackages = [
inputs.nbfc-linux.packages.x86_64-linux.default
];
# Setup nbfc package
systemd.services.nbfc_service = {
enable = true;
description = "NoteBook FanControl Service";
serviceConfig.Type = "simple";
path = [pkgs.kmod];
script = "${inputs.nbfc-linux.packages.x86_64-linux.default}/bin/nbfc_service --config-file '/home/crony/.config/nbfc.json'";
wantedBy = ["multi-user.target"];
};
};
}

View file

@ -0,0 +1,18 @@
{
config,
lib,
...
}: {
options = {
crony.nfs-share.enable = lib.mkEnableOption "Setup personal nfs share mount.";
};
config = lib.mkIf config.crony.nfs-share.enable {
# Nfs share
fileSystems."/mnt/share" = {
device = "192.168.0.4:/mnt/nfs";
fsType = "nfs";
options = ["_netdev" "noauto" "x-systemd.automount" "x-systemd.mount-timeout=10" "timeo=14" "x-systemd.idle-timeout=600"];
};
};
}

View file

@ -0,0 +1,37 @@
{
lib,
pkgs,
config,
...
}: {
# Allow for nvidia
options = {
crony.nvidia.enable = lib.mkEnableOption "enable nvidia";
};
config = lib.mkIf config.crony.nvidia.enable {
# Setup vaapi for nvidia
hardware.graphics.extraPackages = with pkgs; [
nvidia-vaapi-driver
];
# Setup nvidia drivers
services.xserver.videoDrivers = ["nvidia"];
hardware.nvidia = {
open = true;
modesetting.enable = true;
powerManagement.enable = true;
nvidiaSettings = true;
prime = {
reverseSync.enable = true;
offload = {
enableOffloadCmd = true;
enable = false;
};
nvidiaBusId = "PCI:1:0:0";
amdgpuBusId = "PCI:5:0:0";
};
};
};
}

View file

@ -0,0 +1,20 @@
{
pkgs,
config,
lib,
...
}: {
options = {
crony.plasma.enable = lib.mkEnableOption "enable plasma";
};
config = lib.mkIf config.crony.plasma.enable {
# Enable the KDE Plasma Desktop Environment.
services.desktopManager.plasma6.enable = true;
environment.plasma6.excludePackages = with pkgs.kdePackages; [
plasma-browser-integration
konsole
oxygen
];
};
}

View file

@ -0,0 +1,19 @@
{
config,
pkgs,
lib,
...
}: {
options = {
crony.qemu.enable = lib.mkEnableOption "Enable qemu and setup quickemu";
};
config = lib.mkIf config.crony.qemu.enable {
systemd.tmpfiles.rules = ["L+ /var/lib/qemu/firmware - - - - ${pkgs.qemu}/share/qemu/firmware"];
environment.systemPackages = with pkgs; [
qemu
quickemu
];
};
}

View file

@ -0,0 +1,153 @@
{
config,
pkgs,
lib,
...
}: let
ryzenadj-service =
pkgs.writers.writePython3Bin "ryzenadj-service" {
libraries = [pkgs.ryzenadj];
flakeIgnore = ["E501" "F405" "F403" "E265"];
} ''
#!/bin/env python3
import argparse
import os
import sys
import time
from ctypes import *
lib_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(lib_path)
lib = cdll.LoadLibrary("${pkgs.ryzenadj}/lib/libryzenadj.so")
# define ctype mappings for types which can not be mapped automatically
# ryzenadj tables
lib.init_ryzenadj.restype = c_void_p
lib.refresh_table.argtypes = [c_void_p]
# Stapm value and limit
lib.get_stapm_limit.restype = c_float
lib.get_stapm_limit.argtypes = [c_void_p]
# Slow limit and value
lib.get_slow_limit.restype = c_float
lib.get_slow_limit.argtypes = [c_void_p]
# Fast limit and value
lib.get_fast_limit.restype = c_float
lib.get_fast_limit.argtypes = [c_void_p]
# Slow time and value
lib.get_slow_time.restype = c_float
lib.get_slow_time.argtypes = [c_void_p]
# stapm time and value
lib.get_stapm_time.restype = c_float
lib.get_stapm_time.argtypes = [c_void_p]
# Vrm Max Current and value
lib.get_vrmmax_current.restype = c_float
lib.get_vrmmax_current.argtypes = [c_void_p]
# Tctl cpu temp
lib.get_tctl_temp.restype = c_float
lib.get_tctl_temp.argtypes = [c_void_p]
ry = lib.init_ryzenadj()
if not ry:
sys.exit("RyzenAdj could not get initialized")
error_messages = {
-1: "{:s} is not supported on this family\n",
-3: "{:s} is not supported on this SMU\n",
-4: "{:s} is rejected by SMU\n",
}
def adjust(field, value):
function_name = "set_" + field
adjust_func = lib.__getattr__(function_name)
adjust_func.argtypes = [c_void_p, c_ulong]
res = adjust_func(ry, value)
if res:
error = error_messages.get(res, "{:s} did fail with {:d}\n")
sys.stderr.write(error.format(function_name, res))
else:
print(f"Succesfully set {field} to {value}")
def enable(field):
function_name = "set_" + field
adjust_func = lib.__getattr__(function_name)
adjust_func.argtypes = [c_void_p]
res = adjust_func(ry)
if res:
error = error_messages.get(res, "{:s} did fail with {:d}\n")
sys.stderr.write(error.format(function_name, res))
else:
print(f"Sucessfully enable {field}")
def set(args):
adjust("stapm_limit", args.stapm_limit)
adjust("fast_limit", args.fast_limit)
adjust("slow_limit", args.slow_limit)
# adjust("slow_time", args.slow_time)
# adjust("stapm_time", args.stapm_time)
adjust("tctl_temp", args.tctl_temp)
adjust("vrmmax_current", args.vrmmax_current)
enable("max_performance")
def loop(args):
set(args)
while True:
lib.refresh_table(ry)
current = round(lib.get_tctl_temp(ry))
if current != 85:
set(args)
time.sleep(3)
def parse_args():
parser = argparse.ArgumentParser(
prog="Ryzenadj Service",
description="Simple Ryzenadj python service to keep values set",
)
parser.add_argument("--stapm-limit", action="store", required=True, type=int)
parser.add_argument("--fast-limit", action="store", required=True, type=int)
parser.add_argument("--slow-limit", action="store", required=True, type=int)
# parser.add_argument("--slow-time", action="store", required=True, type=int)
# parser.add_argument("--stapm-time", action="store", required=True, type=int)
parser.add_argument("--tctl-temp", action="store", required=True, type=int)
parser.add_argument("--vrmmax-current", action="store", required=True, type=int)
return parser.parse_args()
def main():
args = parse_args()
loop(args)
if __name__ == "__main__":
main()
'';
in {
options = {
crony.ryzenadj.enable = lib.mkEnableOption "Enable ryzenadj and customize it for my system.";
};
config = lib.mkIf config.crony.ryzenadj.enable {
# Add ryzen-smu driver to allow reading values
boot.extraModulePackages = with config.boot.kernelPackages; [ryzen-smu];
# Install ryzenadj globally
environment.systemPackages = with pkgs; [
ryzenadj
];
# Setup python service for ryzenadj
systemd.services.ryzenadj = {
enable = true;
description = "Set my cpu power usage power to something more manageable.";
wantedBy = ["multi-user.target"];
script = "${ryzenadj-service}/bin/ryzenadj-service --stapm-limit 35000 --fast-limit 35000 --slow-limit 35000 --tctl-temp 90 --vrmmax-current 70000";
};
};
}

View file

@ -0,0 +1,30 @@
{
config,
pkgs,
lib,
...
}: {
options = {
crony.sddm.enable = lib.mkEnableOption "Enable sddm.";
};
config = lib.mkIf config.crony.sddm.enable {
environment.systemPackages = [
(pkgs.where-is-my-sddm-theme.override {
variants = ["qt6" "qt5"];
themeConfig.General = {
showSessionsByDefault = true;
background = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
backgroundFill = "#282828";
backgroundMode = "none";
};
})
];
services.displayManager.sddm = {
enable = true;
wayland.enable = true;
theme = "where_is_my_sddm_theme_qt5";
};
};
}

View file

@ -0,0 +1,60 @@
{
pkgs,
config,
lib,
...
}: {
options = {
crony.stylix.enable = lib.mkEnableOption "enable stylix and style my system";
};
config = lib.mkIf config.crony.stylix.enable {
# Enable sytling using stylix
stylix.enable = true;
stylix.autoEnable = true;
stylix.image = ./background.png;
stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-medium.yaml";
# Change Cursor
stylix.cursor.package = pkgs.bibata-cursors;
stylix.cursor.name = "Bibata-Modern-Ice";
stylix.cursor.size = 32;
# Fix stuff not automatically using dark theme on websites
stylix.polarity = "dark";
# Change u those fonts
stylix.fonts = {
serif = {
package = pkgs.dejavu_fonts;
name = "DejaVu Serif";
};
sansSerif = {
package = pkgs.dejavu_fonts;
name = "DejaVu Sans";
};
monospace = {
package = pkgs.nerd-fonts.commit-mono;
name = "CommitMono Nerd Font";
};
emoji = {
package = pkgs.noto-fonts-emoji;
name = "Noto Color Emoji";
};
};
# Change font sizes
stylix.fonts.sizes = {
applications = 15;
desktop = 13;
popups = 13;
terminal = 15;
};
# Change chrome settings
stylix.targets.chromium.enable = false;
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

View file

@ -0,0 +1,14 @@
{
config,
lib,
...
}: {
options = {
crony.watchdog.disable = lib.mkEnableOption "Disable watchdog for my laptop.";
};
config = lib.mkIf config.crony.watchdog.disable {
boot.kernelParams = ["nmi_watchdog=0"];
boot.blacklistedKernelModules = ["sp5100_tco"];
};
}

View file

@ -0,0 +1,26 @@
{
config,
lib,
...
}: {
options = {
crony.wireguard.enable = lib.mkEnableOption "Open ports in firewall for wireguard to work.";
};
config = lib.mkIf config.crony.wireguard.enable {
# Allow for wireguard traffic
networking.firewall = {
# if packets are still dropped, they will show up in dmesg
logReversePathDrops = true;
# wireguard trips rpfilter up
extraCommands = ''
ip46tables -t mangle -I nixos-fw-rpfilter -p udp -m udp --sport 51820 -j RETURN
ip46tables -t mangle -I nixos-fw-rpfilter -p udp -m udp --dport 51820 -j RETURN
'';
extraStopCommands = ''
ip46tables -t mangle -D nixos-fw-rpfilter -p udp -m udp --sport 51820 -j RETURN || true
ip46tables -t mangle -D nixos-fw-rpfilter -p udp -m udp --dport 51820 -j RETURN || true
'';
};
};
}

View file

@ -0,0 +1,18 @@
{
config,
lib,
pkgs,
...
}: {
options = {
crony.zsh.enable = lib.mkEnableOption "install and enable zsh for all users";
};
config = lib.mkIf config.crony.zsh.enable {
# Installing zsh
programs.zsh.enable = true;
programs.zsh.enableCompletion = false;
users.defaultUserShell = pkgs.zsh;
environment.pathsToLink = ["/share/zsh"];
};
}