diff --git a/modules/applications/tlp/default.nix b/modules/applications/tlp/default.nix new file mode 100644 index 0000000..19ed304 --- /dev/null +++ b/modules/applications/tlp/default.nix @@ -0,0 +1,128 @@ +{ stdenv +, lib +, checkbashisms +, coreutils +, ethtool +, fetchFromGitHub +, gawk +, gnugrep +, gnused +, hdparm +, iw +, kmod +, makeWrapper +, pciutils +, perl +, shellcheck +, smartmontools +, systemd +, utillinux +# , x86_energy_perf_policy + # RDW only works with NetworkManager, and thus is optional with default off +, enableRDW ? false +, networkmanager +}: stdenv.mkDerivation rec { + pname = "tlp"; + version = "1.3.1"; + + src = fetchFromGitHub { + owner = "linrunner"; + repo = "TLP"; + rev = version; + sha256 = "14fcnaz9pw534v4d8dddqq4wcvpf1kghr8zlrk62r5lrl46sp1p5"; + }; + + # XXX: See patch files for relevant explanations. + patches = [ ./patches/fix-makefile-sed.patch ./patches/tlp-sleep-service.patch ]; + + buildInputs = [ perl ]; + nativeBuildInputs = [ makeWrapper gnused ]; + + # XXX: While [1] states that DESTDIR should not be used, and that the correct + # variable to set is, in fact, PREFIX, tlp thinks otherwise. The Makefile for + # tlp concerns itself only with DESTDIR [2] (possibly incorrectly) and so we set + # that as opposed to PREFIX, despite what [1] says. + # + # [1]: https://github.com/NixOS/nixpkgs/issues/65718 + # [2]: https://github.com/linrunner/TLP/blob/ab788abf4936dfb44fbb408afc34af834230a64d/Makefile#L4-L46 + makeFlags = [ + "DESTDIR=${placeholder "out"}" + + "TLP_NO_INIT=1" + "TLP_WITH_ELOGIND=0" + "TLP_WITH_SYSTEMD=1" + + "TLP_BIN=/bin" + "TLP_CONFDEF=/share/tlp/defaults.conf" + "TLP_FLIB=/share/tlp/func.d" + "TLP_MAN=/share/man" + "TLP_META=/share/metainfo" + "TLP_SBIN=/sbin" + "TLP_SHCPL=/share/bash-completion/completions" + "TLP_TLIB=/share/tlp" + ]; + + installTargets = [ "install-tlp" "install-man" ] + ++ lib.optionals enableRDW [ "install-rdw" "install-man-rdw" ]; + + # XXX: This is disabled because it's basically just noise since upstream + # itself does not seem to care about the zillion shellcheck errors. + doCheck = false; + checkInputs = [ checkbashisms shellcheck ]; + checkTarget = [ "checkall" ]; + + postInstall = let + paths = lib.makeBinPath ( + [ + coreutils + ethtool + gawk + gnugrep + gnused + hdparm + iw + kmod + pciutils + perl + smartmontools + systemd + utillinux + # x86_energy_perf_policy + ] ++ lib.optional enableRDW networkmanager + ); + in + '' + fixup_perl=( + $out/share/tlp/tlp-pcilist + $out/share/tlp/tlp-readconfs + $out/share/tlp/tlp-usblist + $out/share/tlp/tpacpi-bat + ) + for f in "''${fixup_perl[@]}"; do + wrapProgram "$f" --prefix PATH : "${paths}" + done + + fixup_bash=( + $out/bin/* + $out/etc/NetworkManager/dispatcher.d/* + $out/lib/udev/tlp-* + $out/sbin/* + $out/share/tlp/func.d/* + $out/share/tlp/tlp-func-base + ) + for f in "''${fixup_bash[@]}"; do + sed -i '2iexport PATH=${paths}:$PATH' "$f" + done + mkdir -p $out/etc/default + cp ./defaults.conf $out/etc/default/tlp + ''; + + meta = with lib; { + description = "Advanced Power Management for Linux"; + homepage = + "https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html"; + platforms = platforms.linux; + maintainers = with maintainers; [ abbradar lovesegfault ]; + license = licenses.gpl2Plus; + }; +} diff --git a/modules/applications/tlp/patches/fix-makefile-sed.patch b/modules/applications/tlp/patches/fix-makefile-sed.patch new file mode 100644 index 0000000..942c9a5 --- /dev/null +++ b/modules/applications/tlp/patches/fix-makefile-sed.patch @@ -0,0 +1,46 @@ +commit c44347b3b813e209fff537b4d46d23430727a5e2 +Author: Bernardo Meurer +Date: Tue Feb 25 21:27:39 2020 -0800 + + makefile: correctly sed paths + + The default Makefile for tlp makes a mess with catenating `DESTDIR` to + everything, but then not actualy using the catenated (_ prefixed) + variables to sed it's `.in` files. + + This patch makes sure that it correctly sets the paths, taking `DESTDIR` + in account where it makes sense (e.g. /bin where we want $out/bin) but + not where it doesn't (/etc/tlp.conf should be just that). + + The reason DESTDIR is used at all, as opposed to the more appropriate + PREFIX, is covered in the nix formula, and is (also) due to the Makefile + being a bit "different." + +diff --git a/Makefile b/Makefile +index b5af74e..95122df 100644 +--- a/Makefile ++++ b/Makefile +@@ -47,17 +47,17 @@ _TPACPIBAT = $(DESTDIR)$(TPACPIBAT) + + SED = sed \ + -e "s|@TLPVER@|$(TLPVER)|g" \ +- -e "s|@TLP_SBIN@|$(TLP_SBIN)|g" \ +- -e "s|@TLP_TLIB@|$(TLP_TLIB)|g" \ +- -e "s|@TLP_FLIB@|$(TLP_FLIB)|g" \ +- -e "s|@TLP_ULIB@|$(TLP_ULIB)|g" \ ++ -e "s|@TLP_SBIN@|$(_SBIN)|g" \ ++ -e "s|@TLP_TLIB@|$(_TLIB)|g" \ ++ -e "s|@TLP_FLIB@|$(_FLIB)|g" \ ++ -e "s|@TLP_ULIB@|$(_ULIB)|g" \ + -e "s|@TLP_CONFUSR@|$(TLP_CONFUSR)|g" \ + -e "s|@TLP_CONFDIR@|$(TLP_CONFDIR)|g" \ +- -e "s|@TLP_CONFDEF@|$(TLP_CONFDEF)|g" \ ++ -e "s|@TLP_CONFDEF@|$(_CONFDEF)|g" \ + -e "s|@TLP_CONF@|$(TLP_CONF)|g" \ + -e "s|@TLP_RUN@|$(TLP_RUN)|g" \ + -e "s|@TLP_VAR@|$(TLP_VAR)|g" \ +- -e "s|@TPACPIBAT@|$(TPACPIBAT)|g" ++ -e "s|@TPACPIBAT@|$(_TPACPIBAT)|g" + + INFILES = \ + tlp \ diff --git a/modules/applications/tlp/patches/tlp-sleep-service.patch b/modules/applications/tlp/patches/tlp-sleep-service.patch new file mode 100644 index 0000000..b37c728 --- /dev/null +++ b/modules/applications/tlp/patches/tlp-sleep-service.patch @@ -0,0 +1,95 @@ +commit ca94cd56210067e2a55c1f413bd7713f7d338f9f +Author: Bernardo Meurer +Date: Wed Feb 26 10:46:23 2020 -0800 + + tlp-sleep.service: reintroduce + + This patch reintroduces tlp-sleep as a systemd unit as opposed to a + systemd system-sleep hook script. This is due to the recommendation by + systemd itself to not use the hook scripts. As per the manual: + + > Note that scripts or binaries dropped in /usr/lib/systemd/system-sleep/ + > are intended for local use only and should be considered hacks. If + > applications want to react to system suspend/hibernation and resume, + > they should rather use the Inhibitor interface[1]. + +diff --git a/Makefile b/Makefile +index 95122df..0e9230a 100644 +--- a/Makefile ++++ b/Makefile +@@ -70,6 +70,7 @@ INFILES = \ + tlp.rules \ + tlp-readconfs \ + tlp-run-on \ ++ tlp-sleep.service \ + tlp.service \ + tlp-stat \ + tlp.upstart \ +@@ -99,7 +100,6 @@ SHFILES = \ + tlp-rdw-udev.in \ + tlp-rf.in \ + tlp-run-on.in \ +- tlp-sleep \ + tlp-sleep.elogind \ + tlp-stat.in \ + tlp-usb-udev.in +@@ -147,7 +147,7 @@ ifneq ($(TLP_NO_INIT),1) + endif + ifneq ($(TLP_WITH_SYSTEMD),0) + install -D -m 644 tlp.service $(_SYSD)/tlp.service +- install -D -m 755 tlp-sleep $(_SDSL)/tlp ++ install -D -m 644 tlp-sleep.service $(_SYSD)/tlp-sleep.service + endif + ifneq ($(TLP_WITH_ELOGIND),0) + install -D -m 755 tlp-sleep.elogind $(_ELOD)/49-tlp-sleep +@@ -204,7 +204,7 @@ uninstall-tlp: + rm $(_ULIB)/rules.d/85-tlp.rules + rm -f $(_SYSV)/tlp + rm -f $(_SYSD)/tlp.service +- rm -f $(_SDSL)/tlp-sleep ++ rm -f $(_SYSD)/tlp-sleep.service + rm -f $(_ELOD)/49-tlp-sleep + rm -f $(_SHCPL)/tlp-stat + rm -f $(_SHCPL)/bluetooth +diff --git a/tlp-sleep b/tlp-sleep +deleted file mode 100644 +index 3de85ce..0000000 +--- a/tlp-sleep ++++ /dev/null +@@ -1,11 +0,0 @@ +-#!/bin/sh +- +-# tlp - systemd suspend/resume hook +-# +-# Copyright (c) 2020 Thomas Koch and others. +-# This software is licensed under the GPL v2 or later. +- +-case $1 in +- pre) tlp suspend ;; +- post) tlp resume ;; +-esac +diff --git a/tlp-sleep.service.in b/tlp-sleep.service.in +new file mode 100644 +index 0000000..4ac17bd +--- /dev/null ++++ b/tlp-sleep.service.in +@@ -0,0 +1,19 @@ ++# tlp - systemd suspend/resume service ++# ++# Copyright (c) 2020 Thomas Koch and others. ++# This software is licensed under the GPL v2 or later. ++ ++[Unit] ++Description=TLP suspend/resume ++Before=sleep.target ++StopWhenUnneeded=yes ++Documentation=https://linrunner.de/tlp ++ ++[Service] ++Type=oneshot ++RemainAfterExit=yes ++ExecStart=@TLP_SBIN@/tlp suspend ++ExecStop=@TLP_SBIN@/tlp resume ++ ++[Install] ++WantedBy=sleep.target diff --git a/modules/packages.nix b/modules/packages.nix index cbbcf01..bb8379d 100644 --- a/modules/packages.nix +++ b/modules/packages.nix @@ -25,6 +25,8 @@ in { spicetify-cli = pkgs.callPackage ./applications/spicetify-cli.nix { }; + tlp = pkgs.callPackage ./applications/tlp { }; + # spotify-tui = pkgs.callPackage ./applications/spotify-tui.nix { }; # spotify-tui = naersk.buildPackage { diff --git a/nix/sources.json b/nix/sources.json index 7734886..e2efa5c 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -17,10 +17,10 @@ "homepage": "", "owner": "rycee", "repo": "home-manager", - "rev": "f0fe18cd22f8daededa54892f8ba8d363c1ea1d9", - "sha256": "0pi9m95szvrsclj5jizjw35b996fnhr2fvkdapfv14ijkqd5cn0v", + "rev": "3673107bc45810fec1f30b631d81b39d7aa85823", + "sha256": "1f1cgb15y3cxsy6zfx6nzp7lxm4g7nba4x6gfic3vmpk0ksy2g5n", "type": "tarball", - "url": "https://github.com/rycee/home-manager/archive/f0fe18cd22f8daededa54892f8ba8d363c1ea1d9.tar.gz", + "url": "https://github.com/rycee/home-manager/archive/3673107bc45810fec1f30b631d81b39d7aa85823.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "i3lock-fancy-rapid": { @@ -53,10 +53,10 @@ "homepage": "https://mopidy.com", "owner": "mopidy", "repo": "mopidy", - "rev": "292d90b0a8218230f1be1e7a9fbcef15e32c8998", - "sha256": "1n6hgg0xb54vb6rp3f9vs9vzq18ir67454zslyfxhp7ykcqxvv1q", + "rev": "14fa5aa8fc5a23afb686b25979e5f40773462df9", + "sha256": "0i9r2yljbkgzqdfmps8h1jziv5138i6r58wbrjdggf19k1f2yx5j", "type": "tarball", - "url": "https://github.com/mopidy/mopidy/archive/292d90b0a8218230f1be1e7a9fbcef15e32c8998.tar.gz", + "url": "https://github.com/mopidy/mopidy/archive/14fa5aa8fc5a23afb686b25979e5f40773462df9.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "naersk": { @@ -65,10 +65,10 @@ "homepage": "", "owner": "nmattia", "repo": "naersk", - "rev": "11ac47b4cc522dd94dca1320701da69ed2f59b49", - "sha256": "0w10qa4rpbn398qmh4xxb34kibbp0ivz1w4rr6dbh352nb1zfwc2", + "rev": "8ca25122562af4610a9df33e0e0ba64eb26cd64e", + "sha256": "098mqxyasjq2y1wq9njvnfjxkg7gaishh45245m36nhahwgjfdqj", "type": "tarball", - "url": "https://github.com/nmattia/naersk/archive/11ac47b4cc522dd94dca1320701da69ed2f59b49.tar.gz", + "url": "https://github.com/nmattia/naersk/archive/8ca25122562af4610a9df33e0e0ba64eb26cd64e.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { @@ -77,10 +77,10 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "2ecfd86b631714b457e56d70dd83fa60435baeb6", - "sha256": "01j6727cws8blg1npp54b4w6xa0gpgyzhyws2vqgp8clnlnmqqhi", + "rev": "98c74a80934123cb4c3bf3314567f67311eb711a", + "sha256": "1w8n54hapd4x9f1am33icvngkqns7m3hl9yair38yqq08ffwg0kn", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/2ecfd86b631714b457e56d70dd83fa60435baeb6.tar.gz", + "url": "https://github.com/nmattia/niv/archive/98c74a80934123cb4c3bf3314567f67311eb711a.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { @@ -89,10 +89,10 @@ "homepage": "https://github.com/NixOS/nixpkgs", "owner": "NixOS", "repo": "nixpkgs-channels", - "rev": "8130f3c1c2bb0e533b5e150c39911d6e61dcecc2", - "sha256": "154nrhmm3dk5kmga2w5f7a2l6j79dvizrg4wzbrcwlbvdvapdgkb", + "rev": "d96bd3394b734487d1c3bfbac0e8f17465e03afe", + "sha256": "05n27wz5ln9ni5cy5rhjcy612i44gmblkq5m0g827v8pd0nk00da", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/8130f3c1c2bb0e533b5e150c39911d6e61dcecc2.tar.gz", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/d96bd3394b734487d1c3bfbac0e8f17465e03afe.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs-mozilla": { @@ -101,10 +101,10 @@ "homepage": null, "owner": "mozilla", "repo": "nixpkgs-mozilla", - "rev": "36455d54de0b40d9432bba6d8207a5582210b3eb", - "sha256": "0ll0ws3jpidhrcz70hzq1l46y0bbzm87spw03x4zdpacq0n1yqrn", + "rev": "e912ed483e980dfb4666ae0ed17845c4220e5e7c", + "sha256": "08fvzb8w80bkkabc1iyhzd15f4sm7ra10jn32kfch5klgl0gj3j3", "type": "tarball", - "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/36455d54de0b40d9432bba6d8207a5582210b3eb.tar.gz", + "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/e912ed483e980dfb4666ae0ed17845c4220e5e7c.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "spotify-tui": { @@ -113,10 +113,10 @@ "homepage": null, "owner": "Rigellute", "repo": "spotify-tui", - "rev": "e22cda3cde23b7a7b9206284f745ac5192eb371f", - "sha256": "083wazanm3a1fw1lvb594r87djq8rpbib8y0l780vcha8437ymqr", + "rev": "fcde7fe24d48e6038603a725ff20e3330e94061f", + "sha256": "1jb6pp8p56j8rksn3bdmvb96amr9f3a3dx17yasvxjmq9gmjy01q", "type": "tarball", - "url": "https://github.com/Rigellute/spotify-tui/archive/e22cda3cde23b7a7b9206284f745ac5192eb371f.tar.gz", + "url": "https://github.com/Rigellute/spotify-tui/archive/fcde7fe24d48e6038603a725ff20e3330e94061f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "zsh-autosuggestions": {