From 07abb75bd618089f09732b74671c0fc46ac26356 Mon Sep 17 00:00:00 2001 From: Nydragon Date: Tue, 10 Dec 2024 15:22:46 +0100 Subject: [PATCH] feat: add udev rule to properly initialize apple superdrive --- modules/default.nix | 1 + modules/services/default.nix | 3 +++ modules/services/udev.nix | 22 ++++++++++++++++++++++ parts/lib/functions.nix | 3 +++ 4 files changed, 29 insertions(+) create mode 100644 modules/services/default.nix create mode 100644 modules/services/udev.nix diff --git a/modules/default.nix b/modules/default.nix index 54cd6fa..d8f5059 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -6,6 +6,7 @@ ./fonts.nix ./portals.nix ./env.nix + ./services ./system/printing.nix ./system/audio.nix diff --git a/modules/services/default.nix b/modules/services/default.nix new file mode 100644 index 0000000..da81259 --- /dev/null +++ b/modules/services/default.nix @@ -0,0 +1,3 @@ +{ + imports = [ ./udev.nix ]; +} diff --git a/modules/services/udev.nix b/modules/services/udev.nix new file mode 100644 index 0000000..662685d --- /dev/null +++ b/modules/services/udev.nix @@ -0,0 +1,22 @@ +{ + pkgs, + lib, + config, + ... +}: +let + inherit (lib.my) getExe' mkStringIf; + isDesktop = config.modules.system.roles.desktop.enable; +in +{ + services.udev.extraRules = '' + ${mkStringIf isDesktop '' + # Rule for the MacBook Air SuperDrive + ACTION=="add", \ + ATTRS{product}=="MacBook Air SuperDrive", \ + ATTRS{idProduct}=="1500", ATTRS{idVendor}=="05ac", \ + DRIVERS=="usb", \ + RUN+="${getExe' pkgs.sg3_utils "sg_raw"} %r/sr%n EA 00 00 00 00 00 01" + ''} + ''; +} diff --git a/parts/lib/functions.nix b/parts/lib/functions.nix index 98c540c..7145846 100644 --- a/parts/lib/functions.nix +++ b/parts/lib/functions.nix @@ -87,6 +87,9 @@ in in if builtins.pathExists abs then abs else throw "${abs} does not exist."; + # Returns the string if the given predicate is true, otherwise returns an empty string is returned + mkStringIf = predicate: string: if predicate then string else ""; + mkVHost = name: port: ssl: { inherit name; value = {