implementing modules for system applications

This commit is contained in:
cnst
2024-08-18 13:49:05 +02:00
parent 38f68c3550
commit a4306380e3
101 changed files with 1105 additions and 452 deletions

View File

@@ -0,0 +1,40 @@
{systemModules, ...}: {
imports = [
"${systemModules}/network"
"${systemModules}/gaming/gamemode"
"${systemModules}/gaming/gamescope"
"${systemModules}/gaming/steam"
"${systemModules}/gaming/lutris"
"${systemModules}/gui/gnome"
"${systemModules}/gui/hyprland"
"${systemModules}/utils/android"
"${systemModules}/utils/anyrun"
"${systemModules}/utils/corectrl"
"${systemModules}/utils/microfetch"
"${systemModules}/utils/nix-ld"
"${systemModules}/sysd/blueman"
"${systemModules}/sysd/dbus"
"${systemModules}/sysd/fwupd"
"${systemModules}/sysd/gnome-keyring"
"${systemModules}/sysd/greetd"
"${systemModules}/sysd/gvfs"
"${systemModules}/sysd/locate"
"${systemModules}/sysd/mullvad"
"${systemModules}/sysd/pipewire"
"${systemModules}/sysd/powerd"
"${systemModules}/sysd/samba"
"${systemModules}/sysd/sops"
"${systemModules}/sysd/ssh"
"${systemModules}/sysd/udisks"
"${systemModules}/sysd/xserver/amd"
"${systemModules}/sysd/xserver/amd/hhkbse"
"${systemModules}/sysd/xserver/nvidia"
"${systemModules}/hardware/graphics/amd"
"${systemModules}/hardware/graphics/nvidia"
"${systemModules}/hardware/bluetooth"
"${systemModules}/hardware/logitech"
"${systemModules}/studio/gimp"
"${systemModules}/studio/inkscape"
"${systemModules}/studio/blender"
];
}

View File

@@ -0,0 +1,48 @@
{
config,
lib,
pkgs,
inputs,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption;
cfg = config.modules.gaming.gamemode;
pipewireLowLatencyModule = inputs.nix-gaming.nixosModules.pipewireLowLatency;
in {
imports = [
pipewireLowLatencyModule
];
options = {
modules.gaming.gamemode = {
enable = mkEnableOption "Enables gamemode";
optimizeGpu = mkOption {
type = lib.types.bool;
default = false;
description = "Whether to apply GPU optimizations.";
};
};
};
config = mkIf cfg.enable {
programs.gamemode = {
enable = true;
settings = {
general = {
inhibit_screensaver = 1;
softrealtime = "auto";
renice = 15;
};
gpu = mkIf cfg.optimizeGpu {
apply_gpu_optimisations = "accept-responsibility";
gpu_device = 0;
amd_performance_level = "high";
};
custom = {
start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'";
end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
};
};
};
# see https://github.com/fufexan/nix-gaming/#pipewire-low-latency
services.pipewire.lowLatency.enable = true;
};
}

View File

@@ -0,0 +1,22 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.gaming.gamescope;
in {
options = {
modules.gaming.gamescope.enable = mkEnableOption "Enables gamescope";
};
config = mkIf cfg.enable {
programs.gamescope = {
enable = true;
capSysNice = true;
args = [
"--rt"
"--expose-wayland"
];
};
};
}

View File

@@ -0,0 +1,18 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.gaming.lutris;
in {
options = {
modules.gaming.lutris.enable = mkEnableOption "Enables lutris";
};
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [
lutris
];
};
}

View File

@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.gaming.steam;
in {
options = {
modules.gaming.steam.enable = mkEnableOption "Enables steam";
};
config = mkIf cfg.enable {
programs = {
steam = {
enable = true;
gamescopeSession.enable = true;
};
};
};
}

View File

@@ -0,0 +1,22 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.gui.gnome;
in {
options = {
modules.gui.gnome.enable = mkEnableOption "Enables gnome";
};
config = mkIf cfg.enable {
services = {
xserver = {
desktopManager.gnome = {
enable = true;
};
};
gnome.games.enable = true;
};
};
}

View File

