diff --git a/config/default.nix b/config/default.nix index 2df5610..c370431 100644 --- a/config/default.nix +++ b/config/default.nix @@ -12,7 +12,6 @@ ./gaming.nix ./gnome-desktop.nix ./hardware.nix - ./keylightd.nix ./locale.nix ./media.nix ./networking.nix diff --git a/config/hardware.nix b/config/hardware.nix index 0d3751f..1ca098a 100644 --- a/config/hardware.nix +++ b/config/hardware.nix @@ -65,6 +65,8 @@ programs.yubikey-manager.enable = true; + services.keylightd.enable = true; + environment.systemPackages = with pkgs; [ (nvtopPackages.intel.override { amd = true; }) intel-gpu-tools diff --git a/config/keylightd.nix b/config/keylightd.nix deleted file mode 100644 index 6a75548..0000000 --- a/config/keylightd.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ lib, pkgs', ... }: -{ - environment.systemPackages = [ pkgs'.keylightd ]; - - users = { - users.keylightd = { - isSystemUser = true; - group = "keylightd"; - home = "/var/lib/keylightd"; - }; - groups.keylightd = { }; - }; - - systemd.services.keylightd = { - description = "Elgato Key Light daemon"; - wantedBy = [ "multi-user.target" ]; - wants = [ "network-online.target" ]; - after = [ "network-online.target" ]; - serviceConfig = { - ExecStart = lib.getExe pkgs'.keylightd; - Restart = "on-failure"; - RestartSec = "10s"; - User = "keylightd"; - Group = "keylightd"; - StateDirectory = "keylightd"; - RuntimeDirectory = "keylightd"; - RuntimeDirectoryMode = "0775"; - UMask = "0002"; - Environment = [ - "XDG_CONFIG_HOME=/var/lib/keylightd" - "XDG_RUNTIME_DIR=/run/keylightd" - ]; - NoNewPrivileges = true; - PrivateTmp = true; - ProtectSystem = "strict"; - ProtectHome = true; - ProtectKernelTunables = true; - ProtectKernelModules = true; - ProtectControlGroups = true; - RestrictRealtime = true; - RestrictSUIDSGID = true; - RemoveIPC = true; - SystemCallFilter = [ "@system-service" ]; - SystemCallErrorNumber = "EPERM"; - }; - }; -} diff --git a/flake.nix b/flake.nix index 2d782e9..a2360c9 100644 --- a/flake.nix +++ b/flake.nix @@ -116,6 +116,7 @@ { modules = [ ./hardware-configuration.nix + ./modules ./config inputs.nix-index-database.nixosModules.default inputs.nix-gaming.nixosModules.platformOptimizations diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..84ce5ef --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./keylightd.nix + ]; +} diff --git a/modules/keylightd.nix b/modules/keylightd.nix new file mode 100644 index 0000000..52ebdd2 --- /dev/null +++ b/modules/keylightd.nix @@ -0,0 +1,69 @@ +{ + lib, + pkgs', + config, + ... +}: +let + cfg = config.services.keylightd; +in +{ + options.services.keylightd = { + enable = lib.mkEnableOption "keylightd"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs'.keylightd; + defaultText = "pkgs.keylightd"; + description = "keylightd package to use"; + example = lib.literalExpression "pkgs.keylightd"; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ pkgs'.keylightd ]; + + users = { + users.keylightd = { + isSystemUser = true; + group = "keylightd"; + home = "/var/lib/keylightd"; + }; + groups.keylightd = { }; + }; + + systemd.services.keylightd = { + description = "Elgato Key Light daemon"; + wantedBy = [ "multi-user.target" ]; + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + serviceConfig = { + ExecStart = lib.getExe cfg.package; + Restart = "on-failure"; + RestartSec = "10s"; + User = "keylightd"; + Group = "keylightd"; + StateDirectory = "keylightd"; + RuntimeDirectory = "keylightd"; + RuntimeDirectoryMode = "0775"; + UMask = "0002"; + Environment = [ + "XDG_CONFIG_HOME=/var/lib/keylightd" + "XDG_RUNTIME_DIR=/run/keylightd" + ]; + NoNewPrivileges = true; + PrivateTmp = true; + ProtectSystem = "strict"; + ProtectHome = true; + ProtectKernelTunables = true; + ProtectKernelModules = true; + ProtectControlGroups = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + RemoveIPC = true; + SystemCallFilter = [ "@system-service" ]; + SystemCallErrorNumber = "EPERM"; + }; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 652ba47..7681003 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -3,8 +3,7 @@ let overrides = import ../overrides { inherit pkgs inputs; }; callPackage = pkgs.lib.callPackageWith (pkgs // packages); packages = { - # keylightd = callPackage ./keylightd.nix { }; - keylightd = callPackage ./keylightd-bin.nix { }; + keylightd = callPackage ./keylightd.nix { }; # reasonix-desktop = callPackage ./reasonix-desktop.nix { }; }; diff --git a/pkgs/keylightd-bin.nix b/pkgs/keylightd-bin.nix deleted file mode 100644 index bc476ce..0000000 --- a/pkgs/keylightd-bin.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ - lib, - stdenvNoCC, - fetchurl, -}: -let - version = "0.1.8"; - - archives = { - x86_64-linux = { - arch = "amd64"; - hash = "sha256-xZ5gNuH5S122sAu4oDGOA61ClSXNjXdftwc1sLXAInA="; - }; - aarch64-linux = { - arch = "arm64"; - hash = "sha256-2Wr+GD1lp6BYcJbxczSJxrF/QWAeFFUGUTh0qp3hlCc="; - }; - }; - - archive = archives.${stdenvNoCC.hostPlatform.system}; -in -stdenvNoCC.mkDerivation (finalAttrs: { - inherit version; - pname = "keylightd"; - - src = fetchurl { - url = "https://github.com/jmylchreest/keylightd/releases/download/v${finalAttrs.version}/keylightd_${finalAttrs.version}_linux_${archive.arch}.tar.gz"; - inherit (archive) hash; - }; - - sourceRoot = "."; - - installPhase = '' - runHook preInstall - - install -Dm755 keylightd "$out/bin/keylightd" - install -Dm755 keylightctl "$out/bin/keylightctl" - - runHook postInstall - ''; - - meta = { - description = "Daemon and CLI for Elgato Key Lights"; - homepage = "https://github.com/jmylchreest/keylightd"; - license = lib.licenses.mit; - mainProgram = "keylightctl"; - platforms = lib.attrNames archives; - sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; - }; -}) diff --git a/pkgs/keylightd.nix b/pkgs/keylightd.nix index 6b140c0..810094c 100644 --- a/pkgs/keylightd.nix +++ b/pkgs/keylightd.nix @@ -8,68 +8,60 @@ webkitgtk_4_1, pkg-config, }: -let +buildGoModule (finalAttrs: { pname = "keylightd"; - version = "0.1.8"; - src = fetchFromGitHub { owner = "jmylchreest"; repo = "keylightd"; - rev = "v${version}"; - hash = "sha256-3DmsYm8ZB2nILBWtgv4vPTw9clKyaSrVlAypwUlAajw="; + rev = "v${finalAttrs.version}"; + hash = "sha256-pa8zKmqaal3Ys8LoVSviKeqsi5x50GjSB8PLJkqMpE4="; }; - npmDeps = fetchNpmDeps { - src = "${src}/contrib/keylightd-tray/frontend"; - hash = "sha256-Q4MRYuxy3qV2GUrfdw7SzbuflaV7A4Fr7w1cQV5LXMY="; - }; - npmRoot = "contrib/keylightd-tray/frontend"; -in -buildGoModule (finalAttrs: { - inherit - pname - version - src - ; + version = "0.1.9"; - vendorHash = "sha256-Odx74tTuufpcvssybAXqYoU5ubem4IvI3lOw5nT2aEo="; + vendorHash = "sha256-8+9kyyvJ9jJciDx+rPmtfSsGmPhBY6qI/eGDpeJ/ES0="; env = { - inherit npmDeps npmRoot; + CGO_ENABLED = 0; + + npmDeps = fetchNpmDeps { + src = "${finalAttrs.src}/contrib/keylightd-tray/frontend"; + hash = "sha256-Q4MRYuxy3qV2GUrfdw7SzbuflaV7A4Fr7w1cQV5LXMY="; + }; + + npmRoot = "contrib/keylightd-tray/frontend"; }; nativeBuildInputs = [ - wails - pkg-config - npmHooks.npmConfigHook + # wails + # pkg-config + # npmHooks.npmConfigHook ]; - buildInputs = [ webkitgtk_4_1 ]; - - buildPhase = '' - runHook preBuild - - make build + # buildInputs = [ webkitgtk_4_1 ]; - runHook postBuild - ''; + ldflags = [ + "-s" + "-w" + "-X main.version=${finalAttrs.version}" + "-X main.commit=${finalAttrs.src.rev}" + "-X main.buildDate=1970-01-01T00:00:00Z" + ]; - # installPhase = '' - # runHook preInstall - # install -Dm755 keylightd "$out/bin/keylightd" - # install -Dm755 keylightctl "$out/bin/keylightctl" - # runHook postInstall - # ''; + subPackages = [ + "cmd/keylightd" + "cmd/keylightctl" + ]; passthru = { - inherit npmDeps; + inherit (finalAttrs) npmDeps; }; meta = { description = "Daemon and CLI for Elgato Key Lights"; homepage = "https://github.com/jmylchreest/keylightd"; license = lib.licenses.mit; - mainProgram = "keylightctl"; + mainProgram = "keylightd"; }; })