asusd: allow specifying configs via paths

This commit is contained in:
Marcin Serwin
2024-12-23 17:02:04 +01:00
parent 8fa4a6c597
commit 1d2118f727
+92 -68
View File
@@ -24,73 +24,95 @@ in
];
options = {
services.asusd = {
enable = lib.mkEnableOption "the asusd service for ASUS ROG laptops";
services.asusd =
with lib.types;
let
configType = submodule (
{ text, source, ... }:
{
options = {
text = lib.mkOption {
default = null;
type = nullOr lines;
description = "Text of the file.";
};
package = lib.mkPackageOption pkgs "asusctl" { };
source = lib.mkOption {
default = null;
type = nullOr path;
description = "Path of the source file.";
};
};
}
);
in
{
enable = lib.mkEnableOption "the asusd service for ASUS ROG laptops";
enableUserService = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Activate the asusd-user service.
'';
package = lib.mkPackageOption pkgs "asusctl" { };
enableUserService = lib.mkOption {
type = bool;
default = false;
description = ''
Activate the asusd-user service.
'';
};
animeConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/anime.ron.
See https://asus-linux.org/asusctl/#anime-control.
'';
};
asusdConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/asusd.ron.
See https://asus-linux.org/asusctl/.
'';
};
auraConfigs = lib.mkOption {
type = attrsOf configType;
default = { };
description = ''
The content of /etc/asusd/aura_<name>.ron.
See https://asus-linux.org/asusctl/#led-keyboard-control.
'';
};
profileConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/profile.ron.
See https://asus-linux.org/asusctl/#profiles.
'';
};
fanCurvesConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/fan_curves.ron.
See https://asus-linux.org/asusctl/#fan-curves.
'';
};
userLedModesConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/asusd-user-ledmodes.ron.
See https://asus-linux.org/asusctl/#led-keyboard-control.
'';
};
};
animeConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The content of /etc/asusd/anime.ron.
See https://asus-linux.org/asusctl/#anime-control.
'';
};
asusdConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The content of /etc/asusd/asusd.ron.
See https://asus-linux.org/asusctl/.
'';
};
auraConfigs = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = { };
description = ''
The content of /etc/asusd/aura_<name>.ron.
See https://asus-linux.org/asusctl/#led-keyboard-control.
'';
};
profileConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The content of /etc/asusd/profile.ron.
See https://asus-linux.org/asusctl/#profiles.
'';
};
fanCurvesConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The content of /etc/asusd/fan_curves.ron.
See https://asus-linux.org/asusctl/#fan-curves.
'';
};
userLedModesConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The content of /etc/asusd/asusd-user-ledmodes.ron.
See https://asus-linux.org/asusctl/#led-keyboard-control.
'';
};
};
};
config = lib.mkIf cfg.enable {
@@ -100,10 +122,12 @@ in
let
maybeConfig =
name: cfg:
lib.mkIf (cfg != null) {
source = pkgs.writeText name cfg;
mode = "0644";
};
lib.mkIf (cfg != null) (
(if (cfg.source != null) then { source = cfg.source; } else { text = cfg.text; })
// {
mode = "0644";
}
);
in
{
"asusd/anime.ron" = maybeConfig "anime.ron" cfg.animeConfig;