From 5a48afacccb6ffe3ecfdee5b2e99bcb7d6031420 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Fri, 10 May 2024 17:02:24 +0200 Subject: [PATCH] tlpui patch -> overlay --- custom/tlpui/package.nix | 70 ++++++++++++++++++++++++++++++++++++++++ custom/tlpui/path.patch | 57 ++++++++++++++++++++++++++++++++ fake_flake.nix | 10 +++--- overlays/default.nix | 1 + overlays/tlpui.nix | 4 +++ 5 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 custom/tlpui/package.nix create mode 100644 custom/tlpui/path.patch create mode 100644 overlays/tlpui.nix diff --git a/custom/tlpui/package.nix b/custom/tlpui/package.nix new file mode 100644 index 0000000..e1c5a1e --- /dev/null +++ b/custom/tlpui/package.nix @@ -0,0 +1,70 @@ +{ + cairo, + fetchFromGitHub, + gobject-introspection, + gtk3, + lib, + pciutils, + python3Packages, + substituteAll, + tlp, + usbutils, + wrapGAppsHook, +}: +python3Packages.buildPythonPackage rec { + pname = "tlpui"; + version = "1.6.5"; + pyproject = true; + + src = fetchFromGitHub { + owner = "d4nj1"; + repo = "TLPUI"; + rev = "refs/tags/tlpui-${version}"; + hash = "sha256-pgzGhf2WDRNQ2z0hPapUJA5MLTKq92UlgjC+G78T/4s="; + }; + + patches = [ + (substituteAll { + src = ./path.patch; + inherit tlp; + }) + ]; + + # ignore test/test_tlp_settings.py asit relies on opening a gui which is non-trivial + pytestFlagsArray = [ "--ignore=test/test_tlp_settings.py" ]; + nativeCheckInputs = [ + gobject-introspection + python3Packages.pytestCheckHook + ]; + + build-system = [ + wrapGAppsHook + python3Packages.poetry-core + ]; + + buildInputs = [ tlp ]; + + dependencies = [ + gobject-introspection + gtk3 + pciutils + python3Packages.pycairo + python3Packages.pygobject3 + python3Packages.pyyaml + usbutils + ]; + + meta = { + changelog = "https://github.com/d4nj1/TLPUI/releases/tag/tlpui-${version}"; + description = "A GTK user interface for TLP written in Python"; + homepage = "https://github.com/d4nj1/TLPUI"; + license = lib.licenses.gpl2Only; + longDescription = '' + The Python scripts in this project generate a GTK-UI to change TLP configuration files easily. + It has the aim to protect users from setting bad configuration and to deliver a basic overview of all the valid configuration values. + ''; + platforms = lib.platforms.linux; + mainProgram = "tlpui"; + maintainers = with lib.maintainers; [ grimmauld ]; + }; +} diff --git a/custom/tlpui/path.patch b/custom/tlpui/path.patch new file mode 100644 index 0000000..2eeee28 --- /dev/null +++ b/custom/tlpui/path.patch @@ -0,0 +1,57 @@ +diff --git a/tlpui/file.py b/tlpui/file.py +index f0f3ecb..a9ad7f8 100644 +--- a/tlpui/file.py ++++ b/tlpui/file.py +@@ -26,7 +26,7 @@ def get_tlp_config_defaults(tlpversion: str): + tlpconfig_defaults = extract_default_tlp_configs(f"{settings.workdir}/defaults/tlp-{tlpversion}.conf") + + # update default values with intrinsic ones +- intrinsic_defaults_path = f"{settings.FOLDER_PREFIX}/usr/share/tlp/defaults.conf" ++ intrinsic_defaults_path = f"@tlp@/share/tlp/defaults.conf" + tlpconfig_defaults.update(extract_default_tlp_configs(intrinsic_defaults_path)) + + return tlpconfig_defaults +@@ -124,7 +124,10 @@ def create_tmp_tlp_config_file(changedproperties: dict) -> str: + filehandler, tmpfilename = mkstemp(dir=settings.TMP_FOLDER) + newfile = open(tmpfilename, mode='w', encoding='utf-8') + +- oldfile = open(settings.tlpconfigfile, encoding='utf-8') ++ try: ++ oldfile = open(settings.tlpconfigfile, encoding='utf-8') ++ except FileNotFoundError: ++ oldfile = open("@tlp@/etc/tlp.conf", encoding='utf-8') + lines = oldfile.readlines() + oldfile.close() + +diff --git a/tlpui/mainui.py b/tlpui/mainui.py +index 0242514..da59046 100644 +--- a/tlpui/mainui.py ++++ b/tlpui/mainui.py +@@ -115,8 +115,12 @@ def changed_items_dialog(window, tmpfilename: str, dialogtitle: str, message: st + scrolledwindow.set_hexpand(True) + scrolledwindow.set_vexpand(True) + +- with open(settings.tlpconfigfile, encoding='utf-8') as fromfile: +- fromfilecontent = fromfile.readlines() ++ try: ++ with open(settings.tlpconfigfile, encoding='utf-8') as fromfile: ++ fromfilecontent = fromfile.readlines() ++ except FileNotFoundError: ++ with open("@tlp@/etc/tlp.conf", encoding='utf-8') as fromfile: ++ fromfilecontent = fromfile.readlines() + with open(tmpfilename, encoding='utf-8') as tofile: + tofilecontent = tofile.readlines() + diff = settings.tlpbaseconfigfile + '\n\n' +diff --git a/tlpui/settingshelper.py b/tlpui/settingshelper.py +index 69481c0..d769029 100644 +--- a/tlpui/settingshelper.py ++++ b/tlpui/settingshelper.py +@@ -20,7 +20,7 @@ def exec_command(commands: [str]): + + def get_tlp_config_file(prefix: str) -> str: + """Select tlp config file by prefix.""" +- return f"{prefix}/etc/tlp.conf" ++ return f"{prefix}/etc/tlp.d/30-tlpui.conf" + + + def check_binaries_exist(flatpak_folder_prefix: str) -> None: diff --git a/fake_flake.nix b/fake_flake.nix index 544a0b1..0e09698 100644 --- a/fake_flake.nix +++ b/fake_flake.nix @@ -28,11 +28,11 @@ let }; nixpkgs_patches = [ - { - # tlpui - url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/305278.patch"; - hash = "sha256-vmzj7gF8jwHdqxN+dQiJ4MRxKpHvBTzbrUvFgt1DK8I="; - } +# { +# # tlpui +# url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/305278.patch"; +# hash = "sha256-vmzj7gF8jwHdqxN+dQiJ4MRxKpHvBTzbrUvFgt1DK8I="; +# } ]; # enable ccache for lix if ccache is enabled diff --git a/overlays/default.nix b/overlays/default.nix index 2579115..8be1c09 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -24,6 +24,7 @@ [ ./matrix-appservice-discord.nix ./deskwhich.nix + ./tlpui.nix ./mcontrolcenter.nix ./ccache-wrapper.nix ]; diff --git a/overlays/tlpui.nix b/overlays/tlpui.nix new file mode 100644 index 0000000..6cbeaff --- /dev/null +++ b/overlays/tlpui.nix @@ -0,0 +1,4 @@ +{ final, prev, ... }: +{ + tlpui = prev.callPackage ../custom/tlpui/package.nix { }; +}