From 7e3a3f3170676043024055615da19b58614c4a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20W=C3=A5gberg?= Date: Fri, 12 Apr 2024 23:01:44 +0200 Subject: [PATCH] apple/t2: add tiny-dfr service --- apple/t2/default.nix | 21 +++++++++++++++- apple/t2/pkgs/tiny-dfr.nix | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 apple/t2/pkgs/tiny-dfr.nix diff --git a/apple/t2/default.nix b/apple/t2/default.nix index cbdba9d..abe9cac 100644 --- a/apple/t2/default.nix +++ b/apple/t2/default.nix @@ -24,6 +24,8 @@ let pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/"; + tiny-dfrPackage = pkgs.callPackage ./pkgs/tiny-dfr.nix { }; + apple-set-os-loader-installer = pkgs.stdenv.mkDerivation { name = "apple-set-os-loader-installer-1.0"; src = pkgs.fetchFromGitHub { @@ -60,9 +62,10 @@ in boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { }); boot.initrd.kernelModules = [ "apple-bce" ]; + services.udev.packages = [ audioFilesUdevRules tiny-dfrPackage ]; + # For audio boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; - services.udev.packages = [ audioFilesUdevRules ]; hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; @@ -71,6 +74,22 @@ in pipewire = pipewirePackage; }; + # For tiny-dfr + systemd.services.tiny-dfr = { + enable = true; + description = "Tiny Apple silicon touch bar daemon"; + after = [ "systemd-user-sessions.service" "getty@tty1.service" "plymouth-quit.service" "systemd-logind.service" ]; + bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ]; + startLimitIntervalSec = 30; + startLimitBurst = 2; + script = "${tiny-dfrPackage}/bin/tiny-dfr"; + restartTriggers = [ tiny-dfrPackage ]; + }; + + environment.etc."tiny-dfr/config.toml" = { + source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml"; + }; + # Make sure post-resume.service exists powerManagement.enable = true; diff --git a/apple/t2/pkgs/tiny-dfr.nix b/apple/t2/pkgs/tiny-dfr.nix new file mode 100644 index 0000000..ce4be0f --- /dev/null +++ b/apple/t2/pkgs/tiny-dfr.nix @@ -0,0 +1,51 @@ +{ pkgs, fetchFromGitHub, rustPlatform, ... }: + +let + repo = fetchFromGitHub { + owner = "kekrby"; + repo = "tiny-dfr"; + rev = "8a5d413cb1dbe2a25b77a9e7f3cb5b9c88ef3ffb"; + hash = "sha256-l4D7aePz/CYpkRorrvsgIYrvSzoZl59OGcFGJqqJftk="; + }; + +in +rustPlatform.buildRustPackage rec { + pname = "tiny-dfr"; + version = repo.rev; + + src = repo; + + cargoLock.lockFile = "${src}/Cargo.lock"; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + + buildInputs = with pkgs; [ + udev + glib + pango + cairo + gdk-pixbuf + libxml2 + libinput + ]; + + postPatch = '' + substituteInPlace src/main.rs --replace "/usr/share/tiny-dfr/" "$out/share/tiny-dfr/" + ''; + + postInstall = '' + mkdir -p $out/etc $out/share + + cp -r etc/udev $out/etc/ + cp -r share/tiny-dfr $out/share/ + ''; + + meta = with pkgs.lib; { + description = "The most basic dynamic function row daemon possible"; + homepage = "https://github.com/kekrby/tiny-dfr"; + license = with licenses; [ asl20 bsd3 cc0 isc lgpl21Plus mit mpl20 unicode-dfs-2016 asl20 asl20-llvm mit unlicense ]; + maintainers = []; + }; +}