Skip to content

Commit

Permalink
Update branch to main branch (#54)
Browse files Browse the repository at this point in the history
* Adding @Svenum as an assignee to nix-related issues (#43)

* Fixing adding @Svenum as an assignee to nix-related issues (#44)

(non contributors cannot be assigned to issues)

* Reload will report if config couldn't be parsed and the service keeps running. (#46)

Authored-by: Nina Alexandra Klama <[email protected]>

* Removing binary blobs from the project (#51)

* removing binary blobs from the project.
we now fetch the ectool from the gitlab artifacts and confirm the checksum.

* remove bin references from README.md

* extracting $TEMP_FOLDER from installEctool

* Fix README spelling/grammer, fix "FrameWork" capitalization in service description (#52)

* Review README spelling/grammar

* Fix "FrameWork" capitalization in service

* use ectool form nixpkgs

* update flake

* remove old deps

* remove duplicated pkgs

---------

Co-authored-by: Léopold Hubert <[email protected]>
Co-authored-by: Nina Alexandra Klama <[email protected]>
Co-authored-by: DeflateAwning <[email protected]>
  • Loading branch information
4 people authored Jun 30, 2024
1 parent d6d384b commit c51335b
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report---packaging-nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ If applicable, add the full error message.

**Additional context**
Add any other context about the problem here.

**Assigned maintainers**
- @Svenum
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,5 @@ fabric.properties

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

.temp
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
This is a simple Python service for Linux that drives Framework Laptop's fan(s) speed according to a configurable speed/temp curve.
Its default configuration targets very silent fan operation, but it's easy to configure it for a different comfort/performance trade-off.
Its possible to specify two separate fan curves depending on whether the Laptop is charging/discharging.
Under the hood, it uses [ectool](https://gitlab.howett.net/DHowett/ectool) to change parameters in FrameWork's embedded controller (EC).
Under the hood, it uses [ectool](https://gitlab.howett.net/DHowett/ectool) to change parameters in Framework's embedded controller (EC).

It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs and with or without discrete GPU.
It is compatible with all kinds of 13" and 16" models, both AMD/Intel CPUs, with or without a discrete GPU.

# Install
For NixOS this repo contains an Flake. You could add it to your config like this:
Expand Down Expand Up @@ -90,11 +90,11 @@ Strategies can be configured with the following parameters:

## 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.
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 strategy is active during all times.

# Commands

| option | contexte | description |
| Option | Context | Description |
|-------------------|-----------------|---------------------------------|
| \<strategy> | run & configure | the name of the strategy to use |
| --run | run | run the service |
Expand Down
Binary file removed bin/ectool
Binary file not shown.
16 changes: 11 additions & 5 deletions fanctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def __init__(self, path):

def reload(self):
with open(self.path, "r") as fp:
self.data = json.load(fp)
try:
self.data = json.load(fp)
except json.JSONDecodeError:
return False
return True

def getStrategies(self):
return self.data["strategies"].keys()
Expand Down Expand Up @@ -161,10 +165,12 @@ def bindSocket(self):
if args.list_strategies:
client_socket.sendall('\n'.join(self.configuration.getStrategies()).encode())
if args.reload:
self.configuration.reload()
if self.overwrittenStrategy is not None:
self.overwriteStrategy(self.overwrittenStrategy.name)
client_socket.sendall("Success".encode())
if self.configuration.reload():
if self.overwrittenStrategy is not None:
self.overwriteStrategy(self.overwrittenStrategy.name)
client_socket.sendall("Success".encode())
else:
client_socket.sendall("Error: Config file could not be parsed due to JSON Error".encode())
except:
pass
finally:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions fetch/ectool/linux/gitlab_job_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
899
1 change: 1 addition & 0 deletions fetch/ectool/linux/hash.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ab94a1e9a33f592d5482dbfd4f42ad351ef91227ee3b3707333c0107d7f2b1b0
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
localSystem = "x86_64-linux";
}).pkgs.callPackage ./nix/packages/fw-fanctrl.nix {};

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;
};
}
42 changes: 40 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if [[ $? -ne 0 ]]; then
exit 1;
fi

TEMP_FOLDER='./.temp'
trap 'rm -rf $TEMP_FOLDER' EXIT

PREFIX_DIR="/usr"
DEST_DIR=""
SYSCONF_DIR="/etc"
Expand Down Expand Up @@ -128,10 +131,12 @@ function uninstall() {
function install() {
uninstall_legacy

rm -rf "$TEMP_FOLDER"
mkdir -p "$DEST_DIR$PREFIX_DIR/bin"
if [ "$SHOULD_INSTALL_ECTOOL" = true ]; then
cp "./bin/ectool" "$DEST_DIR$PREFIX_DIR/bin/ectool"
chmod +x "$DEST_DIR$PREFIX_DIR/bin/ectool"
mkdir "$TEMP_FOLDER"
installEctool "$TEMP_FOLDER" || (echo "an error occurred when installing ectool." && echo "please check your internet connection or consider installing it manually and using --no-ectool on the installation script." && exit 1)
rm -rf "$TEMP_FOLDER"
fi
mkdir -p "$DEST_DIR$SYSCONF_DIR/fw-fanctrl"
cp "./fanctrl.py" "$DEST_DIR$PREFIX_DIR/bin/fw-fanctrl"
Expand Down Expand Up @@ -180,6 +185,39 @@ function install() {
fi
}

function installEctool() {
workingDirectory=$1
echo "installing ectool"

ectoolDestPath="$DEST_DIR$PREFIX_DIR/bin/ectool"

ectoolJobId="$(cat './fetch/ectool/linux/gitlab_job_id')"
ectoolSha256Hash="$(cat './fetch/ectool/linux/hash.sha256')"

artifactsZipFile="$workingDirectory/artifact.zip"

echo "downloading artifact from gitlab"
curl -s -S -o "$artifactsZipFile" -L "https://gitlab.howett.net/DHowett/ectool/-/jobs/${ectoolJobId}/artifacts/download?file_type=archive" || (echo "failed to download the artifact." && return 1)
if [[ $? -ne 0 ]]; then return 1; fi

echo "checking artifact sha256 sum"
actualEctoolSha256Hash=$(sha256sum "$artifactsZipFile" | cut -d ' ' -f 1)
if [[ "$actualEctoolSha256Hash" != "$ectoolSha256Hash" ]]; then
echo "Incorrect sha256 sum for ectool gitlab artifact '$ectoolJobId' : '$ectoolSha256Hash' != '$actualEctoolSha256Hash'"
return 1
fi

echo "extracting artifact"
{
unzip -q -j "$artifactsZipFile" '_build/src/ectool' -d "$workingDirectory" &&
cp "$workingDirectory/ectool" "$ectoolDestPath" &&
chmod +x "$ectoolDestPath"
} || (echo "failed to extract the artifact to its designated location." && return 1)
if [[ $? -ne 0 ]]; then return 1; fi

echo "ectool installed"
}

if [ "$SHOULD_REMOVE" = true ]; then
uninstall
else
Expand Down
7 changes: 3 additions & 4 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ with lib;
with lib.types;
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
Expand Down Expand Up @@ -84,9 +83,9 @@ in

config = mkIf cfg.enable {
# Install package
environment.systemPackages = [
environment.systemPackages = with pkgs; [
fw-fanctrl
fw-ectool
ectool
];

# Create config
Expand All @@ -102,7 +101,7 @@ in
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";
ExecStopPost = "${pkgs.ectool}/bin/ectool autofanctrl";
};
enable = true;
wantedBy = [ "multi-user.target" ];
Expand Down
43 changes: 0 additions & 43 deletions nix/packages/fw-ectool.nix

This file was deleted.

5 changes: 3 additions & 2 deletions nix/packages/fw-fanctrl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ python3Packages,
python3,
bash,
callPackage,
getopt
getopt,
ectool
}:

let
Expand Down Expand Up @@ -45,7 +46,7 @@ python3Packages.buildPythonPackage rec{
];

propagatedBuildInputs = [
(callPackage ./fw-ectool.nix {})
ectool
];

doCheck = false;
Expand Down
2 changes: 1 addition & 1 deletion services/fw-fanctrl.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=FrameWork Fan Controller
Description=Framework Fan Controller
After=multi-user.target
[Service]
Type=simple
Expand Down

0 comments on commit c51335b

Please sign in to comment.