Modularize hardware config and remove specific nix folder

This commit is contained in:
DashieTM 2024-07-20 01:56:54 +02:00
parent a5042bb645
commit 9ac5b25036
72 changed files with 322 additions and 100 deletions

View file

@ -0,0 +1,18 @@
{ lib, config, options, ... }: {
options.mods = {
acpid.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables acpid.
'';
};
};
config = lib.mkIf config.mods.acpid.enable (lib.optionalAttrs (options?virtualisation.virtualbox.host) {
services.acpid.enable = true;
});
}

View file

@ -0,0 +1,20 @@
{ lib, config, options, ... }: {
options.mods = {
bluetooth.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables bluetooth.
'';
};
};
config = lib.mkIf config.mods.bluetooth.enable (lib.optionalAttrs (options?hardware.bluetooth) {
hardware.bluetooth = {
enable = true;
powerOnBoot = true;
};
});
}

View file

@ -0,0 +1,11 @@
{
imports = [
./virtualbox.nix
./kde_connect.nix
./gpu.nix
./xone.nix
./drives.nix
./bluetooth.nix
./acpid.nix
];
}

View file

@ -0,0 +1,69 @@
{ lib, config, options, ... }:
let
driveModule = lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
description = ''
The path of the drive.
Note that a / is already added at the beginning.
'';
default = "";
example = "drive2";
};
drive = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
description = "The attrs of the drive";
default = { };
example = {
device = "/dev/disk/by-label/DRIVE2";
fsType = "ext4";
options = [
"noatime"
"nodiratime"
"discard"
];
};
};
};
};
in
{
options.mods = {
extraDrives =
lib.mkOption {
default = [ ];
example = [
{
name = "drive2";
drive = {
device = "/dev/disk/by-label/DRIVE2";
fsType = "ext4";
options = [
"noatime"
"nodiratime"
"discard"
];
};
}
];
# TODO: how to make this work
# type = with lib.types; listOf (attrsOf driveModule);
type = with lib.types; listOf (attrsOf anything);
description = ''
Extra drives to add.
'';
};
};
config = (lib.optionalAttrs (options?fileSystems) {
fileSystems = builtins.listToAttrs
(map
({ name, drive }: {
name = "/" + name;
value = drive;
})
config.mods.extraDrives);
});
}

63
modules/programs/gpu.nix Normal file
View file

@ -0,0 +1,63 @@
{ lib, config, options, pkgs, ... }: {
options.mods = {
amdgpu.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables amdgpu support.
'';
};
vapi = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables vapi.
'';
};
rocm.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables rocm support.
'';
};
};
};
config = lib.mkIf config.mods.vapi.enable
(lib.optionalAttrs
(options?hardware.graphics)
{
boot = lib.mkIf config.mods.amdgpu.enable {
kernelModules = [ "kvm-amd" ];
initrd.kernelModules = [ "amdgpu" ];
kernelParams = [
"amdgpu.ppfeaturemask=0xffffffff"
];
};
hardware = {
graphics =
let
base_packages = [
pkgs.libvdpau-va-gl
pkgs.vaapiVdpau
];
rocm_packages = [
pkgs.rocmPackages.clr.icd
pkgs.rocm-opencl-runtime
];
in
{
enable = true;
enable32Bit = lib.mkDefault true;
extraPackages = base_packages ++
(lib.lists.optionals config.mods.vapi.rocm.enable rocm_packages);
};
};
});
}

View file

@ -0,0 +1,30 @@
{ lib, config, options, pkgs, ... }: {
options.mods = {
kde_connect.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables kde_connect.
'';
};
};
config = lib.mkIf config.mods.kde_connect.enable
(lib.optionalAttrs (options?networking.firewall)
{
networking.firewall = {
allowedTCPPortRanges = [
{ from = 1714; to = 1764; } # KDE Connect
];
allowedUDPPortRanges = [
{ from = 1714; to = 1764; } # KDE Connect
];
};
} // lib.optionalAttrs (options?home.packages) {
home.packages = with pkgs; [
kdeconnect
];
});
}

View file

@ -0,0 +1,17 @@
{ lib, config, options, ... }: {
options.mods = {
virtualbox.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables virtualbox.
'';
};
};
config = lib.optionalAttrs (options?virtualisation.virtualbox.host) {
virtualisation.virtualbox.host.enable = lib.mkIf config.mods.virtualbox.enable true;
};
}

17
modules/programs/xone.nix Normal file
View file

@ -0,0 +1,17 @@
{ lib, config, options, ... }: {
options.mods = {
xone.enable = lib.mkOption {
default = false;
type = lib.types.bool;
example = true;
description = ''
Enables the xone driver for xbox controllers.
'';
};
};
config = lib.optionalAttrs (options?hardware) {
hardware.xone.enable = true;
};
}