From 91883a2ed6b092cc2d9b4d963fba9ff30d21c3b6 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 20 Apr 2024 23:56:40 +0200 Subject: [PATCH 01/59] initial --- .gitignore | 1 + flake.lock | 44 +++++++++++++++++++++++++++++ flake.nix | 21 ++++++++++++++ nix/package.nix | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/package.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a06816 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +results diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8de5f21 --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1713564160, + "narHash": "sha256-YguPZpiejgzLEcO36/SZULjJQ55iWcjAmf3lYiyV1Fo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bc194f70731cc5d2b046a6c1b3b15f170f05999c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1c5c968 --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + description = "Solaar is Open Source Logitech Driver for Linux"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-compat }: { + + packages.x86_64-linux.default = ( + import nixpkgs { + currentSystem = "x86_64-linux"; + localSystem = "x86_64-linux"; + }).pkgs.callPackage ./nix/package.nix {}; + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..3b3276d --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,75 @@ +{ +lib, +lm_sensors, +python3Packages, +python3, +bash +}: + +let + pversion = "20-04-2024"; + description = "A simple systemd service to better control Framework Laptop's fan(s)"; + url = "https://github.com/TamtamHero/fw-fanctrl"; +in +python3Packages.buildPythonPackage rec{ + pname = "fw-fanctrl"; + version = pversion; + + src = ../.; + + outputs = [ "out" ]; + + preBuild = '' + cat > setup.py << EOF + from setuptools import setup + + with open("requirements.txt") as f: + install_requires = f.read().splitlines() + + setup( + name="fw-fanctrl", + description="${description}", + url="${url}", + platforms=["linux"], + + install_requires=install_requires, + scripts=[ + "fanctrl.py", + ], + ) + EOF + ''; + + nativeBuildInputs = [ + python3 + ]; + + propagatedBuildInputs = with python3Packages; [ + watchdog + lm_sensors + ]; + + doCheck = false; + + postPatch = '' + patchShebangs --build fanctrl.py + substituteInPlace fanctrl.py --replace "/bin/bash" "${bash}/bin/bash" + cat fanctrl.py + ''; + + installPhase = '' + mkdir -p $out/bin + mv ./bin/ectool $out/bin/ectool + mv ./fanctrl.py $out/bin/fw-fanctrl + chmod 755 $out/bin/fw-fanctrl + ''; + + meta = with lib; { + mainProgram = "fw-fanctrl"; + homepage = url; + description = description; + platforms = with platforms; linux; + license = licenses.bsd3; + maintainers = with maintainers; [ "TamtamHero" ]; + }; +} From 2429c607103177bdfbaa8fbc3ae57704dfcb28a6 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 20 Apr 2024 23:58:55 +0200 Subject: [PATCH 02/59] update gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1a06816..c4a847d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -results +/result From 68a710cd3ac6ed0000cbb0bd147b6de4e0bd6689 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sun, 21 Apr 2024 00:00:36 +0200 Subject: [PATCH 03/59] update inputs --- nix/package.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nix/package.nix b/nix/package.nix index 3b3276d..4cbd731 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -44,9 +44,12 @@ python3Packages.buildPythonPackage rec{ python3 ]; + buildInputs = [ + lm_sensors + ]; + propagatedBuildInputs = with python3Packages; [ watchdog - lm_sensors ]; doCheck = false; From 231f2ca7f70c63a5111bedafbf4cd5ff1c919840 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 21:17:36 +0200 Subject: [PATCH 04/59] add fw-ectool dependencie --- nix/package.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/package.nix b/nix/package.nix index 4cbd731..39c6ca0 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,6 +1,7 @@ { lib, lm_sensors, +fw-ectool, python3Packages, python3, bash @@ -50,6 +51,7 @@ python3Packages.buildPythonPackage rec{ propagatedBuildInputs = with python3Packages; [ watchdog + fw-ectool ]; doCheck = false; @@ -62,7 +64,6 @@ python3Packages.buildPythonPackage rec{ installPhase = '' mkdir -p $out/bin - mv ./bin/ectool $out/bin/ectool mv ./fanctrl.py $out/bin/fw-fanctrl chmod 755 $out/bin/fw-fanctrl ''; From f06e0f5909227d49c2ec64a56c47aaee87d33980 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:35:01 +0200 Subject: [PATCH 05/59] add module --- flake.nix | 2 ++ nix/module.nix | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 nix/module.nix diff --git a/flake.nix b/flake.nix index 1c5c968..a11b78d 100644 --- a/flake.nix +++ b/flake.nix @@ -17,5 +17,7 @@ currentSystem = "x86_64-linux"; localSystem = "x86_64-linux"; }).pkgs.callPackage ./nix/package.nix {}; + + nixosModules.default = import ./nix/module.nix; }; } diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..03c0ef2 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,50 @@ +{ options, config, lib, self, ... }: + +with lib; +with lib.types; +let + cfg = config.programs.fw-fanctrl; + package = self.packages.x86_64-linux.default; +in +{ + options.programs.fw-fanctrl = { + enable = mkOption { + type = bool; + default = false; + description = '' + Enable fw-fanctrl systemd service and install the needed packages. + ''; + }; + config = mkOption { + type = lines; + default = builtins.readFile ../config.json; + description = '' + Config json that creates the config in /etc/fw-fanctrl/config.json. + ''; + + }; + }; + + config = mkIf cfg.enable { + environment.systemPackage = [ + package + ]; + }; + + environment.etc."fw-fanctrl/config.json" = { + text = cfg.config; + }; + + systemd.services.fw-fanctrl = { + description = "Framework Fan Controller"; + after = "multi-user.target"; + type = "simple"; + unitConfig = '' + Type=simple + Restart=always + ''; + script = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + enable = true; + wantedBy = "multi-user.target"; + }; +} From aac94613e05cca28c86eeef39f93eed664c15ddc Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:36:15 +0200 Subject: [PATCH 06/59] fix tabs --- nix/module.nix | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 03c0ef2..61f5fe5 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -29,22 +29,22 @@ in environment.systemPackage = [ package ]; - }; - environment.etc."fw-fanctrl/config.json" = { - text = cfg.config; - }; + environment.etc."fw-fanctrl/config.json" = { + text = cfg.config; + }; - systemd.services.fw-fanctrl = { - description = "Framework Fan Controller"; - after = "multi-user.target"; - type = "simple"; - unitConfig = '' - Type=simple - Restart=always - ''; - script = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; - enable = true; - wantedBy = "multi-user.target"; + systemd.services.fw-fanctrl = { + description = "Framework Fan Controller"; + after = "multi-user.target"; + type = "simple"; + unitConfig = '' + Type=simple + Restart=always + ''; + script = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + enable = true; + wantedBy = "multi-user.target"; + }; }; } From eaa983c332ca19ac887a2d5992952ff28d1622fc Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:38:26 +0200 Subject: [PATCH 07/59] fix package --- nix/module.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 61f5fe5..3623d82 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,10 +1,10 @@ -{ options, config, lib, self, ... }: +{ options, config, lib, pkgs, ... }: with lib; with lib.types; let cfg = config.programs.fw-fanctrl; - package = self.packages.x86_64-linux.default; + package = pkgs.callPackage ./package.nix {}; in { options.programs.fw-fanctrl = { From 1ef9e728c5c7f607d9749eba5b5d34ac13565428 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:46:45 +0200 Subject: [PATCH 08/59] fix typo --- nix/module.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 3623d82..714ee5b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -21,12 +21,11 @@ in description = '' Config json that creates the config in /etc/fw-fanctrl/config.json. ''; - }; }; config = mkIf cfg.enable { - environment.systemPackage = [ + environment.systemPackages = [ package ]; From 8016fecc6dfc4d0cdd2910ddcb9bd69164034014 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:57:27 +0200 Subject: [PATCH 09/59] fix service --- flake.nix | 2 +- nix/module.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index a11b78d..3aa1f1a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Solaar is Open Source Logitech Driver for Linux"; + description = "A software to controll the Framework fan speed"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; diff --git a/nix/module.nix b/nix/module.nix index 714ee5b..c78eba0 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -36,7 +36,6 @@ in systemd.services.fw-fanctrl = { description = "Framework Fan Controller"; after = "multi-user.target"; - type = "simple"; unitConfig = '' Type=simple Restart=always From f50d730d77e31470af60e18bf836a868ac89170d Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 22:59:21 +0200 Subject: [PATCH 10/59] fix type --- nix/module.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index c78eba0..16cd3cf 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -35,14 +35,14 @@ in systemd.services.fw-fanctrl = { description = "Framework Fan Controller"; - after = "multi-user.target"; + after = [ "multi-user.target" ]; unitConfig = '' Type=simple Restart=always ''; script = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; enable = true; - wantedBy = "multi-user.target"; + wantedBy = [ "multi-user.target" ]; }; }; } From f27ee51fe1892fefc39b8820c7273e268a82853a Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:01:18 +0200 Subject: [PATCH 11/59] add options --- nix/module.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 16cd3cf..f0c0c94 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -36,11 +36,11 @@ in systemd.services.fw-fanctrl = { description = "Framework Fan Controller"; after = [ "multi-user.target" ]; - unitConfig = '' - Type=simple - Restart=always - ''; - script = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + unitConfig = { + Type = "simple"; + Restart = "always"; + ExecStart = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + }; enable = true; wantedBy = [ "multi-user.target" ]; }; From bd33e858c7e644bba3594f9c61ebac65dc41c9c2 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:05:39 +0200 Subject: [PATCH 12/59] fix service --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index f0c0c94..37eac2b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -36,7 +36,7 @@ in systemd.services.fw-fanctrl = { description = "Framework Fan Controller"; after = [ "multi-user.target" ]; - unitConfig = { + serviceConfig = { Type = "simple"; Restart = "always"; ExecStart = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; From ab6de2c3856b45dc3101efa70649220085d88d91 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:27:22 +0200 Subject: [PATCH 13/59] fix build inputs --- fanctrl.py | 2 +- nix/package.nix | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fanctrl.py b/fanctrl.py index 87a2f34..1f926ef 100644 --- a/fanctrl.py +++ b/fanctrl.py @@ -255,7 +255,7 @@ def main(): nargs="?", help="Switches the strategy of a currently running fw-fanctrl instance", ) - parser.add_argument("--config", type=str, help="Path to config file", default=".") + parser.add_argument("--config", type=str, help="Path to config file", default="/etc/fw-fanctrl/config.json") parser.add_argument( "--strategy", type=str, diff --git a/nix/package.nix b/nix/package.nix index 39c6ca0..78151a6 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -45,13 +45,10 @@ python3Packages.buildPythonPackage rec{ python3 ]; - buildInputs = [ - lm_sensors - ]; - propagatedBuildInputs = with python3Packages; [ watchdog fw-ectool + lm_sensors ]; doCheck = false; From 398203cf88fbf911e2845142282d05e29ed3753c Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:48:28 +0200 Subject: [PATCH 14/59] add Readme + add suspend script --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ nix/module.nix | 12 ++++++++++++ 2 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 01cdf6b..f4f70d9 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs and w # Install +**This discripes how to install fw-fanctrl on every distro that is not NixOS! If you want to use it on NixOS show [here](#nixos)** + ## Dependancies This tool depends on `lm-sensors` to fetch CPU temperature: @@ -79,3 +81,41 @@ It is possible to hot swap the current strategy with another one by running the fw-fanctrl strategyName ``` where `strategyName is one of the strategies described in the config file. + + +# NixOS + +For NixOS this repo contains an Flake. You could add it to your config like this: + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + fw-fanctrl = { + url = "github:TamtamHero/fw-fanctrl/main; # This is NOT a stable tested version + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = {nixpkgs, fw-fanctrl}: { + nixosConfigurations.foo = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + fw-fanctrl.nixosModules.default + configuration.nix + ]; + }; + } +} +``` +and then add in your *configuration.nix*: +```nix +# Enable fw-fanctrl +programs.fw-fanctrl.enable = true; + +# Add a custom config +programs.fw-fanctrl.config = '' + { + ... + } +''; +``` diff --git a/nix/module.nix b/nix/module.nix index 37eac2b..66c6ad0 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -25,14 +25,17 @@ in }; config = mkIf cfg.enable { + # Install package environment.systemPackages = [ package ]; + # Create config environment.etc."fw-fanctrl/config.json" = { text = cfg.config; }; + # Create Service systemd.services.fw-fanctrl = { description = "Framework Fan Controller"; after = [ "multi-user.target" ]; @@ -44,5 +47,14 @@ in enable = true; wantedBy = [ "multi-user.target" ]; }; + + # Create suspend config + environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = pkgs.writeShellScript '' + case \$1 in + pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl sleep" ;; + post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; + esac + ''; + }; }; } From 4e823a982a1cd1bc0e25b0970f6c50a90e3fc170 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:50:54 +0200 Subject: [PATCH 15/59] remove unneeded }; --- nix/module.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 66c6ad0..afcea53 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -55,6 +55,5 @@ in post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; esac ''; - }; }; } From 690795eaa11d239dfbe1716f889997a62bb4d05d Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:53:03 +0200 Subject: [PATCH 16/59] fix pkgs.writeShellScript --- nix/module.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index afcea53..3d51a2e 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -49,11 +49,12 @@ in }; # Create suspend config - environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = pkgs.writeShellScript '' - case \$1 in - pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl sleep" ;; - post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; - esac + environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = + pkgs.writeShellScript "fw-fanctrl-suspend.sh" '' + case \$1 in + pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl sleep" ;; + post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; + esac ''; }; } From bf785d2c08f393150ea17614bb37f8fd795dc784 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 3 May 2024 23:55:17 +0200 Subject: [PATCH 17/59] remvoe \ --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 3d51a2e..483c5c7 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -51,7 +51,7 @@ in # Create suspend config environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = pkgs.writeShellScript "fw-fanctrl-suspend.sh" '' - case \$1 in + case $1 in pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl sleep" ;; post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; esac From 01e7c596d35f667c24f1db503a9146873d2d81a0 Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 6 May 2024 20:06:47 +0200 Subject: [PATCH 18/59] try --- flake.nix | 10 +++++-- nix/module.nix | 14 ++++++---- nix/packages/fw-ectool.nix | 29 ++++++++++++++++++++ nix/{package.nix => packages/fw-fanctrl.nix} | 10 +++---- 4 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 nix/packages/fw-ectool.nix rename nix/{package.nix => packages/fw-fanctrl.nix} (91%) diff --git a/flake.nix b/flake.nix index 3aa1f1a..55f36ac 100644 --- a/flake.nix +++ b/flake.nix @@ -12,11 +12,17 @@ outputs = { self, nixpkgs, flake-compat }: { - packages.x86_64-linux.default = ( + packages.x86_64-linux.fw-fanctrl = ( import nixpkgs { currentSystem = "x86_64-linux"; localSystem = "x86_64-linux"; - }).pkgs.callPackage ./nix/package.nix {}; + }).pkgs.callPackage ./nix/packages/fw-fanctrl.nix { inherit self; }; + + packages.x86_64-linux.fw-ectool = ( + import nixpkgs { + currentSystem = "x86_64-linux"; + localSystem = "x86_64-linux"; + }).pkgs.callPackage ./nix/packages/fw-ectool.nix {}; nixosModules.default = import ./nix/module.nix; }; diff --git a/nix/module.nix b/nix/module.nix index 483c5c7..feb1b39 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,10 +1,11 @@ -{ options, config, lib, pkgs, ... }: +{ options, config, lib, pkgs, self, ... }: with lib; with lib.types; let cfg = config.programs.fw-fanctrl; - package = pkgs.callPackage ./package.nix {}; + fw-ectool = self.packages.x86_64-linux.fw-ectool; + fw-fanctrl = self.packages.x86_64-linux.fw-fanctrl; in { options.programs.fw-fanctrl = { @@ -27,7 +28,8 @@ in config = mkIf cfg.enable { # Install package environment.systemPackages = [ - package + fw-fanctrl + fw-ectool ]; # Create config @@ -42,7 +44,7 @@ in serviceConfig = { Type = "simple"; Restart = "always"; - ExecStart = "${package}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; }; enable = true; wantedBy = [ "multi-user.target" ]; @@ -52,8 +54,8 @@ in environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = pkgs.writeShellScript "fw-fanctrl-suspend.sh" '' case $1 in - pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl sleep" ;; - post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${package}/bin/fw-fanctrl defaultStrategy" ;; + pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${fw-fanctrl}/bin/fw-fanctrl sleep" ;; + post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${fw-fanctrl}/bin/fw-fanctrl defaultStrategy" ;; esac ''; }; diff --git a/nix/packages/fw-ectool.nix b/nix/packages/fw-ectool.nix new file mode 100644 index 0000000..4fb6080 --- /dev/null +++ b/nix/packages/fw-ectool.nix @@ -0,0 +1,29 @@ +{ + stdenv, + lib +}: + +stdenv.mkDerivation rec { + version = "20-04-2024"; + name = "fw-ectool"; + src = ../../.; + + outputs = [ "out" ]; + + installPhase = '' + mkdir -p $out/bin/ + mv ./bin/ectool $out/bin/ectool + ln -s $out/bin/ectool $out/bin/fw-ectool + ''; + + doCheck = false; + + meta = with lib; { + mainProgram = "ectool"; + homepage = "https://github.com/TamtamHero/fw-fanctrl"; + description = "fw-ectool customized for fw-fanctrl"; + platforms = with platforms; linux; + license = licenses.bsd3; + maintainers = with maintainers; [ "Svenum" ]; + }; +} diff --git a/nix/package.nix b/nix/packages/fw-fanctrl.nix similarity index 91% rename from nix/package.nix rename to nix/packages/fw-fanctrl.nix index 78151a6..ca46e58 100644 --- a/nix/package.nix +++ b/nix/packages/fw-fanctrl.nix @@ -1,10 +1,10 @@ { lib, lm_sensors, -fw-ectool, python3Packages, python3, -bash +bash, +self }: let @@ -16,7 +16,7 @@ python3Packages.buildPythonPackage rec{ pname = "fw-fanctrl"; version = pversion; - src = ../.; + src = ../../.; outputs = [ "out" ]; @@ -47,7 +47,7 @@ python3Packages.buildPythonPackage rec{ propagatedBuildInputs = with python3Packages; [ watchdog - fw-ectool + self.packages.x86_64-linux.fw-ectool lm_sensors ]; @@ -71,6 +71,6 @@ python3Packages.buildPythonPackage rec{ description = description; platforms = with platforms; linux; license = licenses.bsd3; - maintainers = with maintainers; [ "TamtamHero" ]; + maintainers = with maintainers; [ "Svenum" ]; }; } From d8b63b02ac01b96be9e75c8480fe30d55d896460 Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 6 May 2024 20:10:41 +0200 Subject: [PATCH 19/59] add self --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 55f36ac..ccfa340 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,7 @@ }; outputs = { self, nixpkgs, flake-compat }: { + inherit self; packages.x86_64-linux.fw-fanctrl = ( import nixpkgs { From a608a83429d5e964550bc4e22009ea832e9dec34 Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 6 May 2024 20:16:52 +0200 Subject: [PATCH 20/59] fix module --- flake.nix | 3 +-- nix/module.nix | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index ccfa340..7893276 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,7 @@ }; outputs = { self, nixpkgs, flake-compat }: { - inherit self; - + packages.x86_64-linux.default = self.packages.x86_64-linux.fw-fanctrl; packages.x86_64-linux.fw-fanctrl = ( import nixpkgs { currentSystem = "x86_64-linux"; diff --git a/nix/module.nix b/nix/module.nix index feb1b39..51439d5 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,11 +1,11 @@ -{ options, config, lib, pkgs, self, ... }: +{ options, config, lib, pkgs, ... }: with lib; with lib.types; let cfg = config.programs.fw-fanctrl; - fw-ectool = self.packages.x86_64-linux.fw-ectool; - fw-fanctrl = self.packages.x86_64-linux.fw-fanctrl; + fw-ectool = pkgs.callPackage ./packages/fw-ectool.nix {}; + fw-fanctrl = pkgs.callPackage ./packages/fw-fanctrl.nix {}; in { options.programs.fw-fanctrl = { From 6f993e267340fb51fc8de6aa419f4bb1023caa39 Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 6 May 2024 20:20:24 +0200 Subject: [PATCH 21/59] update package --- flake.nix | 2 +- nix/packages/fw-fanctrl.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 7893276..63fe589 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,7 @@ import nixpkgs { currentSystem = "x86_64-linux"; localSystem = "x86_64-linux"; - }).pkgs.callPackage ./nix/packages/fw-fanctrl.nix { inherit self; }; + }).pkgs.callPackage ./nix/packages/fw-fanctrl.nix {}; packages.x86_64-linux.fw-ectool = ( import nixpkgs { diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index ca46e58..e1974f1 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -4,7 +4,7 @@ lm_sensors, python3Packages, python3, bash, -self +callPackage }: let @@ -47,7 +47,7 @@ python3Packages.buildPythonPackage rec{ propagatedBuildInputs = with python3Packages; [ watchdog - self.packages.x86_64-linux.fw-ectool + ( callPackage ./fw-ectool.nix {} ) lm_sensors ]; From 5036aa136c8db5c153e7d54c4a28f4027bed92de Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 6 May 2024 20:57:50 +0200 Subject: [PATCH 22/59] fix package --- nix/packages/fw-ectool.nix | 22 ++++++++++++++++++---- nix/packages/fw-fanctrl.nix | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/nix/packages/fw-ectool.nix b/nix/packages/fw-ectool.nix index 4fb6080..1900116 100644 --- a/nix/packages/fw-ectool.nix +++ b/nix/packages/fw-ectool.nix @@ -1,19 +1,33 @@ { stdenv, - lib + lib, + autoPatchelfHook, + libusb1, + libftdi1 }: -stdenv.mkDerivation rec { +stdenv.mkDerivation { version = "20-04-2024"; name = "fw-ectool"; src = ../../.; outputs = [ "out" ]; + nativeBuildInputs = [ + autoPatchelfHook + ]; + + propagatedBuildInputs = [ + libusb1 + libftdi1 + ]; + installPhase = '' - mkdir -p $out/bin/ - mv ./bin/ectool $out/bin/ectool + mkdir -p $out/bin + runHook preInstall + install -m755 ./bin/ectool $out/bin/ectool ln -s $out/bin/ectool $out/bin/fw-ectool + chmod -R 755 $out/bin/* ''; doCheck = false; diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index e1974f1..1c5f962 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -32,6 +32,7 @@ python3Packages.buildPythonPackage rec{ description="${description}", url="${url}", platforms=["linux"], + py_modules=[], install_requires=install_requires, scripts=[ @@ -47,7 +48,7 @@ python3Packages.buildPythonPackage rec{ propagatedBuildInputs = with python3Packages; [ watchdog - ( callPackage ./fw-ectool.nix {} ) + (callPackage ./fw-ectool.nix {}) lm_sensors ]; From 0f8f846597b58606bc3200e0dfc73b78633bff87 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 13:31:16 +0200 Subject: [PATCH 23/59] use sleep script --- nix/module.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 51439d5..0050ac6 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -52,11 +52,6 @@ in # Create suspend config environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - pkgs.writeShellScript "fw-fanctrl-suspend.sh" '' - case $1 in - pre) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${fw-fanctrl}/bin/fw-fanctrl sleep" ;; - post) ${pkgs.util-linux}/bin/runuser -l $(${pkgs.coreutils}/bin/logname) -c "${fw-fanctrl}/bin/fw-fanctrl defaultStrategy" ;; - esac - ''; + pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); }; } From 4afc9421554efa2beb99314c0ae41b51ca579308 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 13:56:59 +0200 Subject: [PATCH 24/59] add config options --- nix/module.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 0050ac6..3b2678c 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -16,13 +16,70 @@ in Enable fw-fanctrl systemd service and install the needed packages. ''; }; - config = mkOption { + configFile = mkOption { type = lines; default = builtins.readFile ../config.json; description = '' Config json that creates the config in /etc/fw-fanctrl/config.json. ''; }; + config = { + defaultStrategy = mkOption { + type = str; + defualt = "lazy"; + description = "Default strategy to use"; + }; + strategyOnDischarging = mkOption { + type = str; + default = ""; + description = "Default strategy on discharging"; + }; + batteryChargingStatusPath = mkOption { + type = str; + default = ""; + }; + strategies = mkOption { + type = listOf (submodule ( + { options, ... }: + { + options = { + name = mkOption { + type = str; + default = ""; + description = "Name of the strategy"; + }; + fanSpeedUpdateFrequency = mkOption { + type = int; + default = 5; + }; + movingAverageInterval = mkOption { + type = int; + default = 25; + }; + speedCurve = mkOption { + type = listOf (submodule ( + { options, ... }: + { + options = { + temp = mkOption { + type = int; + default = 0; + description = "Tempreture on which the fan speed should be changed"; + }; + speed = mkOption { + type = int; + default = 0; + description = "Percent how fast the fan should run at"; + }; + }; + } + )); + }; + }; + } + )); + }; + }; }; config = mkIf cfg.enable { @@ -34,7 +91,11 @@ in # Create config environment.etc."fw-fanctrl/config.json" = { - text = cfg.config; + text = cfg.configFile; + }; + + environment.etc."fw-fanctrl/config2.json" = { + text = builtins.toJson cfg.config; }; # Create Service From dba838ad840ad2dccf7c4f72346b56242ebd6e4f Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 13:59:33 +0200 Subject: [PATCH 25/59] fix typo --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 3b2678c..ea2f898 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -95,7 +95,7 @@ in }; environment.etc."fw-fanctrl/config2.json" = { - text = builtins.toJson cfg.config; + text = builtins.toJSON cfg.config; }; # Create Service From 6ee820fc637453fd56391e301d4f4df94724d47d Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:00:33 +0200 Subject: [PATCH 26/59] fix typo --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index ea2f898..91e81e1 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -26,7 +26,7 @@ in config = { defaultStrategy = mkOption { type = str; - defualt = "lazy"; + default = "lazy"; description = "Default strategy to use"; }; strategyOnDischarging = mkOption { From d4ce5af59adb12fa183bc98f7a9a54f2c4e464b3 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:02:28 +0200 Subject: [PATCH 27/59] add defaults --- nix/module.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/module.nix b/nix/module.nix index 91e81e1..905f203 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -39,6 +39,7 @@ in default = ""; }; strategies = mkOption { + default = []; type = listOf (submodule ( { options, ... }: { @@ -57,6 +58,7 @@ in default = 25; }; speedCurve = mkOption { + default = []; type = listOf (submodule ( { options, ... }: { From d246269e9b4c974bd54d93bf16fb6b894496575d Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:05:13 +0200 Subject: [PATCH 28/59] fix type --- nix/module.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 905f203..26aeacb 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -39,9 +39,9 @@ in default = ""; }; strategies = mkOption { - default = []; - type = listOf (submodule ( - { options, ... }: + default = {}; + type = attrsOf (submodule ( + { options, name, ... }: { options = { name = mkOption { From bcc1ac070510da42a085b00966ce0180d01ddc4f Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:19:39 +0200 Subject: [PATCH 29/59] add prettyier --- nix/module.nix | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 26aeacb..0924dbd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -6,6 +6,7 @@ let cfg = config.programs.fw-fanctrl; fw-ectool = pkgs.callPackage ./packages/fw-ectool.nix {}; fw-fanctrl = pkgs.callPackage ./packages/fw-fanctrl.nix {}; + defaultConfig = builtins.fromJSON (builtins.readFile ../config.json); in { options.programs.fw-fanctrl = { @@ -26,20 +27,20 @@ in config = { defaultStrategy = mkOption { type = str; - default = "lazy"; + default = defaultConfig.defaultStrategy; description = "Default strategy to use"; }; strategyOnDischarging = mkOption { type = str; - default = ""; + default = defaultConfig.strategyOnDischarging; description = "Default strategy on discharging"; }; batteryChargingStatusPath = mkOption { type = str; - default = ""; + default = defaultConfig.batteryChargingStatusPath; }; strategies = mkOption { - default = {}; + default = defaultConfig.strategies; type = attrsOf (submodule ( { options, name, ... }: { @@ -93,11 +94,7 @@ in # Create config environment.etc."fw-fanctrl/config.json" = { - text = cfg.configFile; - }; - - environment.etc."fw-fanctrl/config2.json" = { - text = builtins.toJSON cfg.config; + text = generators.toPretty (builtins.toJSON cfg.config); }; # Create Service From 89bf5c78db56ea8821712d5d25f4609ad047be22 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:23:45 +0200 Subject: [PATCH 30/59] remove beautifyer --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 0924dbd..e3bd8dd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -94,7 +94,7 @@ in # Create config environment.etc."fw-fanctrl/config.json" = { - text = generators.toPretty (builtins.toJSON cfg.config); + text = builtins.toJSON cfg.config; }; # Create Service From a1c4b9823ea9aa441f03b4897051a1af5546a530 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:28:38 +0200 Subject: [PATCH 31/59] udpate readme --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c50d717..85c6031 100644 --- a/README.md +++ b/README.md @@ -112,9 +112,24 @@ and then add in your *configuration.nix*: programs.fw-fanctrl.enable = true; # Add a custom config -programs.fw-fanctrl.config = '' - { - ... - } -''; +programs.fw-fanctrl.config = { + defaultStrategy = "lazy"; + strategies = { + "lazy" = { + fanSpeedUpdateFrequency = 5; + movingAverageInterval = 30; + speedCurve = [ + { temp = 0; speed = 15; } + { temp = 50; speed = 15; } + { temp = 65; speed = 25; } + { temp = 70; speed = 35; } + { temp = 75; speed = 50; } + { temp = 85; speed = 100; } + ]; + }; + }; +}; + +# Or just change the default strategy form the default config +programs.fw-fanctrl.config.defaultStrategy = "medium"; ``` From 9f521ae4d8d1d1f7a7ac2eeb76205b8de0ec5f50 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 14:31:34 +0200 Subject: [PATCH 32/59] update installer script --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 58b40be..e537af0 100755 --- a/install.sh +++ b/install.sh @@ -66,7 +66,7 @@ function install() { chmod +x "/usr/local/bin/fw-fanctrl" chown "$LOGNAME:$LOGNAME" "/usr/local/bin/fw-fanctrl" mkdir -p "$HOME/.config/fw-fanctrl" - cp -n "./config.json" "$HOME/.config/fw-fanctrl/" || true + cp -n "./config.json" "/etc/fw-fanctrl/config.json" || true # cleaning legacy file rm "/usr/local/bin/fanctrl.py" 2> "/dev/null" || true @@ -120,4 +120,4 @@ else echo "Unknown command '$1'" exit 1 fi -exit 0 \ No newline at end of file +exit 0 From 7edb34732d4d5e66206062b4006ae51ec169411d Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 10 May 2024 17:07:48 +0200 Subject: [PATCH 33/59] add missing path --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index e537af0..f713d15 100755 --- a/install.sh +++ b/install.sh @@ -65,7 +65,7 @@ function install() { cp "./fanctrl.py" "/usr/local/bin/fw-fanctrl" chmod +x "/usr/local/bin/fw-fanctrl" chown "$LOGNAME:$LOGNAME" "/usr/local/bin/fw-fanctrl" - mkdir -p "$HOME/.config/fw-fanctrl" + mkdir -p "/etc/fw-fanctrl" cp -n "./config.json" "/etc/fw-fanctrl/config.json" || true # cleaning legacy file From 636e5d70a6d90e8511a51811becea5e2a6e10514 Mon Sep 17 00:00:00 2001 From: Svenum <43136984+Svenum@users.noreply.github.com> Date: Sat, 11 May 2024 13:58:33 +0200 Subject: [PATCH 34/59] Update README.md Co-authored-by: Thomas Eizinger --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85c6031..81933e5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs and w # Install -**This discripes how to install fw-fanctrl on every distro that is not NixOS! If you want to use it on NixOS show [here](#nixos)** +**This discribes how to install fw-fanctrl on every distro that is not NixOS! If you want to use it on NixOS, use [these](#nixos) instructions** ## Dependancies From 55d8b612fb06794244c05ff688f3b1ea6fea269d Mon Sep 17 00:00:00 2001 From: Svenum <43136984+Svenum@users.noreply.github.com> Date: Sat, 11 May 2024 13:58:48 +0200 Subject: [PATCH 35/59] Update flake.nix Co-authored-by: Thomas Eizinger --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 63fe589..948a04a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A software to controll the Framework fan speed"; + description = "A software to control the Framework fan speed"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; From cf298eddb1687f57215584642026ec9e9e364f4f Mon Sep 17 00:00:00 2001 From: Svenum <43136984+Svenum@users.noreply.github.com> Date: Sat, 11 May 2024 13:59:26 +0200 Subject: [PATCH 36/59] Update nix/module.nix Co-authored-by: Thomas Eizinger --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index e3bd8dd..bb0afed 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -67,7 +67,7 @@ in temp = mkOption { type = int; default = 0; - description = "Tempreture on which the fan speed should be changed"; + description = "Temperature at which the fan speed should be changed"; }; speed = mkOption { type = int; From c7436ec27d025fcfdc6dfaa18e8c7cf20a98b655 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 11 May 2024 14:06:19 +0200 Subject: [PATCH 37/59] add descriptions --- nix/module.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index bb0afed..79167ca 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -17,13 +17,6 @@ in Enable fw-fanctrl systemd service and install the needed packages. ''; }; - configFile = mkOption { - type = lines; - default = builtins.readFile ../config.json; - description = '' - Config json that creates the config in /etc/fw-fanctrl/config.json. - ''; - }; config = { defaultStrategy = mkOption { type = str; @@ -38,6 +31,7 @@ in batteryChargingStatusPath = mkOption { type = str; default = defaultConfig.batteryChargingStatusPath; + description = ""; }; strategies = mkOption { default = defaultConfig.strategies; @@ -53,13 +47,16 @@ in fanSpeedUpdateFrequency = mkOption { type = int; default = 5; + description = "How often the fan speed should be updated in seconds"; }; movingAverageInterval = mkOption { type = int; default = 25; + description = ""; }; speedCurve = mkOption { default = []; + description = "How should the speed curve look like"; type = listOf (submodule ( { options, ... }: { From 7398b2927d6c95cadc7161b60adfabb814bfb3b5 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 11 May 2024 14:07:49 +0200 Subject: [PATCH 38/59] fix uninstall --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index f713d15..a4a1367 100755 --- a/install.sh +++ b/install.sh @@ -54,7 +54,7 @@ function uninstall() { rm "/usr/local/bin/fw-fanctrl" ectool autofanctrl # restore default fan manager rm "/usr/local/bin/ectool" - rm -rf "$HOME/.config/fw-fanctrl" + rm -rf "/etc/fw-fanctrl" } function install() { From 87cd28f43b7e4b557b97d07cf3621a3d0120d794 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 11 May 2024 14:12:59 +0200 Subject: [PATCH 39/59] update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 81933e5..0760950 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,9 @@ programs.fw-fanctrl.config = { }; }; +# Add a custom config from an existing JSON file +programs.fw-fanctrl.config = builtins.fromJSON (builtins.readFile ./config.json) + # Or just change the default strategy form the default config programs.fw-fanctrl.config.defaultStrategy = "medium"; ``` From 985bd56fbdfe67dfa5822294bb52a959ba3453e5 Mon Sep 17 00:00:00 2001 From: Svenum Date: Mon, 13 May 2024 20:20:29 +0200 Subject: [PATCH 40/59] add description --- nix/module.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 79167ca..99a587f 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -30,7 +30,7 @@ in }; batteryChargingStatusPath = mkOption { type = str; - default = defaultConfig.batteryChargingStatusPath; + default = "/sys/class/power_supply/BAT1/status"; description = ""; }; strategies = mkOption { @@ -52,7 +52,7 @@ in movingAverageInterval = mkOption { type = int; default = 25; - description = ""; + description = "Interval (seconds) of the last temperatures to use to calculate the average temperature"; }; speedCurve = mkOption { default = []; From aee101197d52c5cde9cd834c1f809bc7a67ad6c5 Mon Sep 17 00:00:00 2001 From: Svenum Date: Tue, 21 May 2024 17:29:31 +0200 Subject: [PATCH 41/59] remove requiremetns.txt + add github actions --- .github/workflows/nix-build.yml | 16 ++++++++++++++++ nix/packages/fw-fanctrl.nix | 4 ---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/nix-build.yml diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml new file mode 100644 index 0000000..d6205f9 --- /dev/null +++ b/.github/workflows/nix-build.yml @@ -0,0 +1,16 @@ +name: "Test" +on: + pull_request: + branches: + - main + - packaging/nix +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + - run: nix build + diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index 1c5f962..962668f 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -24,9 +24,6 @@ python3Packages.buildPythonPackage rec{ cat > setup.py << EOF from setuptools import setup - with open("requirements.txt") as f: - install_requires = f.read().splitlines() - setup( name="fw-fanctrl", description="${description}", @@ -34,7 +31,6 @@ python3Packages.buildPythonPackage rec{ platforms=["linux"], py_modules=[], - install_requires=install_requires, scripts=[ "fanctrl.py", ], From 9479a377c8647fb9ba54dd1dd43870f4040d7d69 Mon Sep 17 00:00:00 2001 From: Svenum Date: Tue, 21 May 2024 17:32:42 +0200 Subject: [PATCH 42/59] update action --- .github/workflows/nix-build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index d6205f9..72652a1 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -1,9 +1,7 @@ name: "Test" on: pull_request: - branches: - - main - - packaging/nix + jobs: tests: runs-on: ubuntu-latest From f36419e93a44e54f3c37491abaa5d6afe28f4677 Mon Sep 17 00:00:00 2001 From: Svenum Date: Tue, 21 May 2024 17:34:29 +0200 Subject: [PATCH 43/59] rename workflow test --- .github/workflows/nix-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 72652a1..a5249ce 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -3,7 +3,7 @@ on: pull_request: jobs: - tests: + Build-Package: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 48dfd759dd59f9c933fb3599cbea793f4e0c2994 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 24 May 2024 15:09:54 +0200 Subject: [PATCH 44/59] fix service --- nix/module.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 99a587f..8b13bcd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -101,7 +101,8 @@ in serviceConfig = { Type = "simple"; Restart = "always"; - ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --config /etc/fw-fanctrl/config.json --no-log"; + ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --run --config /etc/fw-fanctrl/config.json --no-log"; + ExecStopPost = "${fw-ectool}/bin/ectool autofanctrl"; }; enable = true; wantedBy = [ "multi-user.target" ]; From 99c36bae347ee531ba22280590e547895343b355 Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 24 May 2024 22:44:20 +0200 Subject: [PATCH 45/59] try --- install.sh | 4 +++- nix/module.nix | 30 +++++++++++++++--------------- nix/packages/fw-fanctrl.nix | 14 ++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index f3057c1..bbf9233 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,9 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] +echo $(whoami) + +if [ "$EUID" -ne 0 ] && [ $(whoami) != "nixbld" ] then echo "This program requires root permissions" exit 1 fi diff --git a/nix/module.nix b/nix/module.nix index 8b13bcd..b8e549d 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -95,21 +95,21 @@ in }; # Create Service - systemd.services.fw-fanctrl = { - description = "Framework Fan Controller"; - after = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - Restart = "always"; - ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --run --config /etc/fw-fanctrl/config.json --no-log"; - ExecStopPost = "${fw-ectool}/bin/ectool autofanctrl"; - }; - enable = true; - wantedBy = [ "multi-user.target" ]; - }; + #systemd.services.fw-fanctrl = { + # description = "Framework Fan Controller"; + # after = [ "multi-user.target" ]; + # serviceConfig = { + # Type = "simple"; + # Restart = "always"; + # ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --run --config /etc/fw-fanctrl/config.json --no-log"; + # ExecStopPost = "${fw-ectool}/bin/ectool autofanctrl"; + # }; + # enable = true; + # wantedBy = [ "multi-user.target" ]; + #}; - # Create suspend config - environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); + ## Create suspend config + #environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = + # pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); }; } diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index 962668f..07af163 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -1,10 +1,10 @@ { lib, -lm_sensors, python3Packages, python3, bash, -callPackage +callPackage, +getopt }: let @@ -40,26 +40,24 @@ python3Packages.buildPythonPackage rec{ nativeBuildInputs = [ python3 + getopt ]; - propagatedBuildInputs = with python3Packages; [ - watchdog + propagatedBuildInputs = [ (callPackage ./fw-ectool.nix {}) - lm_sensors ]; doCheck = false; postPatch = '' patchShebangs --build fanctrl.py + patchShebangs --build install.sh substituteInPlace fanctrl.py --replace "/bin/bash" "${bash}/bin/bash" cat fanctrl.py ''; installPhase = '' - mkdir -p $out/bin - mv ./fanctrl.py $out/bin/fw-fanctrl - chmod 755 $out/bin/fw-fanctrl + ./install.sh --dest-dir $out --prefix-dir "" --no-ectool --no-post-install ''; meta = with lib; { From 70e632e56c928164aa19e15ec0da68b83a7dc8cf Mon Sep 17 00:00:00 2001 From: Svenum Date: Fri, 24 May 2024 22:47:56 +0200 Subject: [PATCH 46/59] try --- nix/module.nix | 30 +++++++++++++++--------------- nix/packages/fw-fanctrl.nix | 2 ++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index b8e549d..8b13bcd 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -95,21 +95,21 @@ in }; # Create Service - #systemd.services.fw-fanctrl = { - # description = "Framework Fan Controller"; - # after = [ "multi-user.target" ]; - # serviceConfig = { - # Type = "simple"; - # Restart = "always"; - # ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --run --config /etc/fw-fanctrl/config.json --no-log"; - # ExecStopPost = "${fw-ectool}/bin/ectool autofanctrl"; - # }; - # enable = true; - # wantedBy = [ "multi-user.target" ]; - #}; + systemd.services.fw-fanctrl = { + description = "Framework Fan Controller"; + after = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + Restart = "always"; + ExecStart = "${fw-fanctrl}/bin/fw-fanctrl --run --config /etc/fw-fanctrl/config.json --no-log"; + ExecStopPost = "${fw-ectool}/bin/ectool autofanctrl"; + }; + enable = true; + wantedBy = [ "multi-user.target" ]; + }; - ## Create suspend config - #environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - # pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); + # Create suspend config + environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = + pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); }; } diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index 07af163..94e0699 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -58,6 +58,8 @@ python3Packages.buildPythonPackage rec{ installPhase = '' ./install.sh --dest-dir $out --prefix-dir "" --no-ectool --no-post-install + rm -rf $out/etc + rm -rf $out/lib ''; meta = with lib; { From 4b4545ed27ded1f3f0c0497b40f8e3c2ee90761e Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 13:41:27 +0200 Subject: [PATCH 47/59] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7af4c03..7523c0d 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,9 @@ For NixOS this repo contains an Flake. You could add it to your config like this ```nix { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; fw-fanctrl = { - url = "github:TamtamHero/fw-fanctrl/main; # This is NOT a stable tested version + url = "github:TamtamHero/fw-fanctrl/packaging/nix; inputs.nixpkgs.follows = "nixpkgs"; }; }; From c74fcd598b22d2ce115ee1746b2255d9073332a5 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 16:48:21 +0200 Subject: [PATCH 48/59] Update README.md --- README.md | 132 +++++++++++++++++++----------------------------------- 1 file changed, 45 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 7523c0d..04273c4 100644 --- a/README.md +++ b/README.md @@ -8,93 +8,6 @@ Under the hood, it uses [ectool](https://gitlab.howett.net/DHowett/ectool) to ch It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs and with or without discrete GPU. # Install - -**This discribes how to install fw-fanctrl on every distro that is not NixOS! If you want to use it on NixOS, use [these](#nixos) instructions** - -## Dependancies - -To communicate with the embedded controller the `ectool` is required. -You can either use the precompiled executable of `ectool` in this repo or -disable its installation (`--no-ectool`) and add your own by recompiling it from [this repo](https://gitlab.howett.net/DHowett/ectool) and putting it in `[dest-dir(/)]/bin`. - -You also need to disable secure boot of your device for `ectool` to work (more details about why [here](https://www.howett.net/posts/2021-12-framework-ec/#using-fw-ectool)) - -Then run: -``` -sudo ./install.sh -``` - -This bash script will to create and activate a service that runs this repo's main script, `fanctrl.py`. -It will copy `fanctrl.py` (to an executable file `fw-fanctrl`) and `./bin/ectool` to `[dest-dir(/)]/bin` and create a config file -in `[dest-dir(/)][sysconf-dir(/etc)]/fw-fanctrl/config.json` - -this script also includes options to: -- specify an installation destination directory (`--dest-dir `). -- specify an installation prefix directory (`--prefix-dir `). -- specify a default configuration directory (`--sysconf-dir `). -- disable ectool installation and service activation (`--no-ectool`) -- disable post-install process (`--no-post-install`) - -# Update - -To install an update, you can pull the latest commit on the `main` branch of this repository, and run the install script again. - -# Uninstall -``` -sudo ./install.sh --remove -``` - -# Configuration - -There is a single `config.json` file located at `[dest-dir(/)][sysconf-dir(/etc)]/fw-fanctrl/config.json`. - -(You will need to reload the configuration with) -``` -fw-fanctrl --reload -``` - -It contains different strategies, ranked from the most silent to the noisiest. It is possible to specify two different strategies for charging/discharging allowing for different optimization goals. -On discharging one could have fan curve optimized for low fan speeds in order to save power while accepting a bit more heat. -On charging one could have a fan curve that focuses on keeping the CPU from throttling and the system cool, at the expense of fan noise. -You can add new strategies, and if you think you have one that deserves to be shared, feel free to make a PR to this repo :) - -Strategies can be configured with the following parameters: - -- **SpeedCurve**: - - This is the curve points for `f(temperature) = fan speed` - - `fw-fanctrl` measures the CPU temperature, compute a moving average of it, and then find an appropriate `fan speed` value by interpolation on the curve. - -- **FanSpeedUpdateFrequency**: - - Time interval between every update to the fan's speed. `fw-fanctrl` measures temperature every second and add it to its moving average, but the actual update to fan speed is controlled using this configuration. This is for comfort, otherwise the speed is changed too often and it is noticeable and annoying, especially at low speed. - For a more reactive fan, you can lower this setting. **Defaults to 5 seconds.** - -- **MovingAverageInterval**: - - Number of seconds on which the moving average of temperature is computed. Increase it, and the fan speed will change more gradually. Lower it, and it will gain in reactivity. **Defaults to 20 seconds.** - -## Charging/Discharging strategies - -The strategy active by default is the one specified in the `defaultStrategy` entry. Optionally a separate strategy only active during discharge can be defined, using the `strategyOnDischarging` entry. By default no extra strategy for discharging is provided, the default stratgy is active during all times. - -# Commands - -| option | contexte | description | -|-------------------|-----------------|---------------------------------| -| \ | run & configure | the name of the strategy to use | -| --run | run | run the service | -| --config | run | specify the configuration path | -| --no-log | run | disable state logging | -| --query, -q | configure | print the current strategy name | -| --list-strategies | configure | print the available strategies | -| --reload, -r | configure | reload the configuration file | -| --pause | configure | temporarily disable the service | -| --resume | configure | resume the service | - -# NixOS - For NixOS this repo contains an Flake. You could add it to your config like this: ```nix @@ -147,3 +60,48 @@ programs.fw-fanctrl.config = builtins.fromJSON (builtins.readFile ./config.json) # Or just change the default strategy form the default config programs.fw-fanctrl.config.defaultStrategy = "medium"; ``` + +Non NixOS install is described [here](https://github.com/TamtamHero/fw-fanctrl/blob/main/README.md#Install) + +# Configuration + +The default config contains different strategies, ranked from the most silent to the noisiest. It is possible to specify two different strategies for charging/discharging allowing for different optimization goals. +On discharging one could have fan curve optimized for low fan speeds in order to save power while accepting a bit more heat. +On charging one could have a fan curve that focuses on keeping the CPU from throttling and the system cool, at the expense of fan noise. +You can add new strategies, and if you think you have one that deserves to be shared, feel free to make a PR to this repo :) + +Strategies can be configured with the following parameters: + +- **SpeedCurve**: + + This is the curve points for `f(temperature) = fan speeds` + + `fw-fanctrl` measures the CPU temperature, compute a moving average of it, and then find an appropriate `fan speed` value by interpolation on the curve. + +- **FanSpeedUpdateFrequency**: + + Time interval between every update to the fan's speed. `fw-fanctrl` measures temperature every second and add it to its moving average, but the actual update to fan speed is controlled using this configuration. This is for comfort, otherwise the speed is changed too often and it is noticeable and annoying, especially at low speed. + For a more reactive fan, you can lower this setting. **Defaults to 5 seconds.** + +- **MovingAverageInterval**: + + Number of seconds on which the moving average of temperature is computed. Increase it, and the fan speed will change more gradually. Lower it, and it will gain in reactivity. **Defaults to 20 seconds.** + +## Charging/Discharging strategies + +The strategy active by default is the one specified in the `defaultStrategy` entry. Optionally a separate strategy only active during discharge can be defined, using the `strategyOnDischarging` entry. By default no extra strategy for discharging is provided, the default stratgy is active during all times. + +# Commands + +| option | contexte | description | +|-------------------|-----------------|---------------------------------| +| \ | run & configure | the name of the strategy to use | +| --run | run | run the service | +| --config | run | specify the configuration path | +| --no-log | run | disable state logging | +| --query, -q | configure | print the current strategy name | +| --list-strategies | configure | print the available strategies | +| --reload, -r | configure | reload the configuration file | +| --pause | configure | temporarily disable the service | +| --resume | configure | resume the service | + From 9ea8fb60a692d8482b3a10ac6a387124253f333b Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 16:49:57 +0200 Subject: [PATCH 49/59] chagne flake description --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 948a04a..1c8816a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A software to control the Framework fan speed"; + description = "A simple systemd service to better control Framework Laptop's fan(s)"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; From 3163d8efdcfda25d85e5d1f1080656e5c1044dac Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 16:55:28 +0200 Subject: [PATCH 50/59] fix suspend script --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 8b13bcd..921472b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -110,6 +110,6 @@ in # Create suspend config environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "runuser" "logname" "fw-fanctrl" ] [ "${pkgs.util-linux}/bin/runuser" "${pkgs.coreutils}/bin/logname" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); + pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend); }; } From f8ad4b88301e05ffbb002e54215c71ec01017598 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 17:05:40 +0200 Subject: [PATCH 51/59] fix script --- nix/module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/module.nix b/nix/module.nix index 921472b..b3048d6 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -110,6 +110,6 @@ in # Create suspend config environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend); + pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "#!/bin/sh" ''/usr/bin/python3 "%PREFIX_DIRECTORY%/bin/fw-fanctrl'' ] [ "" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); }; } From 023b74fd0d83c97f3819a5fccdd21bc0f62970a0 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 18:16:33 +0200 Subject: [PATCH 52/59] fix path --- nix/module.nix | 9 ++++++--- nix/packages/fw-fanctrl.nix | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index b3048d6..7aa53c9 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,4 +1,4 @@ -{ options, config, lib, pkgs, ... }: +{ options, config, lib, pkgs, stdenv, ... }: with lib; with lib.types; @@ -109,7 +109,10 @@ in }; # Create suspend config - environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = - pkgs.writeShellScript "fw-fanctrl-suspend.sh" (builtins.replaceStrings [ "#!/bin/sh" ''/usr/bin/python3 "%PREFIX_DIRECTORY%/bin/fw-fanctrl'' ] [ "" "${fw-fanctrl}/bin/fw-fanctrl" ] (builtins.readFile ../services/system-sleep/fw-fanctrl-suspend)); + environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source = pkgs.writeShellScript "fw-fanctrl-suspend" ( + builtins.replaceStrings [ ''/usr/bin/python3 "%PREFIX_DIRECTORY%/bin/fw-fanctrl"'' "/bin/bash" ] [ "${fw-fanctrl}/bin/fw-fanctrl" "" ] ( + builtins.readFile ../services/system-sleep/fw-fanctrl-suspend + ) + ); }; } diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index 94e0699..6e18be1 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -41,6 +41,7 @@ python3Packages.buildPythonPackage rec{ nativeBuildInputs = [ python3 getopt + bash ]; propagatedBuildInputs = [ @@ -52,8 +53,6 @@ python3Packages.buildPythonPackage rec{ postPatch = '' patchShebangs --build fanctrl.py patchShebangs --build install.sh - substituteInPlace fanctrl.py --replace "/bin/bash" "${bash}/bin/bash" - cat fanctrl.py ''; installPhase = '' From 6f3a1f08bd5f08d20655e5ef536d629d04a0b5af Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 18:31:11 +0200 Subject: [PATCH 53/59] fix install.sh --- install.sh | 16 +++++++++------- nix/packages/fw-fanctrl.nix | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index bbf9233..fade186 100755 --- a/install.sh +++ b/install.sh @@ -1,12 +1,6 @@ #!/bin/bash set -e -echo $(whoami) - -if [ "$EUID" -ne 0 ] && [ $(whoami) != "nixbld" ] - then echo "This program requires root permissions" - exit 1 -fi # Argument parsing SHORT=r,d:,p:,s:,h @@ -22,6 +16,7 @@ SYSCONF_DIR="/etc" SHOULD_INSTALL_ECTOOL=true SHOULD_POST_INSTALL=true SHOULD_REMOVE=false +NO_SUDO=false eval set -- "$VALID_ARGS" while true; do @@ -47,6 +42,8 @@ while true; do '--no-post-install') SHOULD_POST_INSTALL=false ;; + '--no-sudo') + NO_SUDO=true '--help' | '-h') echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install]" 1>&2 exit 0 @@ -57,7 +54,12 @@ while true; do esac shift done -# + +# Root check +if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ] + then echo "This program requires root permissions" + exit 1 +fi SERVICES_DIR="./services" SERVICE_EXTENSION=".service" diff --git a/nix/packages/fw-fanctrl.nix b/nix/packages/fw-fanctrl.nix index 6e18be1..0e207fa 100644 --- a/nix/packages/fw-fanctrl.nix +++ b/nix/packages/fw-fanctrl.nix @@ -56,7 +56,7 @@ python3Packages.buildPythonPackage rec{ ''; installPhase = '' - ./install.sh --dest-dir $out --prefix-dir "" --no-ectool --no-post-install + ./install.sh --dest-dir $out --prefix-dir "" --no-ectool --no-post-install --no-sudo rm -rf $out/etc rm -rf $out/lib ''; From 36b44924cf882a6bde630dc15c6f265429246682 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 18:33:42 +0200 Subject: [PATCH 54/59] fix --no-sudo --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index fac1540..9c4abc8 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ set -e # Argument parsing SHORT=r,d:,p:,s:,h -LONG=remove,dest-dir:,prefix-dir:,sysconf-dir:,no-ectool,no-pre-uninstall,no-post-install,help +LONG=remove,dest-dir:,prefix-dir:,sysconf-dir:,no-ectool,no-pre-uninstall,no-post-install,no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; @@ -48,6 +48,7 @@ while true; do ;; '--no-sudo') NO_SUDO=true + ;; '--help' | '-h') echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install] [--no-pre-uninstall]" 1>&2 exit 0 From 23dc250948865da0f5ef8154a22ccf99bc41957e Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 18:55:35 +0200 Subject: [PATCH 55/59] add --no-sudo to other scripts --- install.sh | 6 +++--- post-install.sh | 20 ++++++++++++-------- pre-uninstall.sh | 19 ++++++++++++------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 9c4abc8..1782d71 100755 --- a/install.sh +++ b/install.sh @@ -50,7 +50,7 @@ while true; do NO_SUDO=true ;; '--help' | '-h') - echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install] [--no-pre-uninstall]" 1>&2 + echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install] [--no-pre-uninstall] [--no-sudo]" 1>&2 exit 0 ;; --) @@ -91,7 +91,7 @@ function uninstall_legacy() { function uninstall() { if [ "$SHOULD_PRE_UNINSTALL" = true ]; then - ./pre-uninstall.sh + ./pre-uninstall.sh $( (( NO_SUDO == true )) && echo "--no-sudo" ) fi # remove program services based on the services present in the './services' folder echo "removing services" @@ -176,7 +176,7 @@ function install() { done done if [ "$SHOULD_POST_INSTALL" = true ]; then - ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" + ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" $( (( NO_SUDO == true )) && echo "--no-sudo" ) fi } diff --git a/post-install.sh b/post-install.sh index c92e74a..f3108db 100755 --- a/post-install.sh +++ b/post-install.sh @@ -1,16 +1,12 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] - then echo "This program requires root permissions" - exit 1 -fi - HOME_DIR="$(eval echo "~$(logname)")" # Argument parsing +NO_SUDO=false SHORT=d:,s:,h -LONG=dest-dir:,sysconf-dir:,help +LONG=dest-dir:,sysconf-dir:,no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; @@ -30,8 +26,11 @@ while true; do SYSCONF_DIR=$2 shift ;; + '--no-sudo') + NO_SUDO=true + ;; '--help' | '-h') - echo "Usage: $0 [--dest-dir,-d ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)]" 1>&2 + echo "Usage: $0 [--dest-dir,-d ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-sudo]" 1>&2 exit 0 ;; --) @@ -40,7 +39,12 @@ while true; do esac shift done -# + +# Root check +if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ] + then echo "This program requires root permissions" + exit 1 +fi SERVICES_DIR="./services" SERVICE_EXTENSION=".service" diff --git a/pre-uninstall.sh b/pre-uninstall.sh index 9ca3953..bbdd9ac 100755 --- a/pre-uninstall.sh +++ b/pre-uninstall.sh @@ -1,14 +1,10 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] - then echo "This program requires root permissions" - exit 1 -fi - HOME_DIR="$(eval echo "~$(logname)")" # Argument parsing +NO_SUDO=false SHORT=h LONG=help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") @@ -19,8 +15,11 @@ fi eval set -- "$VALID_ARGS" while true; do case "$1" in + '--no-sudo') + NO_SUDO=true + ;; '--help' | '-h') - echo "Usage: $0" 1>&2 + echo "Usage: $0 [--no-sudo]" 1>&2 exit 0 ;; --) @@ -29,7 +28,13 @@ while true; do esac shift done -# + +# Root check +if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ] + then echo "This program requires root permissions" + exit 1 +fi + SERVICES_DIR="./services" SERVICE_EXTENSION=".service" From 3e20444ff941519fef0f7eaf825199398eca3d43 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 19:11:51 +0200 Subject: [PATCH 56/59] fix check --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 1782d71..2431c34 100755 --- a/install.sh +++ b/install.sh @@ -91,7 +91,7 @@ function uninstall_legacy() { function uninstall() { if [ "$SHOULD_PRE_UNINSTALL" = true ]; then - ./pre-uninstall.sh $( (( NO_SUDO == true )) && echo "--no-sudo" ) + ./pre-uninstall.sh $([ "$NO_SUDO" = true ] && echo "--no-sudo") fi # remove program services based on the services present in the './services' folder echo "removing services" @@ -176,7 +176,7 @@ function install() { done done if [ "$SHOULD_POST_INSTALL" = true ]; then - ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" $( (( NO_SUDO == true )) && echo "--no-sudo" ) + ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" $([ "$NO_SUDO" = true ] && echo "--no-sudo") fi } From 053eec90ceba733804265d4dbaf570e6cfe4dcf7 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 19:12:56 +0200 Subject: [PATCH 57/59] add option check --- pre-uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-uninstall.sh b/pre-uninstall.sh index bbdd9ac..ad21f5d 100755 --- a/pre-uninstall.sh +++ b/pre-uninstall.sh @@ -6,7 +6,7 @@ HOME_DIR="$(eval echo "~$(logname)")" # Argument parsing NO_SUDO=false SHORT=h -LONG=help +LONG=no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; From f68de1e6bc96aa4665c1addd10bfcc702562c296 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 19:18:14 +0200 Subject: [PATCH 58/59] add missing " --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 2431c34..4aced48 100755 --- a/install.sh +++ b/install.sh @@ -91,7 +91,7 @@ function uninstall_legacy() { function uninstall() { if [ "$SHOULD_PRE_UNINSTALL" = true ]; then - ./pre-uninstall.sh $([ "$NO_SUDO" = true ] && echo "--no-sudo") + ./pre-uninstall.sh "$([ "$NO_SUDO" = true ] && echo "--no-sudo")" fi # remove program services based on the services present in the './services' folder echo "removing services" @@ -176,7 +176,7 @@ function install() { done done if [ "$SHOULD_POST_INSTALL" = true ]; then - ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" $([ "$NO_SUDO" = true ] && echo "--no-sudo") + ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" "$([ "$NO_SUDO" = true ] && echo "--no-sudo")" fi } From 61aebd4ff79deb4a30a67696c5c39e8a1a220487 Mon Sep 17 00:00:00 2001 From: Svenum Date: Sat, 1 Jun 2024 19:26:32 +0200 Subject: [PATCH 59/59] Rename nix action --- .github/workflows/nix-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index a5249ce..27a5605 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -1,4 +1,4 @@ -name: "Test" +name: "Nix packaging test" on: pull_request: