feat(nixosmodules): add udisks2

This commit is contained in:
Mohammad Rafiq 2025-04-27 14:39:47 +08:00
parent d816825ac3
commit 0b393ab562
No known key found for this signature in database
6 changed files with 9 additions and 3 deletions

51
modules/nixos/boot.nix Normal file
View file

@ -0,0 +1,51 @@
{
config,
lib,
pkgs,
modulesPath,
...
}:
let
moduleName = "boot-config";
cfg = config."${moduleName}";
in
{
options = {
"${moduleName}" = {
enable = lib.mkEnableOption "Enable ${moduleName}.";
bootloader = lib.mkOption {
type = lib.types.str;
default = "";
example = "systemd-boot";
description = "What bootloader to use.";
};
};
};
config = lib.mkIf cfg.enable {
boot = {
loader =
{
timeout = 5;
efi.canTouchEfiVariables = true;
}
// lib.mkIf (cfg.bootloader == "systemd-boot") {
systemd-boot.enable = true;
systemd-boot.configurationLimit = 5;
};
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
initrd.availableKernelModules = [
"ahci"
"nvme"
"sd_mod"
"usb_storage"
"usbhid"
"xhci_pci"
"rtsx_pci_sdmmc"
];
};
services.dbus = {
enable = true;
};
};
}

24
modules/nixos/default.nix Normal file
View file

@ -0,0 +1,24 @@
{
config,
lib,
...
}:
let
moduleName = "nixosModules";
cfg = config."${moduleName}";
in
{
imports = [
./boot.nix
./hardware.nix
./nix-config.nix
];
options = {
"${moduleName}" = {
enable = lib.mkEnableOption "Enable ${moduleName}.";
};
};
config = lib.mkIf cfg.enable { };
}

View file

@ -0,0 +1,87 @@
{
config,
lib,
pkgs,
...
}:
let
moduleName = "hardware-config";
cfg = config."${moduleName}";
in
{
options = {
"${moduleName}" = {
cpu = lib.mkOption {
type = lib.types.str;
default = "";
example = "amd";
description = "What CPU is being used.";
};
gpu = lib.mkOption {
type = lib.types.str;
default = "";
example = "nvidia";
description = "What GPU is being used.";
};
usbAutoMount = lib.mkEnableOption "Enable auto mounting USB drives.";
};
};
config = lib.mkMerge [
(lib.mkIf (cfg.cpu != "") {
nixpkgs.hostPlatform = lib.mkIf (cfg.cpu == "amd" || cfg.cpu == "intel") "x86_64-linux";
# CPU Settings
boot.kernelModules =
lib.optionals (cfg.cpu == "intel") [ "kvm-intel" ]
++ lib.optionals (cfg.cpu == "amd") [ "kvm-amd" ];
hardware.cpu =
lib.mkIf (cfg.cpu == "intel") { intel.updateMicrocode = true; }
// lib.mkIf (cfg.cpu == "amd") { amd.updateMicrocode = true; };
})
(lib.mkIf (cfg.gpu == "nvidia") {
# Accept the license by default; needed for some packages.
nixpkgs.config.nvidia.acceptLicense = true;
nix.settings = {
substituters = [ "https://cuda-maintainers.cachix.org" ];
trusted-public-keys = [
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
];
};
services.xserver.videoDrivers = [ "nvidia" ];
environment.variables = {
GBM_BACKEND = "nvidia-drm";
LIBVA_DRIVER_NAME = "nvidia";
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
};
hardware = {
enableRedistributableFirmware = true;
nvidia-container-toolkit.enable = true;
graphics = {
enable = true;
extraPackages = with pkgs; [
nvidia-vaapi-driver # hardware acceleration
];
};
nvidia = {
modesetting.enable = true;
open = false;
nvidiaSettings = true;
nvidiaPersistenced = true;
package = config.boot.kernelPackages.nvidiaPackages.latest;
};
};
boot.initrd.availableKernelModules = [
"nvidia"
"nvidia_modeset"
"nvidia_uvm"
"nvidia_drm"
];
})
(lib.mkIf cfg.usbAutoMount {
services.udisks2 = {
enable = true;
mountOnMedia = true;
};
})
];
}

View file

@ -0,0 +1,45 @@
{
config,
lib,
pkgs,
...
}:
let
moduleName = "nix-config";
cfg = config."${moduleName}";
in
{
options = {
"${moduleName}" = {
enable = lib.mkEnableOption "Enable ${moduleName}.";
};
};
config = lib.mkIf cfg.enable {
system.stateVersion = "24.11";
nixpkgs.config.allowUnfree = true;
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
"pipe-operators"
];
trusted-users = [ "@wheel" ];
# Add binary caches to avoid having to compile them
substituters = [
"https://cache.nixos.org"
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
programs.nix-ld.enable = true;
};
}