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

Add NixOS Flake #26

Merged
merged 66 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
91883a2
initial
Svenum Apr 20, 2024
2429c60
update gitignore
Svenum Apr 20, 2024
68a710c
update inputs
Svenum Apr 20, 2024
231f2ca
add fw-ectool dependencie
Svenum May 3, 2024
a0a5e2a
Merge branch 'main' into add-flake
Svenum May 3, 2024
f06e0f5
add module
Svenum May 3, 2024
aac9461
fix tabs
Svenum May 3, 2024
eaa983c
fix package
Svenum May 3, 2024
1ef9e72
fix typo
Svenum May 3, 2024
8016fec
fix service
Svenum May 3, 2024
f50d730
fix type
Svenum May 3, 2024
f27ee51
add options
Svenum May 3, 2024
bd33e85
fix service
Svenum May 3, 2024
ab6de2c
fix build inputs
Svenum May 3, 2024
398203c
add Readme + add suspend script
Svenum May 3, 2024
4e823a9
remove unneeded };
Svenum May 3, 2024
690795e
fix pkgs.writeShellScript
Svenum May 3, 2024
bf785d2
remvoe \
Svenum May 3, 2024
01e7c59
try
Svenum May 6, 2024
d8b63b0
add self
Svenum May 6, 2024
a608a83
fix module
Svenum May 6, 2024
6f993e2
update package
Svenum May 6, 2024
40aac4a
merge
Svenum May 6, 2024
5036aa1
fix package
Svenum May 6, 2024
0f8f846
use sleep script
Svenum May 10, 2024
4afc942
add config options
Svenum May 10, 2024
dba838a
fix typo
Svenum May 10, 2024
6ee820f
fix typo
Svenum May 10, 2024
d4ce5af
add defaults
Svenum May 10, 2024
d246269
fix type
Svenum May 10, 2024
bcc1ac0
add prettyier
Svenum May 10, 2024
89bf5c7
remove beautifyer
Svenum May 10, 2024
a1c4b98
udpate readme
Svenum May 10, 2024
9f521ae
update installer script
Svenum May 10, 2024
7edb347
add missing path
Svenum May 10, 2024
636e5d7
Update README.md
Svenum May 11, 2024
55d8b61
Update flake.nix
Svenum May 11, 2024
cf298ed
Update nix/module.nix
Svenum May 11, 2024
c7436ec
add descriptions
Svenum May 11, 2024
7398b29
fix uninstall
Svenum May 11, 2024
87cd28f
update readme
Svenum May 11, 2024
985bd56
add description
Svenum May 13, 2024
8adc575
merge
Svenum May 17, 2024
f65de04
Merge branch 'packaging/nix' into add-flake
Svenum May 18, 2024
aee1011
remove requiremetns.txt + add github actions
Svenum May 21, 2024
9479a37
update action
Svenum May 21, 2024
f36419e
rename workflow test
Svenum May 21, 2024
da0fb21
Merge branch 'main' into add-flake
Svenum May 24, 2024
48dfd75
fix service
Svenum May 24, 2024
99c36ba
try
Svenum May 24, 2024
70e632e
try
Svenum May 24, 2024
4b4545e
Update README.md
Svenum Jun 1, 2024
c74fcd5
Update README.md
Svenum Jun 1, 2024
9ea8fb6
chagne flake description
Svenum Jun 1, 2024
3163d8e
fix suspend script
Svenum Jun 1, 2024
f8ad4b8
fix script
Svenum Jun 1, 2024
023b74f
fix path
Svenum Jun 1, 2024
d171862
Merge branch 'packaging/nix' into add-flake
Svenum Jun 1, 2024
6f3a1f0
fix install.sh
Svenum Jun 1, 2024
161a7a9
Merge branch 'add-flake' of github.com:Svenum/fw-fanctrl into add-flake
Svenum Jun 1, 2024
36b4492
fix --no-sudo
Svenum Jun 1, 2024
23dc250
add --no-sudo to other scripts
Svenum Jun 1, 2024
3e20444
fix check
Svenum Jun 1, 2024
053eec9
add option check
Svenum Jun 1, 2024
f68de1e
add missing "
Svenum Jun 1, 2024
61aebd4
Rename nix action
Svenum Jun 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Test"
Svenum marked this conversation as resolved.
Show resolved Hide resolved
on:
pull_request:

jobs:
Build-Package:
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

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Nix Build dir
/result

### Intellij template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down Expand Up @@ -343,4 +346,3 @@ fabric.properties

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

92 changes: 53 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,65 @@ 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

## 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:
For NixOS this repo contains an Flake. You could add it to your config like this:

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
fw-fanctrl = {
url = "github:TamtamHero/fw-fanctrl/packaging/nix;
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {nixpkgs, fw-fanctrl}: {
nixosConfigurations.foo = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
fw-fanctrl.nixosModules.default
configuration.nix
];
};
}
}
```
sudo ./install.sh
and then add in your *configuration.nix*:
```nix
# Enable fw-fanctrl
programs.fw-fanctrl.enable = true;

# Add a custom 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; }
];
};
};
};

# 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";
```

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`
Non NixOS install is described [here](https://github.com/TamtamHero/fw-fanctrl/blob/main/README.md#Install)

this script also includes options to:
- specify an installation destination directory (`--dest-dir <installation destination directory (defaults to /)>`).
- specify an installation prefix directory (`--prefix-dir <installation prefix directory (defaults to /usr)>`).
- specify a default configuration directory (`--sysconf-dir <system configuration destination directory (defaults to /etc)>`).
- disable ectool installation and service activation (`--no-ectool`)
- disable post-install process (`--no-post-install`)
- disable pre-uninstall process (`--no-pre-uninstall`)

# 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.
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 :)
Expand All @@ -61,7 +75,7 @@ Strategies can be configured with the following parameters:

- **SpeedCurve**:

This is the curve points for `f(temperature) = fan speed`
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.

Expand Down
44 changes: 44 additions & 0 deletions flake.lock

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

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "A simple systemd service to better control Framework Laptop's fan(s)";

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 = self.packages.x86_64-linux.fw-fanctrl;
packages.x86_64-linux.fw-fanctrl = (
import nixpkgs {
currentSystem = "x86_64-linux";
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;
};
}
23 changes: 14 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/bin/bash
set -e

if [ "$EUID" -ne 0 ]
then echo "This program requires root permissions"
exit 1
fi

# 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;
Expand All @@ -21,6 +17,7 @@ SHOULD_INSTALL_ECTOOL=true
SHOULD_PRE_UNINSTALL=true
SHOULD_POST_INSTALL=true
SHOULD_REMOVE=false
NO_SUDO=false

eval set -- "$VALID_ARGS"
while true; do
Expand Down Expand Up @@ -49,8 +46,11 @@ 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 <installation destination directory (defaults to $DEST_DIR)>] [--prefix-dir,-p <installation prefix directory (defaults to $PREFIX_DIR)>] [--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 <installation destination directory (defaults to $DEST_DIR)>] [--prefix-dir,-p <installation prefix directory (defaults to $PREFIX_DIR)>] [--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
;;
--)
Expand All @@ -59,7 +59,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"
Expand All @@ -86,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"
Expand Down Expand Up @@ -171,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
}

Expand Down
Loading