Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-cpufreq: 1.9.9 -> 2.2.0 #258684

Closed
wants to merge 10 commits into from
65 changes: 59 additions & 6 deletions pkgs/tools/system/auto-cpufreq/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
{ lib, python3Packages, fetchFromGitHub, substituteAll }:
{ lib
, python3Packages
, fetchFromGitHub
, substituteAll
, wrapGAppsHook
, gobject-introspection
, gtk3
}:

python3Packages.buildPythonPackage rec {
# use pyproject.toml instead of setup.py
format = "pyproject";

pname = "auto-cpufreq";
version = "1.9.9";
version = "2.2.0";

src = fetchFromGitHub {
owner = "AdnanHodzic";
repo = pname;
repo = "auto-cpufreq";
rev = "v${version}";
sha256 = "sha256-D/5pwE2V+yXj92ECOUcl/dajMDbvVdz9YNJrl2Pzvts=";
hash = "sha256-lwimP4+qRFNQN+uHSFJHdkXYREWGwtoEc7U+bN5TDcc=";
};

propagatedBuildInputs = with python3Packages; [ setuptools-git-versioning click distro psutil ];
nativeBuildInputs = [
gobject-introspection
wrapGAppsHook
];

buildInputs = [
gtk3
python3Packages.poetry-core
];

propagatedBuildInputs = with python3Packages; [
click
distro
psutil
pygobject3
poetry-dynamic-versioning
setuptools
];

doCheck = false;
pythonImportsCheck = [ "auto_cpufreq" ];
Expand All @@ -27,15 +54,41 @@ python3Packages.buildPythonPackage rec {
./prevent-install-and-copy.patch
# patch to prevent update
./prevent-update.patch
];
];

postPatch = ''
substituteInPlace auto_cpufreq/core.py --replace '/opt/auto-cpufreq/override.pickle' /var/run/override.pickle
substituteInPlace scripts/org.auto-cpufreq.pkexec.policy --replace "/opt/auto-cpufreq/venv/bin/auto-cpufreq" $out/bin/auto-cpufreq

substituteInPlace auto_cpufreq/gui/app.py auto_cpufreq/gui/objects.py \
--replace "/usr/local/share/auto-cpufreq/images/icon.png" $out/share/pixmaps/auto-cpufreq.png
substituteInPlace auto_cpufreq/gui/app.py \
--replace "/usr/local/share/auto-cpufreq/scripts/style.css" $out/share/auto-cpufreq/scripts/style.css

'';

postInstall = ''
# copy script manually
cp ${src}/scripts/cpufreqctl.sh $out/bin/cpufreqctl.auto-cpufreq

# copy css file
mkdir -p $out/share/auto-cpufreq/scripts
cp scripts/style.css $out/share/auto-cpufreq/scripts/style.css


# systemd service
mkdir -p $out/lib/systemd/system
cp ${src}/scripts/auto-cpufreq.service $out/lib/systemd/system

# desktop icon
mkdir -p $out/share/applications
mkdir $out/share/pixmaps
cp scripts/auto-cpufreq-gtk.desktop $out/share/applications
Comment on lines +83 to +85

This comment was marked as resolved.

cp images/icon.png $out/share/pixmaps/auto-cpufreq.png

# polkit policy
mkdir -p $out/share/polkit-1/actions
cp scripts/org.auto-cpufreq.pkexec.policy $out/share/polkit-1/actions
'';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a specific NixOS module for this ? I guess just enabling auto-cpufreq (in environment.packages) is not enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, auto-cpufreq usually runs as a daemon/background process, so just installing the package should only provide the binaries etc. I like that it's a service.

Also, the autocpufreq-service clashes with gnome3's power management (even with the service, sadly), so automatically running the service after installing the package would maybe also not be super nice.

Copy link
Contributor

@drupol drupol Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question was merely how to make sure that the polkit policy is correctly used.

As an example using custom udev rules, is projecteur, as you can see, it provides an udev rule and services.udev.packages need to be enabled.

