From b80f1891288280eeba61a248e9fd3d92c11050ea Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 31 Jul 2024 12:11:08 -0400 Subject: [PATCH] Added specific configs from arnarg/config --- hosts/hl-terra1.hardware-configuration.nix | 59 ++++++++++---- hosts/hl-terra1.nix | 18 +--- modules/hl-hardware/default.nix | 6 ++ modules/hl-hardware/fan2go.nix | 95 ++++++++++++++++++++++ modules/main.nix | 4 +- 5 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 modules/hl-hardware/default.nix create mode 100644 modules/hl-hardware/fan2go.nix diff --git a/hosts/hl-terra1.hardware-configuration.nix b/hosts/hl-terra1.hardware-configuration.nix index a044ede..b81f15a 100644 --- a/hosts/hl-terra1.hardware-configuration.nix +++ b/hosts/hl-terra1.hardware-configuration.nix @@ -2,38 +2,69 @@ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: +let + kernel = config.boot.kernelPackages.kernel; + hddled = pkgs.stdenv.mkDerivation rec { + name = "hddled_tmj33-${version}-${kernel.version}"; + version = "0.3"; + src = pkgs.fetchFromGitHub { + owner = "arnarg"; + repo = "hddled_tmj33"; + rev = version; + sha256 = "sha256-sQ8fLK8NP5sHw/9gJTO6lqgWfwmi1G5KDwWuWujNCZw="; + }; + + nativeBuildInputs = kernel.moduleBuildDependencies; + + # We don't want to depmod yet, just build and package the module + preConfigure = '' + sed -i 's|depmod|#depmod|' Makefile + ''; + + makeFlags = [ + "TARGET=${kernel.modDirVersion}" + "KERNEL_MODULES=${kernel.dev}/lib/modules/${kernel.modDirVersion}" + "MODDESTDIR=$(out)/lib/modules/${kernel.modDirVersion}/kernel/drivers/misc" + ]; + }; +in { imports = - [ (modulesPath + "/installer/scan/not-detected.nix") + [ + (modulesPath + "/installer/scan/not-detected.nix") ]; boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "usbhid" "uas" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; - + boot.extraModulePackages = with pkgs.linuxPackages; [ + it87 + hddled + ]; + boot.kernelModules = [ + "kvm-intel" + "coretemp" + "drivetemp" + "it87" + "hddled_tmj33" + ]; fileSystems."/" = - { device = "/dev/disk/by-uuid/a3b275b4-96d4-4eb4-b01f-d80370899791"; + { + device = "/dev/disk/by-uuid/a3b275b4-96d4-4eb4-b01f-d80370899791"; fsType = "ext4"; }; fileSystems."/boot" = - { device = "/dev/disk/by-uuid/AAA7-BCE9"; + { + device = "/dev/disk/by-uuid/AAA7-BCE9"; fsType = "vfat"; options = [ "fmask=0022" "dmask=0022" ]; }; swapDevices = [ ]; - - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking - # (the default) this is the recommended approach. When using systemd-networkd it's - # still possible to use this option, but it's recommended to use it in conjunction - # with explicit per-interface declarations with `networking.interfaces..useDHCP`. networking.useDHCP = lib.mkDefault true; - # networking.interfaces.enp0s21f0u5.useDHCP = lib.mkDefault true; - # networking.interfaces.enp2s0.useDHCP = lib.mkDefault true; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + nix.settings.max-jobs = 2; + powerManagement.cpuFreqGovernor = lib.mkDefault "performance"; } diff --git a/hosts/hl-terra1.nix b/hosts/hl-terra1.nix index a9d11f3..c7a991e 100644 --- a/hosts/hl-terra1.nix +++ b/hosts/hl-terra1.nix @@ -6,22 +6,6 @@ # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - boot.extraModulePackages = with pkgs.linuxPackages; [ it87 ]; - boot.kernelModules = ["coretemp" "it87" "drivetemp"]; -systemd.services.fancontrol = { - enable = true; - description = "Fan control"; - wantedBy = ["multi-user.target" "graphical.target" "rescue.target"]; - - unitConfig = { - Type = "simple"; - }; - - serviceConfig = { - ExecStart = "${pkgs.lm_sensors}/bin/fancontrol"; - Restart = "always"; - }; -}; - + homelab.hardware.fan2go.enable = true; } diff --git a/modules/hl-hardware/default.nix b/modules/hl-hardware/default.nix new file mode 100644 index 0000000..e93bb55 --- /dev/null +++ b/modules/hl-hardware/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = [ + ./fan2go.nix + ]; +} diff --git a/modules/hl-hardware/fan2go.nix b/modules/hl-hardware/fan2go.nix new file mode 100644 index 0000000..9964170 --- /dev/null +++ b/modules/hl-hardware/fan2go.nix @@ -0,0 +1,95 @@ +# Source: https://github.com/arnarg/config/blob/3cfad29004a92d310871a56605aa84df1b13741f/hosts/terra/fan2go.nix +{ lib +, config +, pkgs +, ... +}: +let + cfg = config.homelab.hardware.fan2go; + + fan2goConfig = pkgs.writeText "fan2go.yaml" '' + dbPath: ${cfg.dbPath} + + fans: + - id: out_back + hwmon: + platform: it8613 + rpmChannel: 3 + pwmChannel: 3 + curve: case_max + + sensors: + - id: cpu_package + hwmon: + platform: coretemp + index: 1 + + - id: nvme_ssd + hwmon: + platform: nvme + index: 2 + + - id: hdd + hwmon: + platform: drivetemp + index: 1 + + curves: + - id: cpu_curve + linear: + sensor: cpu_package + steps: + - 40: 0 + - 50: 50 + - 80: 255 + + - id: nvme_curve + linear: + sensor: nvme_ssd + min: 40 + max: 70 + + - id: hdd_curve + linear: + sensor: hdd + min: 30 + max: 50 + + - id: case_max + function: + type: maximum + curves: + - cpu_curve + - nvme_curve + - hdd_curve + ''; +in +{ + options.homelab.hardware.fan2go = with lib; { + enable = mkEnableOption "fan2go"; + + dbPath = mkOption { + type = types.str; + default = "/var/lib/fan2go/fan2go.db"; + description = "The path of the database file."; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.fan2go = { + description = "A simple daemon providing dynamic fan speed control based on temperature sensors."; + wantedBy = [ "multi-user.target" ]; + after = [ "lm_sensors.service" ]; + + serviceConfig = { + ExecStart = lib.concatStringsSep " " [ + "${pkgs.fan2go}/bin/fan2go" + "-c" + "${fan2goConfig}" + "--no-style" + ]; + LimitNOFILE = 8192; + }; + }; + }; +} diff --git a/modules/main.nix b/modules/main.nix index 40f3eee..fdcca76 100644 --- a/modules/main.nix +++ b/modules/main.nix @@ -48,5 +48,7 @@ else [ ]) ++ (if enableNetworkDrives then [ (import ./network-drives.nix) ] else [ ]) - ++ (if enableHomelabServices then [ (import ./hl-services) ] else [ ]); + ++ (if enableHomelabServices then [ (import ./hl-services) ] else [ ]) + ++ (if enableHomelabServices then [ (import ./hl-hardware) ] else [ ]) + ; }