refactor(nix): reorganise files

This commit is contained in:
isabel 2023-10-13 15:31:59 +01:00
parent 37e12a4266
commit d710518c61
No known key found for this signature in database
GPG Key ID: CFF897835DD77813
4 changed files with 85 additions and 62 deletions

View File

@ -3,18 +3,17 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
}; };
outputs = {self, nixpkgs}@inputs : outputs = {nixpkgs, ...} @ inputs: let
let forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "x86_64-darwin" "i686-linux" "aarch64-linux" "aarch64-darwin"];
system = "x86_64-linux"; # replace this as needed pkgsForEach = nixpkgs.legacyPackages;
pkgs = nixpkgs.legacyPackages.${system};
auto-cpufreq = pkgs.python3Packages.callPackage ./nix/default.nix {};
in { in {
packages.${system}.default = auto-cpufreq; packages = forAllSystems (system: {
default = pkgsForEach.${system}.python3Packages.callPackage ./nix/default.nix {};
});
devShells.${system}.default = pkgs.mkShell { devShells = forAllSystems (system: {
inputsFrom = [ auto-cpufreq ]; default = pkgsForEach.${system}.callPackage ./nix/shell.nix {};
packages = [ pkgs.python310Packages.pip ]; });
};
nixosModules.default = import ./nix/module.nix inputs; nixosModules.default = import ./nix/module.nix inputs;
}; };

View File

@ -1,39 +1,46 @@
{ lib, python310Packages, fetchFromGitHub, callPackage, pkgs}: {
lib,
python310Packages.buildPythonPackage rec { python310Packages,
pkgs,
}:
python310Packages.buildPythonPackage {
# use pyproject.toml instead of setup.py # use pyproject.toml instead of setup.py
format = "pyproject"; format = "pyproject";
pname = "auto-cpufreq"; pname = "auto-cpufreq";
version = "2.0.0dev"; version = "2.0.0";
src = ../.; 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; doCheck = false;
pythonImportsCheck = [ "auto_cpufreq" ]; pythonImportsCheck = ["auto_cpufreq"];
patches = [ 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 ./patches/prevent-install-and-copy.patch
]; ];
postPatch = '' postPatch = ''
substituteInPlace auto_cpufreq/core.py --replace '/opt/auto-cpufreq/override.pickle' /var/run/override.pickle 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 scripts/org.auto-cpufreq.pkexec.policy --replace "/opt/auto-cpufreq/venv/bin/auto-cpufreq" $out/bin/auto-cpufreq
substituteInPlace auto_cpufreq/gui/app.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 = '' postInstall = ''
# copy script manually # copy script manually
cp scripts/cpufreqctl.sh $out/bin/cpufreqctl.auto-cpufreq 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 # systemd service
mkdir -p $out/lib/systemd/system mkdir -p $out/lib/systemd/system
cp scripts/auto-cpufreq.service $out/lib/systemd/system cp scripts/auto-cpufreq.service $out/lib/systemd/system
@ -55,7 +62,7 @@ python310Packages.buildPythonPackage rec {
description = "Automatic CPU speed & power optimizer for Linux"; description = "Automatic CPU speed & power optimizer for Linux";
license = licenses.lgpl3Plus; license = licenses.lgpl3Plus;
platforms = platforms.linux; platforms = platforms.linux;
maintainers = [ maintainers.Technical27 ]; maintainers = [maintainers.Technical27];
mainProgram = "auto-cpufreq"; mainProgram = "auto-cpufreq";
}; };
} }

View File

@ -1,7 +1,11 @@
inputs: { config, lib, pkgs, options, ... }: inputs: {
config,
lib,
pkgs,
options,
...
}:
with lib; let with lib; let
cfg = config.programs.auto-cpufreq; cfg = config.programs.auto-cpufreq;
system = "x86_64-linux"; system = "x86_64-linux";
defaultPackage = inputs.self.packages.${system}.default; defaultPackage = inputs.self.packages.${system}.default;
@ -9,14 +13,13 @@ with lib; let
cfgFile = format.generate cfgFilename cfg.settings; cfgFile = format.generate cfgFilename cfg.settings;
format = pkgs.formats.ini {}; format = pkgs.formats.ini {};
in { in {
options.programs.auto-cpufreq = { options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux"; enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
#gui.enable = mkEnableOption "Enable GUI";
settings = mkOption { settings = mkOption {
description = lib.mdDoc '' description = mdDoc ''
Configuration for `auto-cpufreq`. Configuration for `auto-cpufreq`.
See its [example configuration file] for supported settings. See its [example configuration file] for supported settings.
@ -24,19 +27,19 @@ in {
''; '';
default = {}; default = {};
type = types.submodule { freeformType = format.type; }; type = types.submodule {freeformType = format.type;};
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.systemPackages = [ defaultPackage ]; environment.systemPackages = [defaultPackage];
services.auto-cpufreq.enable = true; services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = { systemd.services.auto-cpufreq = {
overrideStrategy = "asDropin"; overrideStrategy = "asDropin";
serviceConfig.ExecStart = lib.mkForce [ serviceConfig.ExecStart = mkForce [
"" ""
"${defaultPackage}/bin/auto-cpufreq --daemon --config ${cfgFile}" "${getBin} ${defaultPackage} --daemon --config ${cfgFile}"
]; ];
}; };
}; };

14
nix/shell.nix Normal file
View File

@ -0,0 +1,14 @@
{
python310Packages,
python3Packages,
...
}: let
mainPkg = python3Packages.callPackage ./default.nix {};
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs =
[
python310Packages.pip
]
++ (oa.nativeBuildInputs or []);
})