diff --git a/configuration.nix b/configuration.nix index c734354..7b50296 100644 --- a/configuration.nix +++ b/configuration.nix @@ -8,7 +8,6 @@ imports = [ # Include the results of the hardware scan... ./hardware-configuration.nix - ./hwaccel.nix ./network.nix # ...and additional configurations... @@ -26,12 +25,11 @@ ./docker.nix ./chrony.nix ./docker-device-mapper.nix - ./seaweedfs-mount.nix ]; # Use the systemd-boot EFI boot loader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; + # boot.loader.systemd-boot.enable = true; + # boot.loader.efi.canTouchEfiVariables = true; # Enable IP forwarding for NAT (used in wireguard.nix) and load specific modules. boot.kernel.sysctl = { @@ -111,7 +109,6 @@ zoxide yazi fzf - intel-gpu-tools ]; # Open ports in the firewall. diff --git a/open_ccu.nix b/open_ccu.nix new file mode 100644 index 0000000..6e521a5 --- /dev/null +++ b/open_ccu.nix @@ -0,0 +1,32 @@ +{ config, pkgs, ... }: + +{ + virtualisation.docker.enable = true; + + virtualisation.oci-containers.containers.openccu = { + # Official RaspberryMatic image (contains the necessary CCU logic) + image = "ghcr.io/openccu/openccu:latest"; + + autoStart = true; + + # These options are critical for: + # 1. Swarm Networking (connecting to 'public') + # 2. Hardware Access (GPIO/USB) + extraOptions = [ + "--privileged" # Required for internal systemd & hardware + "--network=public" # Connects to your Swarm Overlay network + "--device=/dev/raw-uart:/dev/raw-uart" + "--device=/dev/eq3loop:/dev/eq3loop" + "--device=/dev/ttyUSB0:/dev/ttyUSB0" # Pass the underlying USB too, just in case + ]; + + # Map the web interface locally, or rely on Swarm IP + ports = [ "80:80" ]; + + volumes = [ + "/mnt/service/data/openccu:/usr/local" + "/sys/fs/cgroup:/sys/fs/cgroup:ro" # Required for RaspberryMatic + ]; + }; +} + diff --git a/pi.nix b/pi.nix new file mode 100644 index 0000000..a705fe9 --- /dev/null +++ b/pi.nix @@ -0,0 +1,36 @@ +{ config, pkgs, lib, ... }: +{ + # Boot Options + boot.loader.grub.enable = lib.mkForce false; + boot.loader.generic-extlinux-compatible.enable = lib.mkForce true; + + # tty Console + boot.kernelParams = [ + "console=ttyS1,115200n8" + ]; + + # Bluetooth + hardware.bluetooth = { + enable = true; + powerOnBoot = true; + settings = { + General = { + Experimental = true; + FastConnectable = true; + }; + Policy = { + AutoEnable = true; + }; + }; + }; + + #systemd.services.btattach = { + # before = [ "bluetooth.service" ]; + # after = [ "dev-ttyAMA0.device" ]; + # wantedBy = [ "multi-user.target" ]; + # serviceConfig = { + # ExecStart = "${pkgs.bluez}/bin/btattach -B /dev/ttyAMA0 -P bcm -S 3000000"; + # }; + #}; + +} diff --git a/pivccu.nix b/pivccu.nix new file mode 100644 index 0000000..75c72d7 --- /dev/null +++ b/pivccu.nix @@ -0,0 +1,69 @@ +{ config, lib, pkgs, ... }: + +let + pivccu-modules = config.boot.kernelPackages.callPackage ({ stdenv, fetchFromGitHub, kernel }: stdenv.mkDerivation rec { + pname = "pivccu-modules"; + version = "master"; + + src = fetchFromGitHub { + owner = "alexreinert"; + repo = "piVCCU"; + rev = "master"; + # Ensure this matches the hash you got earlier + sha256 = "sha256-cXvrLcASU/2nsfJBf+cVtC4JnAq4G5JFzcFgj5ztThc="; + }; + + # Set the source root to the kernel subdirectory + sourceRoot = "${src.name}/kernel"; + + hardeningDisable = [ "pic" "format" ]; + nativeBuildInputs = kernel.moduleBuildDependencies; + + # 1. FORCE delete the upstream Makefile (which causes the build error) + # 2. Create a clean Makefile that only builds the modules we need + postPatch = '' + rm -f Makefile + echo "obj-m += eq3_char_loop.o plat_eq3ccu2.o" > Makefile + ''; + + # 3. Explicitly point to the kernel build directory + makeFlags = [ + "KERNEL_DIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "INSTALL_MOD_PATH=$(out)" + "M=$(pwd)" + "modules" + ]; + + # 4. Use the kernel build system to compile the modules + buildPhase = '' + make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$(pwd) modules + ''; + + installPhase = '' + make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$(pwd) INSTALL_MOD_PATH=$out modules_install + ''; + }) {}; + +in +{ + boot.extraModulePackages = [ pivccu-modules ]; + + # Load the modules required for the USB stick + boot.kernelModules = [ "cp210x" "eq3_char_loop" "plat_eq3ccu2" ]; + + # Udev rules for HmIP-RFUSB + services.udev.extraRules = '' + # 1. FORCE BINDING: Tell cp210x to handle the HmIP-RFUSB (1b1f:c020) + # We use 'sh -c echo' because 'new_id' is a virtual file that tells the driver to accept new IDs. + ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1b1f", ATTR{idProduct}=="c020", \ + RUN+="${pkgs.kmod}/bin/modprobe cp210x", \ + RUN+="${pkgs.bash}/bin/sh -c 'echo 1b1f c020 > /sys/bus/usb-serial/drivers/cp210x/new_id'" + + # 2. CREATE SYMLINK: Once the driver binds, a ttyUSBx device appears. + # We symlink it to /dev/raw-uart and set permissions. + SUBSYSTEM=="tty", ATTRS{idVendor}=="1b1f", ATTRS{idProduct}=="c020", SYMLINK+="raw-uart", OWNER="root", GROUP="root", MODE="0666" + + # 3. USB PERMISSIONS: Ensure the raw USB device is also accessible + SUBSYSTEM=="usb", ATTRS{idVendor}=="1b1f", ATTRS{idProduct}=="c020", MODE="0666" + ''; +}