From cf8457d3cc61d2b35a75250e2f76bba0cc9ef960 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Sun, 26 May 2019 23:24:45 +0100 Subject: [PATCH 1/2] throttled: init at 0.6 --- pkgs/tools/system/throttled/default.nix | 43 +++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 45 insertions(+) create mode 100644 pkgs/tools/system/throttled/default.nix diff --git a/pkgs/tools/system/throttled/default.nix b/pkgs/tools/system/throttled/default.nix new file mode 100644 index 000000000000..4f52b5e09455 --- /dev/null +++ b/pkgs/tools/system/throttled/default.nix @@ -0,0 +1,43 @@ +{ stdenv, fetchFromGitHub, python3Packages }: + +stdenv.mkDerivation rec { + pname = "throttled"; + version = "0.6"; + + src = fetchFromGitHub { + owner = "erpalma"; + repo = pname; + rev = "v${version}"; + sha256 = "1icb2288pj25vbdnd16zvisw9c01hp8vkk25ilkc74gy76xhpcs4"; + }; + + nativeBuildInputs = [ python3Packages.wrapPython ]; + + pythonPath = with python3Packages; [ + configparser + dbus-python + pygobject3 + ]; + + # The upstream unit both assumes the install location, and tries to run in a virtualenv + postPatch = ''sed -e 's|ExecStart=.*|ExecStart=${placeholder "out"}/bin/lenovo_fix.py|' -i systemd/lenovo_fix.service''; + + installPhase = '' + runHook preInstall + install -D -m755 -t $out/bin lenovo_fix.py + install -D -t $out/bin lenovo_fix.py mmio.py + install -D -m644 -t $out/etc etc/* + install -D -m644 -t $out/lib/systemd/system systemd/* + runHook postInstall + ''; + + postFixup = ''wrapPythonPrograms''; + + meta = with stdenv.lib; { + description = "Fix for Intel CPU throttling issues"; + homepage = https://github.com/erpalma/throttled; + license = licenses.mit; + platforms = [ "x86_64-linux" ]; + maintainers = with maintainers; [ michaelpj ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6246cc4a5fb5..8b6465926b3b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23749,6 +23749,8 @@ in thermald = callPackage ../tools/system/thermald { }; + throttled = callPackage ../tools/system/throttled { }; + thinkfan = callPackage ../tools/system/thinkfan { }; tup = callPackage ../development/tools/build-managers/tup { }; From efbd890f991c36f53dfd08f3229952e17fb95d4f Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Sun, 26 May 2019 23:31:55 +0100 Subject: [PATCH 2/2] nixos: add throttled service --- nixos/modules/module-list.nix | 1 + nixos/modules/services/hardware/throttled.nix | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 nixos/modules/services/hardware/throttled.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 49b5076aefde..efbd0154eb6a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -325,6 +325,7 @@ ./services/hardware/tcsd.nix ./services/hardware/tlp.nix ./services/hardware/thinkfan.nix + ./services/hardware/throttled.nix ./services/hardware/trezord.nix ./services/hardware/triggerhappy.nix ./services/hardware/u2f.nix diff --git a/nixos/modules/services/hardware/throttled.nix b/nixos/modules/services/hardware/throttled.nix new file mode 100644 index 000000000000..cd5b01450e44 --- /dev/null +++ b/nixos/modules/services/hardware/throttled.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.throttled; +in { + options = { + services.throttled = { + enable = mkEnableOption "fix for Intel CPU throttling"; + }; + }; + + config = mkIf cfg.enable { + systemd.packages = [ pkgs.throttled ]; + # The upstream package has this in Install, but that's not enough, see the NixOS manual + systemd.services."lenovo_fix".wantedBy = [ "multi-user.target" ]; + + environment.etc."lenovo_fix.conf".source = "${pkgs.throttled}/etc/lenovo_fix.conf"; + }; +}