mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 08:57:46 +00:00
nix: package superfreq; add NixOS module
This commit is contained in:
parent
fd23e1b9aa
commit
8f04194f95
4 changed files with 125 additions and 33 deletions
22
flake.lock
generated
22
flake.lock
generated
|
@ -4,13 +4,13 @@
|
|||
"locked": {
|
||||
"lastModified": 1746904237,
|
||||
"narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=",
|
||||
"owner": "nixos",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
|
@ -18,23 +18,7 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1689347949,
|
||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default-linux",
|
||||
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default-linux",
|
||||
"type": "github"
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
32
flake.nix
32
flake.nix
|
@ -1,22 +1,26 @@
|
|||
{
|
||||
description = "Superfreq";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
systems.url = "github:nix-systems/default-linux";
|
||||
};
|
||||
|
||||
outputs = inputs @ {
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
systems,
|
||||
}: let
|
||||
inherit (nixpkgs) lib;
|
||||
eachSystem = lib.genAttrs (import inputs.systems);
|
||||
pkgsFor = eachSystem (system: nixpkgs.legacyPackages.${system});
|
||||
...
|
||||
} @ inputs: let
|
||||
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux"];
|
||||
pkgsForEach = nixpkgs.legacyPackages;
|
||||
in {
|
||||
devShells = eachSystem (system: {
|
||||
default = pkgsFor.${system}.callPackage ./nix/shell.nix {};
|
||||
packages = forAllSystems (system: {
|
||||
superfreq = pkgsForEach.${system}.callPackage ./nix/package.nix {};
|
||||
default = self.packages.${system}.superfreq;
|
||||
});
|
||||
|
||||
devShells = forAllSystems (system: {
|
||||
default = pkgsForEach.${system}.callPackage ./nix/shell.nix {};
|
||||
});
|
||||
|
||||
nixosModules = {
|
||||
superfreq = import ./nix/module.nix inputs;
|
||||
default = self.nixosModules.superfreq;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
66
nix/module.nix
Normal file
66
nix/module.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
inputs: {
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.types) submodule;
|
||||
inherit (lib.meta) getExe;
|
||||
|
||||
cfg = config.programs.superfreq;
|
||||
|
||||
defaultPackage = inputs.self.packages.${pkgs.stdenv.system}.default;
|
||||
|
||||
format = pkgs.formats.toml {};
|
||||
in {
|
||||
options.programs.superfreq = {
|
||||
enable = mkEnableOption "Automatic CPU speed & power optimizer for Linux";
|
||||
|
||||
settings = mkOption {
|
||||
default = {};
|
||||
type = submodule {freeformType = format.type;};
|
||||
description = "Configuration for Superfreq.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [defaultPackage];
|
||||
|
||||
systemd = {
|
||||
packages = [defaultPackage];
|
||||
services.superfreq = {
|
||||
wantedBy = ["multi-user.target"];
|
||||
serviceConfig = let
|
||||
cfgFile = format.generate "superfreq-config.toml" cfg.settings;
|
||||
in {
|
||||
Environment = ["SUPERFREQ_CONFIG=${cfgFile}"];
|
||||
WorkingDirectory = "";
|
||||
ExecStart = "${getExe defaultPackage} daemon --verbose";
|
||||
Restart = "on-failure";
|
||||
|
||||
RuntimeDirectory = "superfreq";
|
||||
RuntimeDirectoryMode = "0755";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = !config.services.power-profiles-daemon.enable;
|
||||
message = ''
|
||||
You have set services.power-profiles-daemon.enable = true;
|
||||
which conflicts with Superfreq.
|
||||
'';
|
||||
}
|
||||
{
|
||||
assertion = !config.programs.auto-cpufreq.enable;
|
||||
message = ''
|
||||
You have set programs.auto-cpufreq.enable = true;
|
||||
which conflicts with Superfreq.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
38
nix/package.nix
Normal file
38
nix/package.nix
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
lib,
|
||||
rustPlatform,
|
||||
}: let
|
||||
fs = lib.fileset;
|
||||
in
|
||||
rustPlatform.buildRustPackage (finalAttrs: {
|
||||
pname = "superfreq";
|
||||
version = "0.1.0";
|
||||
|
||||
src = fs.toSource {
|
||||
root = ../.;
|
||||
fileset = fs.unions [
|
||||
(fs.fileFilter (file: builtins.any file.hasExt ["rs"]) ../src)
|
||||
../Cargo.lock
|
||||
../Cargo.toml
|
||||
];
|
||||
};
|
||||
|
||||
cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock";
|
||||
useFetchCargoVendor = true;
|
||||
enableParallelBuilding = true;
|
||||
|
||||
meta = {
|
||||
description = "Automatic CPU speed & power optimizer for Linux";
|
||||
longDescription = ''
|
||||
Superfreq is a CPU speed & power optimizer for Linux. It uses
|
||||
the CPU frequency scaling driver to set the CPU frequency
|
||||
governor and the CPU power management driver to set the CPU
|
||||
power management mode.
|
||||
|
||||
'';
|
||||
homepage = "https://github.com/NotAShelf/superfreq";
|
||||
mainProgram = "superfreq";
|
||||
license = lib.licenses.mpl20;
|
||||
platforms = lib.platforms.linux;
|
||||
};
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue