ctucx.git: nixfiles

ctucx' nixfiles

commit 0e37d0837bdb091ee3da7c883c2b2830f687db63
parent 355d31ce102d15a7e6673b5a1a11ca821c6853e7
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sat, 7 May 2022 14:01:14 +0200

machines/blechbuechse/keyboard: lauchagents with nix-darwin now!
1 file changed, 28 insertions(+), 48 deletions(-)
M
machines/blechbuechse/keyboard.nix
|
76
++++++++++++++++++++++++++++------------------------------------------------
diff --git a/machines/blechbuechse/keyboard.nix b/machines/blechbuechse/keyboard.nix
@@ -40,57 +40,37 @@ let
     in lib.foldl (a: v: a + v) 0 (lib.imap0 (k: v: hexToInt."${v}" * (pow 16 (charsLen - k - 1))) chars);
 
   commandList  = lib.forEach keyMappings (entry: ''hidutil property --matching '{"ProductID":0x${entry.ProductID}}' --set '{"UserKeyMapping":${builtins.toJSON entry.UserKeyMapping}}' > /dev/null'');
-  launchAgents = lib.forEach keyMappings (entry: {
-    name         = "org.nixos.activateUserKeyMapping-${entry.VendorID}:${entry.ProductID}.plist";
-    value.enable = if (entry.VendorID != "5ac" && entry.ProductID != "281") then true else false;
-    value.text   = ''
-      <?xml version="1.0" encoding="UTF-8"?>
-      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-      <plist version="1.0">
-      <dict>
-        <key>StandardErrorPath</key>
-        <string>/tmp/activateUserKeyMapping.stderr</string>
-        <key>StandardOutPath</key>
-        <string>/tmp/activateUserKeyMapping.stdout</string>
-
-        <key>Label</key>
-        <string>org.nixos.activateUserKeyMapping-${entry.VendorID}:${entry.ProductID}</string>
-
-        <key>ProgramArguments</key>
-        <array>
-          <string>${XPCEventStreamHandler}/bin/xpc_set_event_stream_handler</string>
-          <string>${pkgs.writeScript "hidutil" ''
-            #!/usr/bin/env bash
-            osascript -e 'display notification "Load UserKeyMapping for ${entry.VendorID}:${entry.ProductID}" with title "hidutil"'
-            hidutil property --matching '{"ProductID":0x${entry.ProductID}}' --set '{"UserKeyMapping":${builtins.toJSON entry.UserKeyMapping}}'  > /dev/null
-          ''}</string>
-        </array>
-
-        <key>LaunchEvents</key>
-        <dict>
-          <key>com.apple.iokit.matching</key>
-          <dict>
-            <key>com.apple.device-attach</key>
-            <dict>
-              <key>idVendor</key>
-              <integer>${builtins.toString (hexToDec entry.VendorID)}</integer>
-              <key>idProduct</key>
-              <integer>${builtins.toString (hexToDec entry.ProductID)}</integer>
-              <key>IOProviderClass</key>
-              <string>IOUSBDevice</string>
-              <key>IOMatchLaunchStream</key>
-              <true/>
-            </dict>
-          </dict>
-        </dict>
-      </dict>
-      </plist>
-    '';
-  });
 
 in {
 
-  environment.userLaunchAgents           = builtins.listToAttrs launchAgents;
+  launchd.user.agents = builtins.listToAttrs (lib.forEach keyMappings (entry: {
+    name  = "activateUserKeyMapping-${entry.VendorID}:${entry.ProductID}";
+    value.serviceConfig = {
+      Disabled          = if (entry.VendorID != "5ac" && entry.ProductID != "281") then false else true;
+      Label             = "org.nixos.activateUserKeyMapping-${entry.VendorID}:${entry.ProductID}";
+#      StandardErrorPath = "/tmp/activateUserKeyMapping.stderr";
+#      StandardOutPath   = "/tmp/activateUserKeyMapping.stdout";
+      ProgramArguments  = [
+        "${XPCEventStreamHandler}/bin/xpc_set_event_stream_handler"
+        "${pkgs.writeScript "hidutil" ''
+          #!/usr/bin/env bash
+          osascript -e 'display notification "Load UserKeyMapping for ${entry.VendorID}:${entry.ProductID}" with title "hidutil"'
+          hidutil property --matching '{"ProductID":0x${entry.ProductID}}' --set '{"UserKeyMapping":${builtins.toJSON entry.UserKeyMapping}}'  > /dev/null
+        ''}"
+      ];
+      LaunchEvents = {
+        "com.apple.iokit.matching" = {
+          "com.apple.device-attach" = {
+            IOMatchLaunchStream = true;
+            IOProviderClass     = "IOUSBDevice";
+            idVendor            = hexToDec entry.VendorID;
+            idProduct           = hexToDec entry.ProductID;
+          };
+        };
+      };
+    };
+  }));
+
   system.activationScripts.keyboard.text = ''
     # Configuring keyboard
     echo "configuring keyboard..." >&2