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 35 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
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 @@ -342,4 +345,3 @@ fabric.properties

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

55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)**
Svenum marked this conversation as resolved.
Show resolved Hide resolved

## Dependancies

This tool depends on `lm-sensors` to fetch CPU temperature:
Expand Down Expand Up @@ -78,3 +80,56 @@ 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
leopoldhub marked this conversation as resolved.
Show resolved Hide resolved

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 = {
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";
```
2 changes: 1 addition & 1 deletion fanctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 software to controll the Framework fan speed";
Svenum marked this conversation as resolved.
Show resolved Hide resolved

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;
};
}
6 changes: 3 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ 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"
cp -n "./config.json" "$HOME/.config/fw-fanctrl/" || true
mkdir -p "/etc/fw-fanctrl"
cp -n "./config.json" "/etc/fw-fanctrl/config.json" || true

Choose a reason for hiding this comment

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

Uninstall needs to be adapted too.

Copy link
Collaborator

@leopoldhub leopoldhub May 13, 2024

Choose a reason for hiding this comment

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

I am working on another PR that does includes this change and transition from previous config to /etc.
I will submit it after PR #29 is merged 👍

https://github.com/leopoldhub/fw-fanctrl/tree/dev


# cleaning legacy file
rm "/usr/local/bin/fanctrl.py" 2> "/dev/null" || true
Expand Down Expand Up @@ -120,4 +120,4 @@ else
echo "Unknown command '$1'"
exit 1
fi
exit 0
exit 0
117 changes: 117 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{ options, config, lib, pkgs, ... }:

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
{
options.programs.fw-fanctrl = {
enable = mkOption {
type = bool;
default = false;
description = ''
Enable fw-fanctrl systemd service and install the needed packages.
'';
};
configFile = mkOption {

Choose a reason for hiding this comment

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

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is outdated, I will remove it

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;
default = defaultConfig.defaultStrategy;
description = "Default strategy to use";
};
strategyOnDischarging = mkOption {
type = str;
default = defaultConfig.strategyOnDischarging;
description = "Default strategy on discharging";
};
batteryChargingStatusPath = mkOption {
type = str;
default = defaultConfig.batteryChargingStatusPath;
};
strategies = mkOption {
default = defaultConfig.strategies;
type = attrsOf (submodule (
{ options, name, ... }:
{
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 {
default = [];
type = listOf (submodule (
{ options, ... }:
{
options = {
temp = mkOption {
type = int;
default = 0;
description = "Tempreture on which the fan speed should be changed";
Svenum marked this conversation as resolved.
Show resolved Hide resolved
};
speed = mkOption {
type = int;
default = 0;
description = "Percent how fast the fan should run at";
};
};
}
));
};
};
}
));
};
};
};

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

# Create config
environment.etc."fw-fanctrl/config.json" = {
text = builtins.toJSON cfg.config;
};

# 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 --config /etc/fw-fanctrl/config.json --no-log";
};
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));
leopoldhub marked this conversation as resolved.
Show resolved Hide resolved
};
}
43 changes: 43 additions & 0 deletions nix/packages/fw-ectool.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
stdenv,
lib,
autoPatchelfHook,
libusb1,
libftdi1
}:

stdenv.mkDerivation {
version = "20-04-2024";
name = "fw-ectool";
src = ../../.;

outputs = [ "out" ];

nativeBuildInputs = [
autoPatchelfHook
];

propagatedBuildInputs = [
libusb1
libftdi1
];

installPhase = ''
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;

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" ];
};
}
Loading