{ config, lib, pkgs, ... }: { options = { services.amd-uprof = { enable = lib.mkOption { type = lib.types.bool; default = false; description = "Whether to enable AMD uProf."; }; }; }; # Only setup amd-uprof if enabled config = lib.mkIf config.services.amd-uprof.enable { # First make sure that we add the module to the list of available modules # in the kernel matching the same kernel version of this configuration. boot.extraModulePackages = with config.boot.kernelPackages; [ amd-uprof-driver ]; boot.kernelModules = [ "AMDPowerProfiler" ]; # Make the userspace tools available in $PATH. environment.systemPackages = with pkgs; [ amd-uprof ]; # Add extra udev rules to setup the /dev/AMDPowerProfiler device. They # forgot to add these. services.udev.extraRules = let # To create the device node we need to read the device number from the # /proc directory, so the module must have been loaded first. addDevice = pkgs.writeShellScript "add-amd-uprof-dev.sh" '' set -x echo date > /tmp/uprof.log mknod /dev/AMDPowerProfiler -m 666 c $(< /proc/AMDPowerProfiler/device) 0 ''; removeDevice = pkgs.writeShellScript "remove-amd-uprof-dev.sh" '' rm /dev/AMDPowerProfiler ''; in '' KERNEL=="AMDPowerProfiler", SUBSYSTEM=="module", ACTION=="add", RUN+="${addDevice}" KERNEL=="AMDPowerProfiler", SUBSYSTEM=="module", ACTION=="remove", RUN+="${removeDevice}" ''; }; }