diff --git a/README.md b/README.md index 14566638..9f3597a1 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ Nix deployment related stuff. * samhain - Desktop. * yule - Laptop. * litha - Relatively unused netbook. -* mabon - Relatively unused Thinkpad t61p. ## To-do diff --git a/configuration/hosts/beltane/services/nginx.nix b/configuration/hosts/beltane/services/nginx.nix index 030a5c88..000e91fe 100644 --- a/configuration/hosts/beltane/services/nginx.nix +++ b/configuration/hosts/beltane/services/nginx.nix @@ -77,7 +77,7 @@ let common = { }; }; } // common; - }; + } // secrets.beltane-protected; }; security.acme = { diff --git a/configuration/hosts/mabon/configuration.nix b/configuration/hosts/mabon/configuration.nix deleted file mode 100644 index 98853b20..00000000 --- a/configuration/hosts/mabon/configuration.nix +++ /dev/null @@ -1,34 +0,0 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running ‘nixos-help’). - -{ config, pkgs, ... }: - -{ - imports = [ # Include the results of the hardware scan. - ./hardware-configuration.nix - ../../profiles/common - ../../profiles/desktop - ../../profiles/xfce - ../../profiles/network - ../../profiles/yubikey - ]; - - # Use the GRUB 2 boot loader. - boot.loader.grub.enable = true; - boot.loader.grub.version = 2; - boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only - - networking.hostName = "mabon"; # Define your hostname. - - networking.useDHCP = false; - networking.interfaces.enp0s25.useDHCP = true; - networking.interfaces.wls3.useDHCP = true; - - # Enable the OpenSSH daemon. - services.openssh.enable = true; - - system.stateVersion = "20.09"; # Did you read the comment? - -} - diff --git a/configuration/hosts/mabon/hardware-configuration.nix b/configuration/hosts/mabon/hardware-configuration.nix deleted file mode 100644 index a164db9b..00000000 --- a/configuration/hosts/mabon/hardware-configuration.nix +++ /dev/null @@ -1,32 +0,0 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ -# and may be overwritten by future invocations. Please make changes -# to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs, modulesPath, ... }: - -{ - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - - boot.initrd.availableKernelModules = [ - "uhci_hcd" - "ehci_pci" - "ata_piix" - "ahci" - "firewire_ohci" - "usb_storage" - "sd_mod" - "sdhci_pci" - ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = { - device = "/dev/disk/by-uuid/05829271-4036-4d81-85b0-cd8c8197d40f"; - fsType = "ext4"; - }; - - swapDevices = - [{ device = "/dev/disk/by-uuid/aacb9f81-bc7a-46f9-8cac-04942d078318"; }]; - - networking.enableIntel3945ABGFirmware = true; -} diff --git a/configuration/hosts/samhain/configuration.nix b/configuration/hosts/samhain/configuration.nix index 15ce935c..0d489032 100644 --- a/configuration/hosts/samhain/configuration.nix +++ b/configuration/hosts/samhain/configuration.nix @@ -12,6 +12,7 @@ ../../profiles/network ../../profiles/yubikey ./services/nginx.nix + ./services/thermal/thermal.nix ./services/torrenting.nix ]; diff --git a/configuration/hosts/samhain/hardware-configuration.nix b/configuration/hosts/samhain/hardware-configuration.nix index 2a87f839..001d5649 100644 --- a/configuration/hosts/samhain/hardware-configuration.nix +++ b/configuration/hosts/samhain/hardware-configuration.nix @@ -36,11 +36,6 @@ fsType = "xfs"; }; - fileSystems."/rpool" = { - device = "rpool"; - fsType = "zfs"; - }; - fileSystems."/disks/pool-raw" = { device = "zstore/raw"; fsType = "zfs"; diff --git a/configuration/hosts/samhain/services/thermal/kaede-power.sh b/configuration/hosts/samhain/services/thermal/kaede-power.sh new file mode 100644 index 00000000..b674aeca --- /dev/null +++ b/configuration/hosts/samhain/services/thermal/kaede-power.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +################################################################################ +# Written by Kaede Fox + +########## +# Default governor, currently required to be "conservative". +METHOD=conservative + +# Configuration parameters. +SCALE_UP=40 +SCALE_DOWN=30 +SCALE_STEP=1 +SAMPLING_RATE=10000 +SAMPLING_FACTOR=10 +NO_NICE=1 + +########## +script_name=`basename $0` + +case "$1" in + "start") + modprobe cpufreq_conservative + modprobe cpufreq_ondemand + + # This also needs to be loaded, in case the service is stopped later + # we can fall back to it. + modprobe cpufreq_performance + + # The governor must be selected for its relevant configuration entries + # to appear in sysfs. + cpupower frequency-set -g $METHOD + sleep .5s + + CONFIG=/sys/devices/system/cpu/cpufreq/$METHOD + chmod $CONFIG 644 + echo $SCALE_UP > $CONFIG/up_threshold + echo $SCALE_DOWN > $CONFIG/down_threshold + echo $SCALE_STEP > $CONFIG/freq_step + echo $SAMPLING_RATE > $CONFIG/sampling_rate + echo $SAMPLING_FACTOR > $CONFIG/sampling_down_factor + echo $NO_NICE > $CONFIG/ignore_nice_load + sleep .5s + + # Force reload all configuration. + cpupower frequency-set -g $METHOD + echo "enabled cpupower" + + echo "loaded ${script_name}" + ;; + "stop") + cpupower frequency-set -g performance && + echo "disabled cpupower" & + wait + + sleep .5s + modprobe -r cpufreq_conservative + modprobe -r cpufreq_ondemand + + echo "unloaded ${script_name}" + ;; + *) + echo "Usage: ${script_name} (start | stop)" + exit 1 + ;; +esac \ No newline at end of file diff --git a/configuration/hosts/samhain/services/thermal/kaede-thermald.xml b/configuration/hosts/samhain/services/thermal/kaede-thermald.xml new file mode 100644 index 00000000..fc9f81fb --- /dev/null +++ b/configuration/hosts/samhain/services/thermal/kaede-thermald.xml @@ -0,0 +1,308 @@ + + + + + + + + AMD Ryzen 5 3600 6-Core Processor + * + * + quiet + + + + CPU_TEMP_CORE + /var/cache/kaede-thermals/cpu_core_temp + 1 + + + + GPU_TEMP + /var/cache/kaede-thermals/gpu_temp + 1 + + + + + CPU_CTRL + + + + + CPU_TEMP_CORE + 70000 + passive + parallel + + 1 + CPU_FREQ0 + 100 + 1 + + + 2 + CPU_FREQ1 + 100 + 1 + + + 3 + CPU_FREQ2 + 100 + 1 + + + 4 + CPU_FREQ3 + 100 + 1 + + + 5 + CPU_FREQ4 + 100 + 1 + + + 6 + CPU_FREQ5 + 100 + 1 + + + 7 + CPU_FREQ6 + 100 + 1 + + + 8 + CPU_FREQ7 + 100 + 1 + + + 9 + CPU_FREQ8 + 100 + 1 + + + 10 + CPU_FREQ9 + 100 + 1 + + + 11 + CPU_FREQ10 + 100 + 1 + + + 12 + CPU_FREQ11 + 100 + 1 + + + + + + + CPU_TEMP_CORE + 85000 + hot + + + CPU_TEMP_CORE + 90000 + critical + + + + + GPU_CTRL + + + + + GPU_TEMP + 70000 + passive + parallel + + 1 + GPU_FREQ_CORE + 50 + 1 + + + 2 + GPU_FREQ_MEM + 50 + 1 + + + + + + + + + + + CPU_FREQ0 + /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ1 + /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ2 + /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ3 + /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ4 + /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ5 + /sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ6 + /sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ7 + /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ8 + /sys/devices/system/cpu/cpu8/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ9 + /sys/devices/system/cpu/cpu9/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ10 + /sys/devices/system/cpu/cpu10/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + CPU_FREQ11 + /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + 3600000 + 2200000 + -100000 + 1 + 1 + 10 + + + + + GPU_FREQ_CORE + /var/cache/kaede-thermals/gpu_power_core + 255 + 0 + -5 + + 0 + 1 + 10 + + + + + GPU_FREQ_MEM + /var/cache/kaede-thermals/gpu_power_mem + 255 + 0 + -5 + 0 + 1 + 10 + + + + + diff --git a/configuration/hosts/samhain/services/thermal/kaede-thermals.sh b/configuration/hosts/samhain/services/thermal/kaede-thermals.sh new file mode 100644 index 00000000..f5eb9329 --- /dev/null +++ b/configuration/hosts/samhain/services/thermal/kaede-thermals.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +################################################################################ +# Written by Kaede Fox + +########## +# thermald can't handle hwmon* moving around, so we use symlinks to resolve +# dynamic paths to static paths. +THERMAL_PATH="/var/cache/kaede-thermals" + +# CPU sensor paths. +CPU_SENSOR_CORE="/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon*/temp1_input" +#CPU_SENSOR_SOCKET="/sys/devices/platform/nct6775.656/hwmon/hwmon*/temp2_input" + +# GPU control and sensor paths (using amdgpu). +GPU_CONTROL="/sys/class/drm/card0/device/" +GPU_SENSOR="/sys/class/drm/card0/device/hwmon/hwmon*/temp1_input" + +# WARNING: MAKE ABSOLUTELY SURE THESE ARE THE PERFORMANCE STATES AND NOT THE +# ACTUAL CORE/MEM CLOCKS OR WE COULD DAMAGE THE HARDWARE. +GPUCTRL_CORECLK="${GPU_CONTROL}/pp_dpm_sclk" +GPUCTRL_MEMCLK="${GPU_CONTROL}/pp_dpm_mclk" + +# How often to resolve paths (in seconds). Changes are extremely rare, but they +# can occur even while the system is booted. +INTERVAL='300' +# How often to update GPU power settings from thermald. +TIMESLICE='1' + +# Formatter used to round floats to integers via printf. +float_to_int='%'\''.0f' + +########## +script_name=`basename $0` + +# Our simple path resolver subroutine, which uses ls to replace hwmon* with +# whichever hwmon is currently active. +sub_resolve_paths() { + ln -s -f "`ls $CPU_SENSOR_CORE`" "./cpu_core_temp" +# ln -s -f "`ls $CPU_SENSOR_SOCKET`" "./cpu_socket_temp" + ln -s -f "`ls $GPU_SENSOR`" "./gpu_temp" +} + +case "$1" in + "start") + echo "loaded ${script_name}" + + mkdir -p "$THERMAL_PATH" 2>/dev/null + cd "$THERMAL_PATH" + + # Switch the video driver into manual control mode for + # performance levels. + echo "manual" >${GPU_CONTROL}/power_dpm_force_performance_level + echo "enabled gpupower" + + # Immediately resolve paths at startup. + sub_resolve_paths + + # Followed by starting thermald in case the paths didn't + # exist, which would've made it fail to start. + sleep .5s + systemctl start thermald + + # thermald will create these files with the wrong permissions. + rm "./gpu_power_core"; printf "%d\n" '-1'>./gpu_power_core + rm "./gpu_power_mem"; printf "%d\n" '-1'>./gpu_power_mem + + # Enter service mode. + slice_counter='0' + while true; do + # Execute a timeslice. Paths are updated every time the + # counter wraps around. + slice_counter=$((slice_counter + TIMESLICE)) + if [ "$slice_counter" -ge "$INTERVAL" ]; then + #printf "DEBUG: *** Updating paths after %d seconds ***\n" "$slice_counter" + slice_counter=$((slice_counter - INTERVAL)) + + # Resolve paths. + sub_resolve_paths + fi + + # Read GPU thermal settings from thermald and apply + # them to the driver via sysfs. + # + # The core and memory clock lists are highly specific + # to the hardware, and need updating if the video card + # is ever changed. + # + gpu_power_core="`cat ./gpu_power_core`" + gpu_power_mem="`cat ./gpu_power_mem`" + if [ -z "$gpu_power_core" ]; then gpu_power_core='-1'; fi + if [ -z "$gpu_power_mem" ]; then gpu_power_mem='-1'; fi + + # Check if we need to update the core clock. + if [ "$gpu_power_core" -ge '0' ]; then + #printf "DEBUG: *** Updating GPU core clock ***\n" + printf "%d\n" '-1'>./gpu_power_core + printf "$gpu_power_core\n">./gpu_power_core_cached + + core_count_f="$(echo "$gpu_power_core" | awk '{ x=(($1/255.0)*(7-1))+1; printf("%f",x) }')" + core_count="$(printf "$float_to_int" "$core_count_f")" + if [ "$core_count" -lt '1' ]; then core_count='1'; fi + if [ "$core_count" -gt '7' ]; then core_count='7'; fi + + gpu_list_core="1" + for ((i=2; i<=core_count; i++)); do + gpu_list_core="$gpu_list_core $i"; done + + echo "$gpu_list_core" >${GPUCTRL_CORECLK} + + #echo "dbg: gpu_power_core: $gpu_power_core" + #echo "dbg: core_count_f: $core_count_f, core_count: $core_count" + #echo "dbg: gpu_list_core: $gpu_list_core" + fi + + # Check if we need to update the memory clock. + if [ "$gpu_power_mem" -ge '0' ]; then + #printf "DEBUG: *** Updating GPU memory clock ***\n" + printf "%d\n" '-1'>./gpu_power_mem + printf "$gpu_power_mem\n">./gpu_power_mem_cached + + mem_count_f="$(echo "$gpu_power_mem" | awk '{ x=(($1/255.0)*(3-1))+1; printf("%f",x) }')" + mem_count="$(printf "$float_to_int" "$mem_count_f")" + if [ "$mem_count" -lt '1' ]; then mem_count='1'; fi + if [ "$mem_count" -gt '3' ]; then mem_count='3'; fi + + gpu_list_mem="1" + for ((i=2; i<=mem_count; i++)); do + gpu_list_mem="$gpu_list_mem $i"; done + + echo "$gpu_list_mem" >${GPUCTRL_MEMCLK} + + #echo "dbg: gpu_power_mem: $gpu_power_mem" + #echo "dbg: mem_count_f: $mem_count_f, mem_count: $mem_count" + #echo "dbg: gpu_list_mem: $gpu_list_mem" + fi + + # Sleep until the next cycle. + sleep "${TIMESLICE}s" + done + ;; + "stop") + # Reset all performance level tunings. + echo "1 2 3 4 5 6 7" >${GPUCTRL_CORECLK} + echo "1 2 3" >${GPUCTRL_MEMCLK} + # Switch the video driver into automatic control mode for + # performance levels. + echo "auto" >${GPU_CONTROL}/power_dpm_force_performance_level + echo "disabled gpupower" + + sleep .5s + echo "unloaded ${script_name}" + ;; + *) + echo "Usage: ${script_name} (start | stop)" + exit 1 + ;; +esac \ No newline at end of file diff --git a/configuration/hosts/samhain/services/thermal/thermal.nix b/configuration/hosts/samhain/services/thermal/thermal.nix new file mode 100644 index 00000000..2eb0903e --- /dev/null +++ b/configuration/hosts/samhain/services/thermal/thermal.nix @@ -0,0 +1,55 @@ +{ config, pkgs, ... }: + +{ + boot.kernelParams = [ "amdgpu.ppfeaturemask=0xffffffff" ]; + powerManagement = { + enable = true; + cpuFreqGovernor = "conservative"; + }; + systemd = { + services = { + kaede-thermals = let kaede-thermals-script = pkgs.writeScriptBin "script" (builtins.readFile ./kaede-thermals.sh); in { + wantedBy = [ "multi-user.target" ]; + path = [pkgs.bash pkgs.coreutils-full]; + serviceConfig = { + RemainAfterExit = "no"; + Type = "simple"; + ExecStart = "${kaede-thermals-script}/bin/script start"; + ExecStop = "${kaede-thermals-script}/bin/script stop"; + User = "root"; + }; + }; + kaede-power = let kaede-power-script = pkgs.writeScriptBin "script" (builtins.readFile ./kaede-power.sh); in { + wantedBy = [ "multi-user.target" ]; + path = [pkgs.bash pkgs.linuxPackages.cpupower]; + serviceConfig = { + RemainAfterExit = "yes"; + Type = "oneshot"; + ExecStart = "${kaede-power-script}/bin/script start"; + ExecStop = "${kaede-power-script}/bin/script stop"; + User = "root"; + }; + }; + }; + }; + services.thermald = let cfg_file = pkgs.writeTextFile { + name = "cfg"; + text = (builtins.readFile ./kaede-thermald.xml); + }; in { + enable = true; + configFile = "${cfg_file}"; + }; +} + +/* +[Service] +Type=simple +RemainAfterExit=no +User=root + +ExecStart=/etc/systemd/system/kaede-thermals.script start +ExecStop=/etc/systemd/system/kaede-thermals.script stop + +[Install] +WantedBy=multi-user.target +*/ \ No newline at end of file diff --git a/configuration/profiles/xfce/default.nix b/configuration/profiles/xfce/default.nix index 5f55f3ad..752fb2da 100644 --- a/configuration/profiles/xfce/default.nix +++ b/configuration/profiles/xfce/default.nix @@ -15,6 +15,7 @@ pkgs.xfce.xfce4-sensors-plugin pkgs.xfce.xfce4-pulseaudio-plugin pkgs.xfce.xfce4-whiskermenu-plugin + pkgs.xfce.xfce4-genmon-plugin pkgs.xfce.xfce4-screenshooter pkgs.xfce.thunar-volman ];