Skip to content

Instantly share code, notes, and snippets.

@Dessix
Created May 2, 2023 01:38
Show Gist options
  • Save Dessix/4b931758be9ac2dfcd65c1b3db049afa to your computer and use it in GitHub Desktop.
Save Dessix/4b931758be9ac2dfcd65c1b3db049afa to your computer and use it in GitHub Desktop.
Systemd System-level OpenRGB service configuration to set lighting on startup
{
# ...
services.orgb = {
enable = true;
motherboard = "amd";
};
# ...
}
{config, pkgs, lib, ...}:
let
cfg = config.services.orgb;
wrapperSuffix = ".wrapped";
openrgb =
lib.overrideDerivation pkgs.openrgb (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.makeWrapper ];
# Wrap executables to set `XDG_CONFIG_HOME` to avoid https://github.com/NixOS/nixpkgs/issues/225762
postInstall = ''
set -e
for exe in $out/bin/*; do
makeWrapper "$exe" "''${exe}${wrapperSuffix}" \
--set XDG_CONFIG_HOME /var/lib/openrgb
done
set +e
'';
});
in
with lib; {
options = {
services.orgb = {
enable = mkOption {
default = false;
type = with types; bool;
description = ''
Start an openrgb daemon without a user.
'';
};
color = mkOption {
default = "000000";
type = with types; uniq string;
description = ''
Color to set all devices to on startup. See `man openrgb` for `--color`.
'';
};
mode = mkOption {
default = "off"; # "direct" / "static" / "off" / "breathing";
type = with types; uniq string;
description = ''
Mode to use for all devices on startup. See `man openrgb` for `--mode`.
'';
};
motherboard = mkOption {
type = types.nullOr (types.enum [ "amd" "intel" ]);
default = null;
description = ''
CPU family of motherboard. Allows for addition motherboard i2c support.
'';
};
server.port = mkOption {
type = types.port;
default = 6742;
description = lib.mdDoc "Set server port of openrgb.";
};
};
};
config =
let
wrapperPath = "${openrgb}/bin/openrgb${wrapperSuffix}";
startCommand = ''
${wrapperPath} \
--color "${cfg.color}" \
--mode "${cfg.mode}" \
--server \
--server-port ${toString cfg.server.port}
'';
in
mkIf cfg.enable {
environment.systemPackages = [ openrgb ];
services.udev.packages = [ openrgb ];
boot.kernelModules =
[ "i2c-dev" ]
++ lib.optionals (cfg.motherboard == "amd") [ "i2c-piix" ]
++ lib.optionals (cfg.motherboard == "intel") [ "i2c-i801" ];
systemd.services.openrgb = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "Start the openrgb service on startup.";
serviceConfig = {
Type = "simple";
ExecStart = startCommand;
};
};
};
meta.maintainers = [
{
email = "[email protected]";
matrix = "@Dessix:Dessix.net";
github = "Dessix";
githubId = 434942;
name = "Dessix Machina";
}
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment