From 00330b4102f2f89bea6782abf9669341bf11dcf3 Mon Sep 17 00:00:00 2001 From: Quentin Boyer Date: Sat, 27 Jul 2024 21:56:35 +0200 Subject: [PATCH] hostconfig/minus: Add the CEC environnement --- hostconfig/minus/nixos.nix | 46 +++++++++++++++++++++++++++++++----- pkgs/default.nix | 1 + pkgs/pulse8-cec.nix | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 pkgs/pulse8-cec.nix diff --git a/hostconfig/minus/nixos.nix b/hostconfig/minus/nixos.nix index f9ec84c..4896a33 100644 --- a/hostconfig/minus/nixos.nix +++ b/hostconfig/minus/nixos.nix @@ -1,5 +1,13 @@ -{ config, pkgs, ... }: { + config, + pkgs, + lib, + ... +}: +{ + boot.extraModulePackages = [ + (pkgs.pulse8-cec.override { inherit (config.boot.kernelPackages) kernel; }) + ]; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -28,7 +36,6 @@ xkbVariant = "dvp"; }; - sound.enable = true; hardware.pulseaudio.enable = false; security.rtkit.enable = true; services.pipewire = { @@ -53,10 +60,37 @@ enable = true; }; - environment.systemPackages = [ - pkgs.moonlight-qt - pkgs.jstest-gtk - (pkgs.kodi.withPackages ( + services.udev.extraRules = '' + SUBSYSTEM=="tty" ACTION=="add" \ + ATTRS{manufacturer}=="Pulse-Eight" ATTRS{product}=="CEC Adapter" \ + TAG+="systemd" ENV{SYSTEMD_WANTS}="pulse8-cec-attach@$devnode.service" + ''; + + systemd.services."pulse8-cec-attach@" = { + description = "Configure USB Pulse-Eight serial device at %I"; + + unitConfig = { + ConditionPathExists = "%I"; + }; + + serviceConfig = + let + systemdLinuxConsoleTools = pkgs.linuxConsoleTools.overrideAttrs (oa: { + makeFlags = oa.makeFlags ++ [ "SYSTEMD_SUPPORT=1" ]; + buildInputs = oa.buildInputs ++ (with pkgs; [ systemdLibs ]); + }); + in + { + Type = "forking"; + ExecStart = "${lib.getExe' systemdLinuxConsoleTools "inputattach"} --daemon --pulse8-cec %I"; + }; + }; + + environment.systemPackages = with pkgs; [ + moonlight-qt + jstest-gtk + libcec + (kodi.withPackages ( p: with p; [ jellyfin youtube diff --git a/pkgs/default.nix b/pkgs/default.nix index 90c713c..6bc7416 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -26,6 +26,7 @@ flex-launcher = pkgs.callPackage ./flex-launcher.nix { }; mesonlsp = pkgs.callPackage ./mesonlsp { }; push-to-talk = pkgs.callPackage ./push-to-talk.nix { }; + pulse8-cec = pkgs.callPackage ./pulse8-cec.nix { }; }; }; } diff --git a/pkgs/pulse8-cec.nix b/pkgs/pulse8-cec.nix new file mode 100644 index 0000000..58715ad --- /dev/null +++ b/pkgs/pulse8-cec.nix @@ -0,0 +1,48 @@ +{ + stdenv, + lib, + linuxPackages, + kernel ? linuxPackages.kernel, +}: +stdenv.mkDerivation { + pname = "pulse8-cec-module"; + inherit (kernel) + src + version + postPatch + nativeBuildInputs + ; + + kernel_dev = kernel.dev; + kernelVersion = kernel.modDirVersion; + + modulePath = "drivers/media/cec/usb/pulse8"; + + buildPhase = '' + BUILT_KERNEL=$kernel_dev/lib/modules/$kernelVersion/build + + cp $BUILT_KERNEL/Module.symvers . + cat $BUILT_KERNEL/.config >.config + cp $kernel_dev/vmlinux . + + ./scripts/config --enable CONFIG_MEDIA_CEC_SUPPORT + ./scripts/config --module CONFIG_USB_PULSE8_CEC + + make "-j$NIX_BUILD_CORES" modules_prepare + make "-j$NIX_BUILD_CORES" M=$modulePath modules + ''; + + installPhase = '' + make \ + INSTALL_MOD_PATH="$out" \ + XZ="xz -T$NIX_BUILD_CORES" \ + M="$modulePath" \ + modules_install + ''; + + meta = { + description = "Pulse 8 CEC kernel module"; + license = lib.licenses.gpl2; + }; + +}