Skip to content

Commit

Permalink
asusd: allow specifying configs via paths
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-serwin committed Dec 23, 2024
1 parent 8fa4a6c commit 1d2118f
Showing 1 changed file with 86 additions and 62 deletions.
148 changes: 86 additions & 62 deletions nixos/modules/services/hardware/asusd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" { };

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.
'';
};
enableUserService = lib.mkOption {
type = bool;
default = false;
description = ''
Activate the asusd-user service.
'';
};

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/.
'';
};
animeConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/anime.ron.
See https://asus-linux.org/asusctl/#anime-control.
'';
};

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.
'';
};
asusdConfig = lib.mkOption {
type = nullOr configType;
default = null;
description = ''
The content of /etc/asusd/asusd.ron.
See https://asus-linux.org/asusctl/.
'';
};

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.
'';
};
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.
'';
};

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.
'';
};
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 = 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.
'';
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.
'';
};
};
};
};

config = lib.mkIf cfg.enable {
Expand All @@ -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;
Expand Down

0 comments on commit 1d2118f

Please sign in to comment.