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";
};
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 {};
outputs = {nixpkgs, ...} @ inputs: let
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "x86_64-darwin" "i686-linux" "aarch64-linux" "aarch64-darwin"];
pkgsForEach = nixpkgs.legacyPackages;
in {
packages.${system}.default = auto-cpufreq;
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;
};

View File

@ -1,14 +1,16 @@
{ 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];
buildInputs = with pkgs; [gtk3 python310Packages.poetry-core];
@ -19,21 +21,26 @@ python310Packages.buildPythonPackage rec {
pythonImportsCheck = ["auto_cpufreq"];
patches = [
# 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 --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

View File

@ -1,7 +1,11 @@
inputs: { config, lib, pkgs, options, ... }:
inputs: {
config,
lib,
pkgs,
options,
...
}:
with lib; let
cfg = config.programs.auto-cpufreq;
system = "x86_64-linux";
defaultPackage = inputs.self.packages.${system}.default;
@ -9,14 +13,13 @@ with lib; let
cfgFile = format.generate cfgFilename cfg.settings;
format = pkgs.formats.ini {};
in {
options.programs.auto-cpufreq = {
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
#gui.enable = mkEnableOption "Enable GUI";
settings = mkOption {
description = lib.mdDoc ''
description = mdDoc ''
Configuration for `auto-cpufreq`.
See its [example configuration file] for supported settings.
@ -34,9 +37,9 @@ in {
services.auto-cpufreq.enable = true;
systemd.services.auto-cpufreq = {
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 []);
})