Do we need to do something similar with auto-cpufreq ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, sorry, then I got the question wrong, can't help in this case 🙈


meta = with lib; {
Expand Down
20 changes: 10 additions & 10 deletions pkgs/tools/system/auto-cpufreq/fix-version-output.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py
index 99397a9..f3ef28f 100755
index 0ef4315..66fd9e2 100755
--- a/auto_cpufreq/core.py
+++ b/auto_cpufreq/core.py
@@ -144,26 +144,10 @@ except PermissionError:
@@ -145,26 +145,8 @@ except PermissionError:

# display running version of auto-cpufreq
def app_version():
+ print("auto-cpufreq version: @version@")
+ print("Git commit: v@version@")

-
- print("auto-cpufreq version: ", end="")
-
- # snap package
- if os.getenv("PKG_MARKER") == "SNAP":
- print(getoutput("echo \(Snap\) $SNAP_VERSION"))
- print(getoutput(r"echo \(Snap\) $SNAP_VERSION"))
- # aur package
- elif dist_name in ["arch", "manjaro", "garuda"]:
- aur_pkg_check = call("pacman -Qs auto-cpufreq > /dev/null", shell=True)
Expand All @@ -28,6 +26,8 @@ index 99397a9..f3ef28f 100755
- except Exception as e:
- print(repr(e))
- pass
def verify_update():
# Specify the repository and package name
# IT IS IMPORTANT TO THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY
+ print("auto-cpufreq version: @version@")
+ print("Git commit: v@version@")

def check_for_update():
# returns True if a new release is available from the GitHub repo
13 changes: 7 additions & 6 deletions pkgs/tools/system/auto-cpufreq/prevent-install-and-copy.patch
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ index 99397a9..48a377a 100755

def gov_check():

diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq
index b89d925..b73974c 100755
--- a/bin/auto-cpufreq
+++ b/bin/auto-cpufreq
@@ -189,41 +189,9 @@
diff --git a/auto_cpufreq/bin/auto_cpufreq.py b/auto_cpufreq/bin/auto_cpufreq.py
index db2b84d..9c3caf3 100755
--- a/auto_cpufreq/bin/auto_cpufreq.py
+++ b/auto_cpufreq/bin/auto_cpufreq.py
@@ -189,41 +189,9 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
print("https://github.com/AdnanHodzic/auto-cpufreq/#donate")
footer()
elif install:
Expand Down Expand Up @@ -160,4 +160,5 @@ index b89d925..b73974c 100755
+ print("remove is disabled in the nix package")
elif update:
root_check()
if os.getenv("PKG_MARKER") == "SNAP":
custom_dir = "/opt/auto-cpufreq/source"

123 changes: 88 additions & 35 deletions pkgs/tools/system/auto-cpufreq/prevent-update.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
diff --git a/requirements.txt b/requirements.txt
index f492cac..e61d1a4 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,4 +2,3 @@
psutil
click
distro
-requests

diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py
index 99397a9..697fb68 100755
index 0ef4315..fe9dc25 100755
--- a/auto_cpufreq/core.py
+++ b/auto_cpufreq/core.py
@@ -18,7 +18,6 @@ from math import isclose
@@ -19,7 +19,6 @@ from math import isclose
from pathlib import Path
from shutil import which
from subprocess import getoutput, call, run, check_output, DEVNULL
Expand All @@ -21,40 +11,103 @@ index 99397a9..697fb68 100755

# execution timestamp used in countdown func

diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq
index b89d925..b73974c 100755
--- a/bin/auto-cpufreq
+++ b/bin/auto-cpufreq
@@ -193,31 +193,7 @@
elif remove:
print("remove is disabled in the nix package")

diff --git a/auto_cpufreq/bin/auto_cpufreq.py b/auto_cpufreq/bin/auto_cpufreq.py
index db2b84d..0425338 100755
--- a/auto_cpufreq/bin/auto_cpufreq.py
+++ b/auto_cpufreq/bin/auto_cpufreq.py
@@ -225,47 +225,7 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
remove_daemon()
remove_complete_msg()
elif update:
- root_check()
- custom_dir = "/opt/auto-cpufreq/source"
- for arg in sys.argv:
- if arg.startswith("--update="):
- custom_dir = arg.split("=")[1]
- sys.argv.remove(arg)
-
- if "--update" in sys.argv:
- update = True
- sys.argv.remove("--update")
- if len(sys.argv) == 2:
- custom_dir = sys.argv[1]
-
- if os.getenv("PKG_MARKER") == "SNAP":
- print("Detected auto-cpufreq was installed using snap")
- # refresh snap directly using this command
- # path wont work in this case
-
- print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.")
- #check for AUR
- elif subprocess.run(["bash", "-c", "command -v yay >/dev/null 2>&1"]).returncode == 0 or subprocess.run(["bash", "-c", "command -v pacman >/dev/null 2>&1"]).returncode == 0:
- elif subprocess.run(["bash", "-c", "command -v pacman >/dev/null 2>&1"]).returncode == 0 and subprocess.run(["bash", "-c", "pacman -Q auto-cpufreq >/dev/null 2>&1"]).returncode == 0:
- print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.")
- else:
- verify_update()
- ans = input ("Do you want to update auto-cpufreq to the latest release? [y/n]: ")
- valid_options = ['y', 'Y', 'yes', 'YES', 'Yes']
- if ans.lower() in valid_options:
- is_new_update = check_for_update()
- if not is_new_update:
- return
- ans = input("Do you want to update auto-cpufreq to the latest release? [Y/n]: ").strip().lower()
- if not os.path.exists(custom_dir):
- os.makedirs(custom_dir)
- if os.path.exists(os.path.join(custom_dir, "auto-cpufreq")):
- shutil.rmtree(os.path.join(custom_dir, "auto-cpufreq"))
- if ans in ['', 'y', 'yes']:
- remove_daemon()
- remove_complete_msg()
- new_update()
- new_update(custom_dir)
- print("enabling daemon")
- run(["auto-cpufreq", "--install"])
- print("auto-cpufreq is installed with the latest version")
- run(["auto-cpufreq", "--version"])
- else:
- print("incorrect input\n")
- print("Aborted")
- print("enabling daemon")
- run(["auto-cpufreq", "--install"])
- print("auto-cpufreq is installed with the latest version")
- app_version()
-
+ print("update is disabled in the nix package")


if __name__ == "__main__":
+ print("Update is disabled in the Nix package")

elif completions:
if completions == "bash":
diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py
index e355ff3..a0e9c48 100755
--- a/auto_cpufreq/core.py
+++ b/auto_cpufreq/core.py
@@ -167,40 +167,8 @@ def app_version():
pass

def check_for_update():
- # returns True if a new release is available from the GitHub repo
+ pass

- # Specify the repository and package name
- # IT IS IMPORTANT TO THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY
- # Fetch the latest release information from GitHub API
- latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
- try:
- latest_release = requests.get(latest_release_url).json()
- except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
- requests.exceptions.RequestException, requests.exceptions.HTTPError) as err:
- print ("Error Connecting to server!")
- return False
-
- latest_version = latest_release["tag_name"]
-
- # Get the current version of auto-cpufreq
- # Extract version number from the output string
- output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
- try:
- version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
- except AttributeError:
- print("Error Retrieving Current Version!")
- exit(1)
- installed_version = "v" + version_line
- #Check whether the same is installed or not
- # Compare the latest version with the installed version and perform update if necessary
- if latest_version == installed_version:
- print("auto-cpufreq is up to date")
- return False
- else:
- print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
- print("Note that your previous custom settings might be erased with the following update")
- return True
-
def new_update(custom_dir):
os.chdir(custom_dir)
print(f"Cloning the latest release to {custom_dir}")
Loading