Skip to content

Commit

Permalink
Merge pull request #582 from isabelroses/master
Browse files Browse the repository at this point in the history
refactor(flake): improve usage
  • Loading branch information
shadeyg56 authored Oct 13, 2023
2 parents 37e12a4 + 78a86a1 commit 964f2f5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 64 deletions.
31 changes: 15 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs = {self, nixpkgs}@inputs :
let
system = "x86_64-linux"; # replace this as needed
pkgs = nixpkgs.legacyPackages.${system};
auto-cpufreq = pkgs.python3Packages.callPackage ./nix/default.nix {};
in {
packages.${system}.default = auto-cpufreq;
outputs = {nixpkgs, ...} @ inputs: let
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "i686-linux" "aarch64-linux"];
pkgsForEach = nixpkgs.legacyPackages;
in {
packages = forAllSystems (system: {
default = pkgsForEach.${system}.python3Packages.callPackage ./nix/default.nix {};
});

devShells.${system}.default = pkgs.mkShell {
inputsFrom = [ auto-cpufreq ];
packages = [ pkgs.python310Packages.pip ];
};
devShells = forAllSystems (system: {
default = pkgsForEach.${system}.callPackage ./nix/shell.nix {};
});

nixosModules.default = import ./nix/module.nix inputs;
};
nixosModules.default = import ./nix/module.nix inputs;
};
}
33 changes: 20 additions & 13 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
{ lib, python310Packages, fetchFromGitHub, callPackage, pkgs}:

python310Packages.buildPythonPackage rec {
{
lib,
python310Packages,
pkgs,
}:
python310Packages.buildPythonPackage {
# use pyproject.toml instead of setup.py
format = "pyproject";

pname = "auto-cpufreq";
version = "2.0.0dev";
version = "2.0.0";
src = ../.;

nativeBuildInputs = with pkgs; [wrapGAppsHook gobject-introspection];

nativeBuildInputs = with pkgs; [ wrapGAppsHook gobject-introspection ];

buildInputs = with pkgs; [ gtk3 python310Packages.poetry-core ];
buildInputs = with pkgs; [gtk3 python310Packages.poetry-core];

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

doCheck = false;
pythonImportsCheck = [ "auto_cpufreq" ];
pythonImportsCheck = ["auto_cpufreq"];

patches = [

# patch to prevent script copying and to disable install
# patch to prevent script copying and to disable install
./patches/prevent-install-and-copy.patch

];

postPatch = ''
substituteInPlace auto_cpufreq/core.py --replace '/opt/auto-cpufreq/override.pickle' /var/run/override.pickle
substituteInPlace scripts/org.auto-cpufreq.pkexec.policy --replace "/opt/auto-cpufreq/venv/bin/auto-cpufreq" $out/bin/auto-cpufreq
substituteInPlace auto_cpufreq/gui/app.py auto_cpufreq/gui/objects.py --replace "/usr/local/share/auto-cpufreq/images/icon.png" $out/share/pixmaps/auto-cpufreq.png
substituteInPlace auto_cpufreq/gui/app.py --replace "/usr/local/share/auto-cpufreq/scripts/style.css" $out/share/auto-cpufreq/scripts/style.css
'';

postInstall = ''
# copy script manually
cp scripts/cpufreqctl.sh $out/bin/cpufreqctl.auto-cpufreq
# move the css to the rihgt place
mkdir -p $out/share/auto-cpufreq/scripts
cp scripts/style.css $out/share/auto-cpufreq/scripts/style.css
# systemd service
mkdir -p $out/lib/systemd/system
cp scripts/auto-cpufreq.service $out/lib/systemd/system
Expand All @@ -55,7 +62,7 @@ python310Packages.buildPythonPackage rec {
description = "Automatic CPU speed & power optimizer for Linux";
license = licenses.lgpl3Plus;
platforms = platforms.linux;
maintainers = [ maintainers.Technical27 ];
maintainers = [maintainers.Technical27];
mainProgram = "auto-cpufreq";
};
}
72 changes: 37 additions & 35 deletions nix/module.nix
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
inputs: { config, lib, pkgs, options, ... }:

inputs: {
config,
lib,
pkgs,
options,
...
}:
with lib; let
cfg = config.programs.auto-cpufreq;
inherit (pkgs.stdenv.hostPlatform) system;
defaultPackage = inputs.self.packages.${system}.default;
cfgFilename = "auto-cpufreq.conf";
cfgFile = format.generate cfgFilename cfg.settings;

cfg = config.programs.auto-cpufreq;
system = "x86_64-linux";
defaultPackage = inputs.self.packages.${system}.default;
cfgFilename = "auto-cpufreq.conf";
cfgFile = format.generate cfgFilename cfg.settings;

format = pkgs.formats.ini {};

format = pkgs.formats.ini {};
in {
options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";

options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
settings = mkOption {
description = mdDoc ''
Configuration for `auto-cpufreq`.
settings = mkOption {
description = lib.mdDoc ''
Configuration for `auto-cpufreq`.
See its [example configuration file] for supported settings.
[example configuration file]: https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto-cpufreq.conf-example
'';

See its [example configuration file] for supported settings.
[example configuration file]: https://github.com/AdnanHodzic/auto-cpufreq/blob/master/auto-cpufreq.conf-example
'';

default = {};
type = types.submodule { freeformType = format.type; };
};
default = {};
type = types.submodule {freeformType = format.type;};
};

config = mkIf cfg.enable {
environment.systemPackages = [ defaultPackage ];

services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = {
overrideStrategy = "asDropin";
serviceConfig.ExecStart = lib.mkForce [
""
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}"
];
};
};

config = mkIf cfg.enable {
environment.systemPackages = [defaultPackage];

services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = {
overrideStrategy = "asDropin";
serviceConfig.ExecStart = mkForce [
""
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}"
];
};
}
};
}
14 changes: 14 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
python310Packages,
python3Packages,
...
}: let
mainPkg = python3Packages.callPackage ./default.nix {};
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs =
[
python310Packages.pip
]
++ (oa.nativeBuildInputs or []);
})

0 comments on commit 964f2f5

Please sign in to comment.