modularizing kernel and loader settings

This commit is contained in:
cnst
2024-09-22 14:30:06 +02:00
parent 6f53da8393
commit 50d554b6f6
22 changed files with 294 additions and 84 deletions

View File

@@ -1,26 +1,36 @@
#!/usr/bin/env bash # Define TERMINAL if not set
TERMINAL="${TERMINAL:-foot}"
# Path to the tuirun executable # Path to the tuirun executable
TUIRUN_PATH="/etc/profiles/per-user/$USER/bin/tuirun" TUIRUN_PATH="/etc/profiles/per-user/$USER/bin/tuirun"
LOGFILE="$HOME/tuirun_debug.log"
echo "Launching tuirun..." >>"$LOGFILE" # Use absolute paths for commands
date >>"$LOGFILE" PGREP="/run/current-system/sw/bin/pgrep"
PKILL="/run/current-system/sw/bin/pkill"
HYPRCTL="/etc/profiles/per-user/$USER/bin/hyprctl"
if pgrep -f "alacritty --title tuirun" >/dev/null; then # Determine OPTIONS based on TERMINAL
echo "Terminating existing tuirun process" >>"$LOGFILE" if [ "$TERMINAL" = "foot" ]; then
pkill -f "alacritty --title tuirun" OPTIONS="--override=main.pad=0x0"
elif [ "$TERMINAL" = "alacritty" ]; then
OPTIONS="--option window.padding.x=0 --option window.padding.y=0"
else else
echo "Starting new tuirun process" >>"$LOGFILE" OPTIONS=""
if ! hyprctl dispatch exec "alacritty --title tuirun -e sh -c '$TUIRUN_PATH'"; then
echo "Failed to launch tuirun in foot terminal" >>"$LOGFILE"
exit 1
fi fi
sleep 1 # Give it a second to start
echo "Checking if tuirun process is still running..." >>"$LOGFILE" # Matching pattern for the process
if pgrep -f "$TUIRUN_PATH" >/dev/null; then MATCH_PATTERN="$TERMINAL --title tuirun"
echo "tuirun is running" >>"$LOGFILE"
if "$PGREP" -f "$MATCH_PATTERN" >/dev/null; then
"$PKILL" -f "$MATCH_PATTERN"
else else
echo "tuirun exited prematurely" >>"$LOGFILE" # Construct the command
CMD="$TERMINAL --title tuirun"
if [ -n "$OPTIONS" ]; then
CMD="$CMD $OPTIONS"
fi fi
CMD="$CMD -e $TUIRUN_PATH"
# Launch the terminal with OPTIONS
"$HYPRCTL" dispatch exec "$CMD"
fi fi

28
flake.lock generated
View File

