From 273674d5ae1d3f8dd6a9dc849fc4b3be603c5274 Mon Sep 17 00:00:00 2001 From: Marin Date: Mon, 20 Nov 2023 17:36:05 -0500 Subject: [PATCH 1/2] Add flake.nix Build with: $ nix build --- flake.lock | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 21 ++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0d21a56 --- /dev/null +++ b/flake.lock @@ -0,0 +1,57 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1736344531, + "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=", + "path": "/nix/store/v0g0bxsd5gw6k0jz2855f8h7l1218925-source", + "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a24aa9d --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + outputs = { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.default = pkgs.stdenv.mkDerivation { + name = "asdcontrol"; + src = pkgs.lib.cleanSource ./.; + installPhase = '' + mkdir -p $out/bin + mv asdcontrol $out/bin + ''; + }; + }); +} From b1eae1492ea8a1b157b29f59b935cf851d9f7ce3 Mon Sep 17 00:00:00 2001 From: Marin Date: Tue, 11 Feb 2025 15:15:16 -0500 Subject: [PATCH 2/2] [flake] Add nixos module The module automatically installs asdcontrol and the corresponding udev rules. Usage: 1. Add the input in flake.nix inputs.asdcontrol.url = "github:supermarin/asdcontrol"; 2. Import the module in machine's configuration imports = [ inputs.asdcontrol.modules.asdcontrol ]; 3. Enable asdcontrol in configuration.nix: programs.asdcontrol.enable = true; --- flake.nix | 64 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index a24aa9d..5dcaf10 100644 --- a/flake.nix +++ b/flake.nix @@ -1,21 +1,49 @@ { - outputs = { - nixpkgs, - flake-utils, - ... - }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in + outputs = { - packages.default = pkgs.stdenv.mkDerivation { - name = "asdcontrol"; - src = pkgs.lib.cleanSource ./.; - installPhase = '' - mkdir -p $out/bin - mv asdcontrol $out/bin - ''; - }; - }); + self, + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.default = pkgs.stdenv.mkDerivation { + name = "asdcontrol"; + src = pkgs.lib.cleanSource ./.; + installPhase = '' + mkdir -p $out/bin + mv asdcontrol $out/bin + ''; + }; + } + ) + // { + modules.asdcontrol = + { + config, + lib, + pkgs, + ... + }: + let + cfg = config.programs.asdcontrol; + in + { + options.programs.asdcontrol = { + enable = lib.mkEnableOption "Enables asdcontrol (brightness control for Apple Monitors)"; + }; + config = lib.mkIf cfg.enable { + environment.defaultPackages = [ self.packages.${pkgs.system}.default ]; + services.udev.extraRules = '' + KERNEL=="hiddev*", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="1114", GROUP="users", OWNER="root", MODE="0660" + KERNEL=="hiddev*", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="9243", GROUP="users", OWNER="root", MODE="0660" + ''; # Studio Display (1114), Pro Display XDR (9243) + }; + }; + }; }