@@ -0,0 +1,22 @@
{
pkgs,
inputs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.gui.hyprland;
in {
options = {
modules.gui.hyprland.enable = mkEnableOption "Enables hyprland";
};
config = mkIf cfg.enable {
programs.hyprland = {
enable = true;
package = inputs.hyprland.packages.${pkgs.system}.default;
portalPackage = inputs.hyprland.packages.${pkgs.system}.xdg-desktop-portal-hyprland;
};
environment.variables.NIXOS_OZONE_WL = "1";
};
}

View File

@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.hardware.bluetooth;
in {
options = {
modules.hardware.bluetooth.enable = mkEnableOption "Enables bluetooth";
};
config = mkIf cfg.enable {
hardware = {
bluetooth = {
enable = true;
powerOnBoot = false;
};
};
};
}

View File

@@ -0,0 +1,40 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.hardware.graphics.amd;
in {
options = {
modules.hardware.graphics.amd.enable = mkEnableOption "Enables AMD graphics";
};
config = mkIf cfg.enable {
hardware = {
graphics = {
enable = true;
enable32Bit = true;
extraPackages = with pkgs; [
libva
vaapiVdpau
libvdpau-va-gl
amdvlk
# mesa
mesa
# vulkan
# vulkan-tools
# vulkan-loader
# vulkan-validation-layers
# vulkan-extension-layer
];
extraPackages32 = with pkgs.pkgsi686Linux; [
vaapiVdpau
libvdpau-va-gl
];
};
};
};
}

View File

@@ -0,0 +1,39 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.hardware.graphics.nvidia;
in {
options = {
modules.hardware.graphics.nvidia.enable = mkEnableOption "Enables NVidia graphics";
};
config = mkIf cfg.enable {
hardware = {
graphics = {
enable = true;
enable32Bit = true;
extraPackages = with pkgs; [
libva
vaapiVdpau
libvdpau-va-gl
intel-media-driver
nvidia-vaapi-driver
];
};
nvidia = {
package = config.boot.kernelPackages.nvidiaPackages.beta;
# package = config.boot.kernelPackages.nvidiaPackages.stable;
modesetting.enable = true;
powerManagement = {
enable = false;
finegrained = false;
};
open = false;
nvidiaSettings = true;
};
};
};
}

View File

@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.hardware.logitech;
in {
options = {
modules.hardware.logitech.enable = mkEnableOption "Enables logitech";
};
config = mkIf cfg.enable {
hardware = {
logitech.wireless = {
enable = true;
enableGraphical = true;
};
};
};
}

View File

@@ -0,0 +1,48 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption types;
cfg = config.modules.network;
in {
options = {
modules = {
network = {
enable = mkEnableOption "Enable the custom networking module";
hostName = mkOption {
type = types.str;
default = "default-hostname";
description = "Hostname for the system.";
};
interfaces = mkOption {
type = types.attrsOf (types.submodule {
options = {
allowedTCPPorts = mkOption {
type = types.listOf types.int;
default = [];
description = "List of allowed TCP ports for this interface.";
};
};
});
default = {};
description = "Network interface configurations.";
};
};
};
};
config = mkIf cfg.enable {
networking = {
networkmanager.enable = true;
inherit (cfg) hostName;
nftables.enable = true;
firewall = {
enable = true;
inherit (cfg) interfaces;
};
};
};
}

View File

@@ -0,0 +1,29 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption;
cfg = config.modules.studio.blender;
in {
options = {
modules.studio.blender = {
enable = mkEnableOption "Enables Blender";
hip = mkOption {
type = lib.types.bool;
default = false;
description = "Use the HIP-enabled version of Blender (for AMD GPUs).";
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [
(
if cfg.hip
then pkgs.blender-hip
else pkgs.blender
)
];
};
}

View File

@@ -0,0 +1,18 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.studio.gimp;
in {
options = {
modules.studio.gimp.enable = mkEnableOption "Enables gimp";
};
config = mkIf cfg.enable {
environment.systemPackages = [
pkgs.gimp-with-plugins
];
};
}

View File

@@ -0,0 +1,18 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.studio.inkscape;
in {
options = {
modules.studio.inkscape.enable = mkEnableOption "Enables inkscape";
};
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [
inkscape-with-extensions
];
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.blueman;
in {
options = {
modules.sysd.blueman.enable = mkEnableOption "Enables blueman";
};
config = mkIf cfg.enable {
services.blueman.enable = true;
};
}

View File

@@ -0,0 +1,21 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.dbus;
in {
options = {
modules.sysd.dbus.enable = mkEnableOption "Enables dbus";
};
config = mkIf cfg.enable {
services.dbus = {
enable = true;
packages = with pkgs; [
gcr
];
};
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.fwupd;
in {
options = {
modules.sysd.fwupd.enable = mkEnableOption "Enables fwupd";
};
config = mkIf cfg.enable {
services.fwupd.enable = true;
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.gnome-keyring;
in {
options = {
modules.sysd.gnome-keyring.enable = mkEnableOption "Enables gnome-keyring";
};
config = mkIf cfg.enable {
services.gnome.gnome-keyring.enable = true;
};
}

View File

@@ -0,0 +1,30 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.greetd;
in {
options = {
modules.sysd.greetd.enable = mkEnableOption "Enables greetd";
};
config = mkIf cfg.enable {
services.greetd = {
enable = true;
settings = {
# AUTOLOGIN
# initial_session = {
# command = "${pkgs.hyprland}/bin/Hyprland";
# user = "cnst"; # <- select which user to auto-login
# };
default_session = {
command = "${pkgs.greetd.tuigreet}/bin/tuigreet -r --remember-session --asterisks";
user = "greeter";
};
};
};
security.pam.services.greetd.enableGnomeKeyring = true;
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.gvfs;
in {
options = {
modules.sysd.gvfs.enable = mkEnableOption "Enables gvfs";
};
config = mkIf cfg.enable {
services.gvfs.enable = true;
};
}

View File

@@ -0,0 +1,20 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.locate;
in {
options = {
modules.sysd.locate.enable = mkEnableOption "Enables plocate";
};
config = mkIf cfg.enable {
services.locate = {
enable = true;
package = pkgs.plocate;
localuser = null;
};
};
}

View File

@@ -0,0 +1,19 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.mullvad;
in {
options = {
modules.sysd.mullvad.enable = mkEnableOption "Enables mullvad";
};
config = mkIf cfg.enable {
services.mullvad-vpn = {
enable = true;
package = pkgs.mullvad-vpn;
};
};
}

View File

@@ -0,0 +1,24 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.pipewire;
in {
options = {
modules.sysd.pipewire.enable = mkEnableOption "Enables pipewire";
};
config = mkIf cfg.enable {
hardware.pulseaudio.enable = false;
services.pipewire = {
enable = true;
alsa = {
enable = true;
support32Bit = true;
};
pulse.enable = true;
jack.enable = true;
};
};
}

View File

@@ -0,0 +1,18 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.powerd;
in {
options = {
modules.sysd.powerd.enable = mkEnableOption "Enables power-profiles-daemon";
};
config = mkIf cfg.enable {
services = {
power-profiles-daemon.enable = true;
upower.enable = true;
};
};
}

View File

@@ -0,0 +1,32 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.samba;
in {
options = {
modules.sysd.samba.enable = mkEnableOption "Enables samba";
};
config = mkIf cfg.enable {
services = {
samba = {
enable = true;
package = pkgs.samba4Full;
openFirewall = true;
};
avahi = {
publish.enable = true;
publish.userServices = true;
enable = true;
openFirewall = true;
};
samba-wsdd = {
enable = true;
openFirewall = true;
};
};
};
}

View File

@@ -0,0 +1,73 @@
{
config,
lib,
pkgs,
self,
...
}: let
defaultConfig = {
defaultSopsFile = "${self}/secrets/cnix-secrets.yaml";
secrets = {
openai_api_key = {
format = "yaml";
sopsFile = "${self}/secrets/cnix-secrets.yaml";
};
ssh_host = {
format = "yaml";
sopsFile = "${self}/secrets/cnix-secrets.yaml";
};
};
};
hostSpecificConfig = lib.mkMerge [
(lib.mkIf (config.networking.hostName == "toothpc") {
defaultSopsFile = "${self}/secrets/toothpc-secrets.yaml";
secrets = {
openai_api_key = {
format = "yaml";
sopsFile = "${self}/secrets/toothpc-secrets.yaml";
};
ssh_host = {
format = "yaml";
sopsFile = "${self}/secrets/toothpc-secrets.yaml";
};
};
})
(lib.mkIf (config.networking.hostName == "adampad") {
defaultSopsFile = "${self}/secrets/adampad-secrets.yaml";
secrets = {
openai_api_key = {
format = "yaml";
sopsFile = "${self}/secrets/adampad-secrets.yaml";
};
ssh_host = {
format = "yaml";
sopsFile = "${self}/secrets/adampad-secrets.yaml";
};
};
})
];
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.sops;
in {
options = {
modules.sysd.sops.enable = mkEnableOption "Enables sops";
};
config = mkIf cfg.enable {
sops = lib.mkMerge [
{
age = {sshKeyPaths = ["/etc/ssh/ssh_host_ed25519_key"];};
gnupg = {
home = "~/.gnupg";
sshKeyPaths = [];
};
}
defaultConfig
hostSpecificConfig
];
environment.systemPackages = [
pkgs.sops
pkgs.age
];
};
}

View File

@@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.ssh;
in {
options = {
modules.sysd.ssh.enable = mkEnableOption "Enables ssh";
};
config = mkIf cfg.enable {
services.openssh = {
enable = true;
};
programs.ssh = {
startAgent = true;
};
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.udisks;
in {
options = {
modules.sysd.udisks.enable = mkEnableOption "Enables udisks";
};
config = mkIf cfg.enable {
services.udisks2.enable = true;
};
}

View File

@@ -0,0 +1,29 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.xserver.amd;
in {
options = {
modules.sysd.xserver.amd.enable = mkEnableOption "Enables xserver with amdgpu";
};
config = mkIf cfg.enable {
services.xserver = {
enable = true;
videoDrivers = ["amdgpu"];
# xkb = {
# extraLayouts.hhkbse = {
# description = "HHKBse by cnst";
# languages = ["se"];
# symbolsFile = /home/cnst/.nix-config/nixos/hosts/cnix/xkb/symbols/hhkbse;
# };
# layout = "hhkbse";
# # dir = "/home/cnst/.nix-config/nixos/xkb";
# variant = "";
# options = "lv3:rwin_switch";
# };
};
};
}

View File

@@ -0,0 +1,30 @@
{
config,
lib,
hostConfig,
...
}: let
path = "${hostConfig}/cnix/xkb/symbols";
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.xserver.amd.hhkbse;
in {
options = {
modules.sysd.xserver.amd.hhkbse.enable = mkEnableOption "Enables xserver for amdgpu with HHKBSE";
};
config = mkIf cfg.enable {
services.xserver = {
enable = true;
videoDrivers = ["amdgpu"];
xkb = {
extraLayouts.hhkbse = {
description = "HHKBse by cnst";
languages = ["se"];
symbolsFile = "${path}/hhkbse";
};
layout = "hhkbse";
variant = "";
options = "lv3:rwin_switch";
};
};
};
}

View File

@@ -0,0 +1,19 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.sysd.xserver.nvidia;
in {
options = {
modules.sysd.xserver.nvidia.enable = mkEnableOption "Enables xserver with nvidia";
};
config = mkIf cfg.enable {
services.xserver = {
enable = true;
videoDrivers = ["nvidia"];
xkb.layout = "se";
};
};
}

View File

@@ -0,0 +1,15 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.utils.android;
in {
options = {
modules.utils.android.enable = mkEnableOption "Enables android tools";
};
config = mkIf cfg.enable {
programs.adb.enable = true;
};
}

View File

@@ -0,0 +1,18 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.utils.anyrun;
in {
options = {
modules.utils.anyrun.enable = mkEnableOption "Enables anyrun";
};
config = mkIf cfg.enable {
environment.systemPackages = [
pkgs.anyrun
];
};
}

View File

@@ -0,0 +1,21 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.utils.corectrl;
in {
options = {
modules.utils.corectrl.enable = mkEnableOption "Enables CoreCtrl";
};
config = mkIf cfg.enable {
programs.corectrl = {
enable = true;
gpuOverclock = {
enable = true;
ppfeaturemask = "0xffffffff";
};
};
};
}

View File

@@ -0,0 +1,16 @@
{
config,
lib,
inputs,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.utils.microfetch;
in {
options = {
modules.utils.microfetch.enable = mkEnableOption "Enables microfetch";
};
config = mkIf cfg.enable {
environment.systemPackages = [inputs.microfetch.packages.x86_64-linux.default];
};
}

View File

@@ -0,0 +1,103 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.utils.nix-ld;
in {
options = {
modules.utils.nix-ld.enable = mkEnableOption "Enables nix-ld";
};
config = mkIf cfg.enable {
programs.nix-ld = {
enable = true;
# Sets up all the libraries to load
libraries = with pkgs; [
stdenv.cc.cc
openssl
xorg.libXcomposite
xorg.libXtst
xorg.libXrandr
xorg.libXext
xorg.libX11
xorg.libXfixes
libGL
libva
xorg.libxcb
xorg.libXdamage
xorg.libxshmfence
xorg.libXxf86vm
libelf
glib
gtk3
bzip2
xorg.libXinerama
xorg.libXcursor
xorg.libXrender
xorg.libXScrnSaver
xorg.libXi
xorg.libSM
xorg.libICE
gnome2.GConf
nspr
nss
cups
libcap
SDL2
libusb1
dbus-glib
ffmpeg
libudev0-shim
xorg.libXt
xorg.libXmu
libogg
libvorbis
SDL
SDL2_image
glew110
libidn
tbb
flac
freeglut
libjpeg
libpng
libpng12
libsamplerate
libmikmod
libtheora
libtiff
pixman
speex
SDL_image
SDL_ttf
SDL_mixer
SDL2_ttf
SDL2_mixer
libappindicator-gtk2
libdbusmenu-gtk2
libindicator-gtk2
libcaca
libcanberra
libgcrypt
libvpx
librsvg
xorg.libXft
libvdpau
gnome2.pango
cairo
atk
gdk-pixbuf
fontconfig
freetype
dbus
alsaLib
expat
libdrm
mesa
libxkbcommon
];
};
};
}