@@ -773,11 +773,11 @@
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1726918033, "lastModified": 1726995313,
"narHash": "sha256-I0U4OLssUlNd6/KXHwErmgmYZURTJYJNHbeoKaMH4iI=", "narHash": "sha256-HTbsXJDFugdQ794d1Bnh8eRSY7AlunIxd7jFW9kkKNM=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "8579066c7a1ceb745499ea4e11d5d420b1387ec0", "rev": "e5ff19ac0f2c8d53a0c847d06a17676e636d6447",
"revCount": 5246, "revCount": 5247,
"submodules": true, "submodules": true,
"type": "git", "type": "git",
"url": "https://github.com/hyprwm/Hyprland" "url": "https://github.com/hyprwm/Hyprland"
@@ -1401,11 +1401,11 @@
}, },
"nur": { "nur": {
"locked": { "locked": {
"lastModified": 1726990799, "lastModified": 1726995785,
"narHash": "sha256-UhRcg+b/WlTmxF0NuaHhcwRafsjgLvgQCLkAAAH7/oU=", "narHash": "sha256-qpY9TCjtyhAeHa64NCyo3SoaHslxrrxQiMOPPY5lXEM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NUR", "repo": "NUR",
"rev": "ea5bcd8bbc996195b556e51e9be9cef204b85ce3", "rev": "474ea929fade537a0ba4f1e5b73abc0d157a293f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -1740,11 +1740,11 @@
"systems": "systems_8" "systems": "systems_8"
}, },
"locked": { "locked": {
"lastModified": 1726992296, "lastModified": 1726998061,
"narHash": "sha256-ra2guef5o6SytQdsWMfXZZgpk6tF2YObx8JnGP7TYXg=", "narHash": "sha256-VgTXpSQuHQkSLvx3/lR8spnZK/iNniVoR3dcsQbEyQo=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "1888a9a17f253492d8db41720d481c2051987e0f", "rev": "05f2efc7135167613ef4b190efd7ba4e01c424d6",
"revCount": 22, "revCount": 24,
"type": "git", "type": "git",
"url": "https://git.sr.ht/~canasta/tuirun" "url": "https://git.sr.ht/~canasta/tuirun"
}, },
@@ -1832,11 +1832,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1726851729, "lastModified": 1726933538,
"narHash": "sha256-1z0esr5lBeUMlrPZ9gZmqZT8oTQekxJi53HAW4cH0Ms=", "narHash": "sha256-xTqnMoJsEojuvqJLuM+U7EZ7q71efaj3pbvjutq4TXc=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "xdg-desktop-portal-hyprland", "repo": "xdg-desktop-portal-hyprland",
"rev": "73b8c4f1150040644cf678aa8bbf2cec48a433cf", "rev": "4880c50146d0c2a3152d2b02f79253810c330c11",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -10,7 +10,6 @@ in {
modules.terminal.alacritty.enable = mkEnableOption "Enables firefox"; modules.terminal.alacritty.enable = mkEnableOption "Enables firefox";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.sessionVariables.TERMINAL = "alacritty";
programs.alacritty = { programs.alacritty = {
enable = true; enable = true;
settings = { settings = {

View File

@@ -11,7 +11,6 @@ in {
modules.terminal.foot.enable = mkEnableOption "Enables foot terminal"; modules.terminal.foot.enable = mkEnableOption "Enables foot terminal";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.sessionVariables.TERMINAL = "foot";
programs.foot = { programs.foot = {
enable = true; enable = true;
package = pkgs.foot; package = pkgs.foot;

View File

@@ -10,7 +10,6 @@ in {
modules.terminal.kitty.enable = mkEnableOption "Enables kitty terminal"; modules.terminal.kitty.enable = mkEnableOption "Enables kitty terminal";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.sessionVariables.TERMINAL = "kitty";
programs.kitty = { programs.kitty = {
enable = true; enable = true;
settings = { settings = {

View File

@@ -15,7 +15,6 @@ in {
modules.terminal.wezterm.enable = mkEnableOption "Enables wezterm terminal"; modules.terminal.wezterm.enable = mkEnableOption "Enables wezterm terminal";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.sessionVariables.TERMINAL = "wezterm";
programs.wezterm = { programs.wezterm = {
enable = true; enable = true;
package = weztermPkg; package = weztermPkg;

View File

@@ -52,7 +52,7 @@ in {
#bind = $mod, M, exec, hyprctl dispatch exit #bind = $mod, M, exec, hyprctl dispatch exit
#bind = $mod, E, exec, $fileManager #bind = $mod, E, exec, $fileManager
"$mod, E, exec, $fileManager" "$mod, E, exec, $fileManager"
"$mod, r, exec, $tuirun" "$mod, R, exec, $tuirun"
"$mod SHIFT, E, exec, $yazi" "$mod SHIFT, E, exec, $yazi"
"$mod, F, fullscreen," "$mod, F, fullscreen,"
"$mod SHIFT, F, togglefloating," "$mod SHIFT, F, togglefloating,"

View File

@@ -19,7 +19,7 @@ in {
"float,initialTitle:(tuirun)" "float,initialTitle:(tuirun)"
"size 600 300,initialTitle:(tuirun)" "size 600 300,initialTitle:(tuirun)"
"center,initialTitle:(tuirun)" "center,initialTitle:(tuirun)"
# "workspace special:tuirun,initialTitle:(tuirun)" "workspace special:tuirun,initialTitle:(tuirun)"
"noborder,initialTitle:(tuirun)" "noborder,initialTitle:(tuirun)"
#windowrulev2 = move 1708 32,class:(floatcal) #windowrulev2 = move 1708 32,class:(floatcal)
"float,class:(org.keepassxc.KeePassXC)" "float,class:(org.keepassxc.KeePassXC)"

View File

@@ -36,15 +36,15 @@ in {
./modules.nix ./modules.nix
]; ];
boot = { # boot = {
consoleLogLevel = 3; # consoleLogLevel = 3;
kernelPackages = lib.mkForce pkgs.linuxPackages_latest; # kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
kernelParams = [ # kernelParams = [
"amd_pstate=active" # "amd_pstate=active"
"quiet" # "quiet"
"splash" # "splash"
]; # ];
}; # };
# environment.variables.COPILOT_API_KEY = config.age.secrets.cnstcopilot.path; # environment.variables.COPILOT_API_KEY = config.age.secrets.cnstcopilot.path;

View File

@@ -1,5 +1,17 @@
{ {
modules = { modules = {
boot = {
loader = {
default.enable = false;
lanzaboote.enable = true;
};
kernel = {
variant = "cachyos";
hardware = "amd";
extraKernelParams = [];
extraBlacklistedModules = [];
};
};
gaming = { gaming = {
steam = { steam = {
enable = true; enable = true;
@@ -154,6 +166,12 @@
anyrun = { anyrun = {
enable = true; enable = true;
}; };
chaotic = {
enable = true;
amd = {
enable = true;
};
};
corectrl = { corectrl = {
enable = true; enable = true;
}; };

View File

@@ -35,16 +35,6 @@ in {
./modules.nix ./modules.nix
]; ];
boot = {
consoleLogLevel = 3;
kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
kernelParams = [
"amd_pstate=active"
"quiet"
"splash"
];
};
swapDevices = [ swapDevices = [
{ {
device = "/var/lib/swapfile"; device = "/var/lib/swapfile";

View File

@@ -1,5 +1,17 @@
{ {
modules = { modules = {
boot = {
loader = {
default.enable = true;
lanzaboote.enable = false;
};
kernel = {
variant = "latest";
hardware = "amd";
extraKernelParams = [];
extraBlacklistedModules = [];
};
};
gaming = { gaming = {
steam = { steam = {
enable = false; enable = false;
@@ -149,6 +161,12 @@
brightnessctl = { brightnessctl = {
enable = true; enable = true;
}; };
chaotic = {
enable = false;
amd = {
enable = false;
};
};
corectrl = { corectrl = {
enable = false; enable = false;
}; };

View File

@@ -34,7 +34,6 @@
shared shared
++ [ ++ [
./cnix ./cnix
"${mod}/boot/lanzaboote"
"${mod}/nix/nh/cnst" "${mod}/nix/nh/cnst"
"${mod}/dev" "${mod}/dev"
{ {
@@ -53,7 +52,6 @@
shared shared
++ [ ++ [
./toothpc ./toothpc
"${mod}/boot/lanzaboote"
"${mod}/nix/nh/toothpick" "${mod}/nix/nh/toothpick"
"${mod}/dev" "${mod}/dev"
{ {
@@ -72,7 +70,6 @@
shared shared
++ [ ++ [
./cnixpad ./cnixpad
"${mod}/boot"
"${mod}/nix/nh/cnst" "${mod}/nix/nh/cnst"
"${mod}/dev" "${mod}/dev"
{ {

View File

@@ -35,15 +35,6 @@ in {
./modules.nix ./modules.nix
]; ];
boot = {
blacklistedKernelModules = [
];
consoleLogLevel = 3;
kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
kernelParams = [
];
};
# https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion
system.stateVersion = lib.mkDefault "23.11"; system.stateVersion = lib.mkDefault "23.11";
} }

View File

@@ -1,5 +1,17 @@
{ {
modules = { modules = {
boot = {
loader = {
default.enable = false;
lanzaboote.enable = true;
};
kernel = {
variant = "cachyos";
hardware = "nvidia";
extraKernelParams = [];
extraBlacklistedModules = [];
};
};
gaming = { gaming = {
steam = { steam = {
enable = true; enable = true;
@@ -38,7 +50,7 @@
}; };
nvidia = { nvidia = {
enable = true; enable = true;
package = "beta"; # set to beta/stable/production depending on your needs package = "latest"; # set to beta/latest/stable/production depending on your needs
}; };
}; };
network = { network = {
@@ -150,6 +162,12 @@
corectrl = { corectrl = {
enable = false; enable = false;
}; };
chaotic = {
enable = true;
amd = {
enable = false;
};
};
microfetch = { microfetch = {
enable = true; enable = true;
}; };

View File

@@ -0,0 +1,72 @@
# kernel.nix
{
pkgs,
lib,
config,
...
}: let
inherit (lib) mkOption;
cfg = config.modules.boot.kernel;
in {
options = {
modules.boot.kernel = {
variant = mkOption {
type = lib.types.enum ["latest" "cachyos"];
default = "latest";
description = "Kernel variant to use.";
};
hardware = mkOption {
type = lib.types.enum ["amd" "nvidia"];
default = "amd";
description = "Hardware type (GPU) configuration.";
};
extraKernelParams = mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Additional kernel parameters.";
};
extraBlacklistedModules = mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Additional kernel modules to blacklist.";
};
};
};
config = {
boot = {
consoleLogLevel = 3;
kernelPackages = (
if cfg.variant == "latest"
then pkgs.linuxPackages_latest
else if cfg.variant == "cachyos"
then pkgs.linuxPackages_cachyos
else pkgs.linuxPackages
);
kernelParams =
[
"quiet"
"splash"
]
++ (
if cfg.hardware == "amd"
then ["amd_pstate=active"]
else []
)
++ cfg.extraKernelParams;
blacklistedKernelModules =
(
if cfg.hardware == "nvidia"
then ["nouveau"]
else []
)
++ cfg.extraBlacklistedModules;
};
};
}

View File

@@ -0,0 +1,60 @@
{
pkgs,
lib,
config,
inputs,
...
}: let
inherit (lib) mkIf mkEnableOption mkMerge mkForce;
cfg = config.modules.boot.loader;
in {
options = {
modules.boot.loader = {
default = {
enable = mkEnableOption "Enable default boot loader configuration.";
};
lanzaboote = {
enable = mkEnableOption "Enable Lanzaboote boot loader configuration.";
};
};
};
imports = [
inputs.lanzaboote.nixosModules.lanzaboote
];
config = mkMerge [
{
assertions = [
{
assertion = !(cfg.default.enable && cfg.lanzaboote.enable);
message = "Only one of modules.boot.loader.default.enable and modules.boot.loader.lanzaboote.enable can be set to true.";
}
];
}
(mkIf cfg.default.enable {
# Default boot loader configuration
boot.loader = {
systemd-boot.enable = true;
systemd-boot.graceful = true;
efi.canTouchEfiVariables = false;
};
})
(mkIf cfg.lanzaboote.enable {
# Lanzaboote boot loader configuration
boot = {
lanzaboote = {
enable = true;
pkiBundle = "/etc/secureboot";
};
# We let Lanzaboote install systemd-boot
loader.systemd-boot.enable = mkForce false;
};
environment.systemPackages = [pkgs.sbctl];
})
];
}

View File

@@ -1,5 +1,7 @@
{systemModules, ...}: { {systemModules, ...}: {
imports = [ imports = [
"${systemModules}/boot/loader"
"${systemModules}/boot/kernel"
"${systemModules}/gaming/gamemode" "${systemModules}/gaming/gamemode"
"${systemModules}/gaming/gamescope" "${systemModules}/gaming/gamescope"
"${systemModules}/gaming/lutris" "${systemModules}/gaming/lutris"
@@ -40,6 +42,7 @@
"${systemModules}/utils/android" "${systemModules}/utils/android"
"${systemModules}/utils/anyrun" "${systemModules}/utils/anyrun"
"${systemModules}/utils/brightnessctl" "${systemModules}/utils/brightnessctl"
"${systemModules}/utils/chaotic"
"${systemModules}/utils/corectrl" "${systemModules}/utils/corectrl"
"${systemModules}/utils/microfetch" "${systemModules}/utils/microfetch"
"${systemModules}/utils/misc" "${systemModules}/utils/misc"

View File

@@ -20,15 +20,7 @@ in {
vaapiVdpau vaapiVdpau
libvdpau-va-gl libvdpau-va-gl
amdvlk amdvlk
# mesa
mesa
# vulkan
vulkan-tools vulkan-tools
# vulkan-loader
# vulkan-validation-layers
# vulkan-extension-layer
]; ];
extraPackages32 = with pkgs.pkgsi686Linux; [ extraPackages32 = with pkgs.pkgsi686Linux; [
vaapiVdpau vaapiVdpau

View File

@@ -18,9 +18,9 @@ in {
modules.hardware.graphics.nvidia = { modules.hardware.graphics.nvidia = {
enable = mkEnableOption "Enables NVidia graphics"; enable = mkEnableOption "Enables NVidia graphics";
package = mkOption { package = mkOption {
type = types.enum ["stable" "beta" "production"]; # Added "production" here type = types.enum ["stable" "beta" "production" "latest"];
default = "stable"; default = "stable";
description = "Choose between the stable, beta, or production NVidia driver package"; description = "Choose between the stable, beta, latest, or production NVidia driver package";
}; };
}; };
}; };
@@ -49,15 +49,17 @@ in {
package = package =
if cfg.package == "beta" if cfg.package == "beta"
then config.boot.kernelPackages.nvidiaPackages.beta then config.boot.kernelPackages.nvidiaPackages.beta
else if cfg.package == "latest"
then config.boot.kernelPackages.nvidiaPackages.latest
else if cfg.package == "production" else if cfg.package == "production"
then config.boot.kernelPackages.nvidiaPackages.production then config.boot.kernelPackages.nvidiaPackages.prodution
else config.boot.kernelPackages.nvidiaPackages.stable; else config.boot.kernelPackages.nvidiaPackages.stable;
modesetting.enable = true; modesetting.enable = true;
powerManagement = { powerManagement = {
enable = false; enable = false;
finegrained = false; finegrained = false;
}; };
open = false; open = true;
nvidiaSettings = true; nvidiaSettings = true;
}; };
}; };

View File

@@ -0,0 +1,44 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption mkMerge;
cfg = config.modules.utils.chaotic;
in {
options = {
modules.utils.chaotic = {
enable = mkEnableOption "Enables Chaotic AUR packages";
amd.enable = mkOption {
type = lib.types.bool;
default = false;
description = "Whether to install AMD-specific settings.";
};
};
};
config = mkIf cfg.enable (mkMerge [
{
# Base configuration when Chaotic is enabled
chaotic.scx.enable = true;
}
(mkIf cfg.amd.enable {
# AMD-specific configuration
chaotic.mesa-git = {
enable = true;
extraPackages = with pkgs; [
mesa_git.opencl
intel-media-driver
intel-ocl
vaapiIntel
];
extraPackages32 = with pkgs; [
mesa32_git.opencl
intel-media-driver
vaapiIntel
];
};
})
]);
}

View File

@@ -14,7 +14,6 @@
environment = { environment = {
systemPackages = with pkgs; [ systemPackages = with pkgs; [
git git
scx
stow stow
]; ];
localBinInPath = true; localBinInPath = true;