From 5903eb650a3edd2c0310bcfebeb665ec21b1b7b7 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Mon, 5 Aug 2024 17:54:43 +0100 Subject: [PATCH 1/7] Update rpi base --- flake.lock | 193 ++++++++++++++++++++++++ flake.nix | 5 +- hosts/common.nix | 2 + hosts/skycam/default.nix | 46 +----- hosts/skycam/hardware-configuration.nix | 18 --- modules/options.nix | 2 +- overlays/0001-Always-installed.patch | 32 ++++ overlays/libcamera.nix | 48 ++++++ 8 files changed, 281 insertions(+), 65 deletions(-) create mode 100644 overlays/0001-Always-installed.patch create mode 100644 overlays/libcamera.nix diff --git a/flake.lock b/flake.lock index dda589b..0c70b65 100644 --- a/flake.lock +++ b/flake.lock @@ -365,6 +365,40 @@ "type": "github" } }, + "libcamera-src": { + "flake": false, + "locked": { + "lastModified": 1718617480, + "narHash": "sha256-qqEMJzMotybf1nJp1dsz3zc910Qj0TmqCm1CwuSb1VY=", + "owner": "raspberrypi", + "repo": "libcamera", + "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "repo": "libcamera", + "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", + "type": "github" + } + }, + "libpisp-src": { + "flake": false, + "locked": { + "lastModified": 1718613892, + "narHash": "sha256-V/d4RrXoq8HNc8r/Kr1gH3E7YTZzfIdgbaJtq/Xi7uQ=", + "owner": "raspberrypi", + "repo": "libpisp", + "rev": "b567f04556801ca350331ed21a1ae3eef4675c23", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "v1.0.6", + "repo": "libpisp", + "type": "github" + } + }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -503,6 +537,22 @@ "type": "indirect" } }, + "nixpkgs_4": { + "locked": { + "lastModified": 1722651103, + "narHash": "sha256-IRiJA0NVAoyaZeKZluwfb2DoTpBAj+FLI0KfybBeDU0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a633d89c6dc9a2a8aae11813a62d7c58b2c0cc51", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixvim": { "inputs": { "devshell": "devshell", @@ -554,6 +604,33 @@ "type": "github" } }, + "raspberry-pi-nix": { + "inputs": { + "libcamera-src": "libcamera-src", + "libpisp-src": "libpisp-src", + "nixpkgs": "nixpkgs_4", + "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", + "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", + "rpi-firmware-src": "rpi-firmware-src", + "rpi-linux-6_10_0-rc5-src": "rpi-linux-6_10_0-rc5-src", + "rpi-linux-6_6_31-src": "rpi-linux-6_6_31-src", + "rpicam-apps-src": "rpicam-apps-src", + "u-boot-src": "u-boot-src" + }, + "locked": { + "lastModified": 1722525809, + "narHash": "sha256-LTCbMSKbSHvKubfXolss39UeTKDIoP9wWTyXV/tDPHU=", + "owner": "nix-community", + "repo": "raspberry-pi-nix", + "rev": "35bb455fdeb495043a94433f67e05fa88980cdad", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "raspberry-pi-nix", + "type": "github" + } + }, "root": { "inputs": { "agenix": "agenix", @@ -569,10 +646,113 @@ "nixpkgs-unstable": "nixpkgs-unstable", "nixvim": "nixvim", "plasma-manager": "plasma-manager", + "raspberry-pi-nix": "raspberry-pi-nix", "secrets": "secrets", "thunderbird-gnome-theme": "thunderbird-gnome-theme" } }, + "rpi-bluez-firmware-src": { + "flake": false, + "locked": { + "lastModified": 1708969706, + "narHash": "sha256-KakKnOBeWxh0exu44beZ7cbr5ni4RA9vkWYb9sGMb8Q=", + "owner": "RPi-Distro", + "repo": "bluez-firmware", + "rev": "78d6a07730e2d20c035899521ab67726dc028e1c", + "type": "github" + }, + "original": { + "owner": "RPi-Distro", + "ref": "bookworm", + "repo": "bluez-firmware", + "type": "github" + } + }, + "rpi-firmware-nonfree-src": { + "flake": false, + "locked": { + "lastModified": 1708967191, + "narHash": "sha256-BGq0+cr+xBRwQM/LqiQuRWuZpQsKM5jfcrNCqWMuVzM=", + "owner": "RPi-Distro", + "repo": "firmware-nonfree", + "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", + "type": "github" + }, + "original": { + "owner": "RPi-Distro", + "ref": "bookworm", + "repo": "firmware-nonfree", + "type": "github" + } + }, + "rpi-firmware-src": { + "flake": false, + "locked": { + "lastModified": 1716978780, + "narHash": "sha256-KsCo7ZG6vKstxRyFljZtbQvnDSqiAPdUza32xTY/tlA=", + "owner": "raspberrypi", + "repo": "firmware", + "rev": "3590de0c181d433af368a95f15bc480bdaff8b47", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "1.20240529", + "repo": "firmware", + "type": "github" + } + }, + "rpi-linux-6_10_0-rc5-src": { + "flake": false, + "locked": { + "lastModified": 1719265450, + "narHash": "sha256-xd/Pz/uZFYW9hJIFKryWDE9Aks6f2EIvEDCmfk0C70c=", + "owner": "raspberrypi", + "repo": "linux", + "rev": "f61d3aca8045e70d64b55f7b98f083738f639ad2", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "rpi-6.10.y", + "repo": "linux", + "type": "github" + } + }, + "rpi-linux-6_6_31-src": { + "flake": false, + "locked": { + "lastModified": 1716545726, + "narHash": "sha256-UWUTeCpEN7dlFSQjog6S3HyEWCCnaqiUqV5KxCjYink=", + "owner": "raspberrypi", + "repo": "linux", + "rev": "c1432b4bae5b6582f4d32ba381459f33c34d1424", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "stable_20240529", + "repo": "linux", + "type": "github" + } + }, + "rpicam-apps-src": { + "flake": false, + "locked": { + "lastModified": 1717081637, + "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", + "owner": "raspberrypi", + "repo": "rpicam-apps", + "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "v1.5.0", + "repo": "rpicam-apps", + "type": "github" + } + }, "secrets": { "flake": false, "locked": { @@ -671,6 +851,19 @@ "type": "github" } }, + "u-boot-src": { + "flake": false, + "locked": { + "lastModified": 1712055538, + "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", + "type": "tarball", + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + }, + "original": { + "type": "tarball", + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + } + }, "utils": { "inputs": { "systems": "systems_2" diff --git a/flake.nix b/flake.nix index fe7a2da..e182efb 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,9 @@ inputs.nixpkgs.follows = "nixpkgs"; inputs.home-manager.follows = "home-manager"; }; + raspberry-pi-nix = { + url = "github:nix-community/raspberry-pi-nix"; + }; secrets = { url = "git+ssh://git@git.vimium.com/jordan/nix-secrets.git"; flake = false; @@ -114,7 +117,7 @@ mail = mkNixosSystem { system = "x86_64-linux"; name = "mail"; }; odyssey = mkNixosSystem { system = "x86_64-linux"; name = "odyssey"; }; pi = mkNixosSystem { system = "aarch64-linux"; name = "pi"; extraModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ]; }; - skycam = mkNixosSystem { system = "aarch64-linux"; name = "skycam"; extraModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ]; }; + skycam = mkNixosSystem { system = "aarch64-linux"; name = "skycam"; extraModules = [ inputs.raspberry-pi-nix.nixosModules.raspberry-pi ]; }; vps1 = mkNixosSystem { system = "x86_64-linux"; name = "vps1"; }; }; diff --git a/hosts/common.nix b/hosts/common.nix index 6fe3fe9..100cc55 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -52,10 +52,12 @@ auto-optimise-store = true; substituters = [ "http://odyssey.mesh.vimium.net" + "https://nix-community.cachix.org" "https://cache.nixos.org" ]; trusted-public-keys = [ "odyssey.mesh.vimium.net:ZhQhjscPWjoN4rlZwoMELznEiBnZ9O26iyGA27ibilQ=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ]; }; gc = { diff --git a/hosts/skycam/default.nix b/hosts/skycam/default.nix index 31c542b..bea0112 100644 --- a/hosts/skycam/default.nix +++ b/hosts/skycam/default.nix @@ -6,49 +6,7 @@ ../server.nix ]; - hardware = { - raspberry-pi."4" = { - apply-overlays-dtmerge.enable = true; - audio.enable = false; - xhci.enable = false; - }; - deviceTree = { - enable = true; - filter = "*rpi-4-*.dtb"; - # From https://github.com/Electrostasy/dots/blob/3b81723feece67610a252ce754912f6769f0cd34/hosts/phobos/klipper.nix#L43-L65 - overlays = - let - mkCompatibleDtsFile = dtbo: - let - drv = pkgs.runCommand "fix-dts" { nativeBuildInputs = with pkgs; [ dtc gnused ]; } '' - mkdir "$out" - dtc -I dtb -O dts ${dtbo} | sed -e 's/bcm2835/bcm2711/' > $out/overlay.dts - ''; - in - "${drv}/overlay.dts"; - - inherit (config.boot.kernelPackages) kernel; - in - [ - { - name = "imx708.dtbo"; - dtsFile = mkCompatibleDtsFile "${kernel}/dtbs/overlays/imx708.dtbo"; - } - { - name = "vc4-kms-v3d-pi4.dtbo"; - dtsFile = mkCompatibleDtsFile "${kernel}/dtbs/overlays/vc4-kms-v3d-pi4.dtbo"; - } - ]; - }; - firmware = with pkgs; [ - firmwareLinuxNonfree - wireless-regdb - ]; - }; - - services.udev.extraRules = '' - SUBSYSTEM="dma_heap", GROUP="video", MODE="0600" - ''; + raspberry-pi-nix.board = "bcm2711"; networking = { hostId = "731d1660"; @@ -68,12 +26,10 @@ services.openssh.settings.PermitRootLogin = lib.mkForce "prohibit-password"; environment.systemPackages = with pkgs; [ - camera-streamer git neovim libraspberrypi raspberrypi-eeprom - rpicam-apps v4l-utils unstable.ustreamer ]; diff --git a/hosts/skycam/hardware-configuration.nix b/hosts/skycam/hardware-configuration.nix index 65f519a..20155b8 100644 --- a/hosts/skycam/hardware-configuration.nix +++ b/hosts/skycam/hardware-configuration.nix @@ -1,24 +1,6 @@ { config, lib, modulesPath, ... }: { - imports = [ - (modulesPath + "/installer/sd-card/sd-image-aarch64.nix") - ]; - - boot = { - kernelModules = [ "bcm2835-v4l2" ]; - kernelParams = [ "cma=512M" ]; - supportedFilesystems = lib.mkForce [ "f2fs" "vfat xfs" ]; - tmp.cleanOnBoot = true; - }; - - nixpkgs.overlays = [ - (final: super: { - makeModulesClosure = x: - super.makeModulesClosure (x // { allowMissing = true; }); - }) - ]; - fileSystems = { "/" = { device = "/dev/disk/by-label/NIXOS_SD"; diff --git a/modules/options.nix b/modules/options.nix index 0ab1d70..014ea98 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -36,7 +36,7 @@ with lib; in { inherit name; isNormalUser = true; - extraGroups = [ "networkmanager" "wheel" "lxd" ]; + extraGroups = [ "networkmanager" "wheel" "lxd" "video" ]; description = "Jordan Holt"; useDefaultShell = true; openssh.authorizedKeys.keys = [ diff --git a/overlays/0001-Always-installed.patch b/overlays/0001-Always-installed.patch new file mode 100644 index 0000000..42b275a --- /dev/null +++ b/overlays/0001-Always-installed.patch @@ -0,0 +1,32 @@ +From ff76624c4407c6132cd4068e6ce065a7b429351f Mon Sep 17 00:00:00 2001 +From: Jordan Holt +Date: Sun, 4 Aug 2024 15:46:04 +0100 +Subject: [PATCH] Always installed + +--- + src/libcamera/source_paths.cpp | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/src/libcamera/source_paths.cpp b/src/libcamera/source_paths.cpp +index 1af5386a..3fc7d044 100644 +--- a/src/libcamera/source_paths.cpp ++++ b/src/libcamera/source_paths.cpp +@@ -39,15 +39,6 @@ namespace { + */ + bool isLibcameraInstalled() + { +- /* +- * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on +- * install. +- */ +- for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) { +- if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH) +- return false; +- } +- + return true; + } + +-- +2.44.1 + diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix new file mode 100644 index 0000000..4ed9aa3 --- /dev/null +++ b/overlays/libcamera.nix @@ -0,0 +1,48 @@ +{ libcamera-src +, libpisp-src +, ... +}: +final: prev: +{ + libpisp = final.stdenv.mkDerivation { + name = "libpisp"; + version = "1.0.6"; + src = libpisp-src; + nativeBuildInputs = with final; [ pkg-config meson ninja ]; + buildInputs = with final; [ nlohmann_json boost ]; + # Meson is no longer able to pick up Boost automatically. + # https://github.com/NixOS/nixpkgs/issues/86131 + BOOST_INCLUDEDIR = "${prev.lib.getDev final.boost}/include"; + BOOST_LIBRARYDIR = "${prev.lib.getLib final.boost}/lib"; + }; + + libcamera = prev.libcamera.overrideAttrs (old: { + version = "0.2.0"; + src = libcamera-src; + buildInputs = old.buildInputs ++ (with final; [ + libpisp openssl libtiff + (python3.withPackages (ps: with ps; [ + python3-gnutls pybind11 pyyaml ply + ])) + libglibutil gst_all_1.gst-plugins-base + ]); + patches = [ ./0001-Always-installed.patch ]; + postPatch = '' + patchShebangs utils/ + patchShebangs src/py/ + ''; + mesonFlags = [ + "--buildtype=release" + "-Dpipelines=rpi/vc4,rpi/pisp" + "-Dipas=rpi/vc4,rpi/pisp" + "-Dv4l2=true" + "-Dgstreamer=enabled" + "-Dtest=false" + "-Dlc-compliance=disabled" + "-Dcam=disabled" + "-Dqcam=disabled" + "-Ddocumentation=enabled" + "-Dpycamera=enabled" + ]; + }); +} From be105b856522a9e001400d30ea016287337ea912 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Mon, 5 Aug 2024 17:55:10 +0100 Subject: [PATCH 2/7] Add deploy step and update camera-streamer --- flake.nix | 24 ++++++++++++++++-------- pkgs/camera-streamer/package.nix | 15 ++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/flake.nix b/flake.nix index e182efb..0590925 100644 --- a/flake.nix +++ b/flake.nix @@ -148,14 +148,22 @@ path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.vps1; }; }; - # pi = { - # hostname = "10.0.1.191"; - # - # profiles.system = { - # user = "root"; - # path = deploy-rs.lib.aarch64-linux.activate.nixos self.nixosConfigurations.pi; - # }; - # }; + pi = { + hostname = "10.0.1.191"; + + profiles.system = { + user = "root"; + path = deploy-rs.lib.aarch64-linux.activate.nixos self.nixosConfigurations.pi; + }; + }; + skycam = { + hostname = "10.0.1.146"; + + profiles.system = { + user = "root"; + path = deploy-rs.lib.aarch64-linux.activate.nixos self.nixosConfigurations.skycam; + }; + }; }; }; diff --git a/pkgs/camera-streamer/package.nix b/pkgs/camera-streamer/package.nix index c051f9f..c2bf2f5 100644 --- a/pkgs/camera-streamer/package.nix +++ b/pkgs/camera-streamer/package.nix @@ -1,5 +1,5 @@ { stdenv -, fetchFromGitHub +, fetchFromGitea , cmake , gnumake @@ -12,9 +12,9 @@ , ffmpeg , libcameraSupport ? true , libcamera -, rtspSupport ? true +, rtspSupport ? false , live555 -, webrtcSupport ? true +, webrtcSupport ? false , openssl , lib @@ -24,11 +24,12 @@ stdenv.mkDerivation (finalAttrs: { pname = "camera-streamer"; version = "0.2.8"; - src = fetchFromGitHub { - owner = "ayufan"; + src = fetchFromGitea { + domain = "git.vimium.com"; + owner = "jordan"; repo = "camera-streamer"; - rev = "refs/tags/v${finalAttrs.version}"; - hash = "sha256-8vV8BMFoDeh22I1/qxk6zttJROaD/lrThBxXHZSPpT4="; + rev = "464f05172c725b4b302464eecdb8b6e85fda6e84"; + hash = "sha256-IkLR/oozYU+hfpct+GXej2T3GEhauQtqwWOcrQAErbM="; fetchSubmodules = true; }; From ccc8ae2a4ac4a38c411668e61489fb09d0b7816f Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Mon, 5 Aug 2024 22:38:18 +0100 Subject: [PATCH 3/7] Add uStreamer service to skycam --- flake.nix | 2 +- hosts/skycam/default.nix | 27 +++- .../0001-Remove-relative-config-lookups.patch | 142 ++++++++++++++++++ overlays/libcamera.nix | 51 ++----- 4 files changed, 183 insertions(+), 39 deletions(-) create mode 100644 overlays/0001-Remove-relative-config-lookups.patch diff --git a/flake.nix b/flake.nix index 8fc4b73..3da5acb 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,7 @@ overlays = [ agenix.overlays.default (import ./overlays/gnome.nix) - (import ./overlays/default.nix) + (import ./overlays/libcamera.nix) ( final: prev: { unstable = import inputs.nixpkgs-unstable { system = final.system; }; diff --git a/hosts/skycam/default.nix b/hosts/skycam/default.nix index bea0112..e8e2a9f 100644 --- a/hosts/skycam/default.nix +++ b/hosts/skycam/default.nix @@ -6,7 +6,10 @@ ../server.nix ]; - raspberry-pi-nix.board = "bcm2711"; + raspberry-pi-nix = { + board = "bcm2711"; + libcamera-overlay.enable = false; + }; networking = { hostId = "731d1660"; @@ -25,9 +28,31 @@ services.openssh.settings.PermitRootLogin = lib.mkForce "prohibit-password"; + systemd.services.ustreamer = { + enable = true; + description = "uStreamer service"; + unitConfig = { + Type = "simple"; + ConditionPathExists = "/sys/bus/i2c/drivers/imx708/10-001a/video4linux"; + }; + serviceConfig = { + ExecStart = ''${pkgs.libcamera}/bin/libcamerify ${pkgs.unstable.ustreamer}/bin/ustreamer \ + --host=0.0.0.0 \ + --resolution=4608x2592 + ''; + DynamicUser = "yes"; + SupplementaryGroups = [ "video" "i2c" ]; + Restart = "always"; + RestartSec = 10; + }; + wantedBy = [ "network-online.target" ]; + confinement.mode = "chroot-only"; + }; + environment.systemPackages = with pkgs; [ git neovim + libcamera libraspberrypi raspberrypi-eeprom v4l-utils diff --git a/overlays/0001-Remove-relative-config-lookups.patch b/overlays/0001-Remove-relative-config-lookups.patch new file mode 100644 index 0000000..61a6e92 --- /dev/null +++ b/overlays/0001-Remove-relative-config-lookups.patch @@ -0,0 +1,142 @@ +From 57128bb78f56cadf9e2dcca5ba4d710c3bd478a7 Mon Sep 17 00:00:00 2001 +From: Jordan Holt +Date: Mon, 5 Aug 2024 21:53:09 +0100 +Subject: [PATCH] Remove relative config lookups + +--- + src/libcamera/ipa_manager.cpp | 16 ---------- + src/libcamera/ipa_proxy.cpp | 48 ++---------------------------- + src/libcamera/pipeline_handler.cpp | 21 ++----------- + 3 files changed, 4 insertions(+), 81 deletions(-) + +diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp +index f4e0b633..6d5bbd05 100644 +--- a/src/libcamera/ipa_manager.cpp ++++ b/src/libcamera/ipa_manager.cpp +@@ -131,22 +131,6 @@ IPAManager::IPAManager() + << "No IPA found in '" << modulePaths << "'"; + } + +- /* +- * When libcamera is used before it is installed, load IPAs from the +- * same build directory as the libcamera library itself. +- */ +- std::string root = utils::libcameraBuildPath(); +- if (!root.empty()) { +- std::string ipaBuildPath = root + "src/ipa"; +- constexpr int maxDepth = 2; +- +- LOG(IPAManager, Info) +- << "libcamera is not installed. Adding '" +- << ipaBuildPath << "' to the IPA search path"; +- +- ipaCount += addDir(ipaBuildPath.c_str(), maxDepth); +- } +- + /* Finally try to load IPAs from the installed system path. */ + ipaCount += addDir(IPA_MODULE_DIR); + +diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp +index 69975d8f..cd9284a3 100644 +--- a/src/libcamera/ipa_proxy.cpp ++++ b/src/libcamera/ipa_proxy.cpp +@@ -122,33 +122,11 @@ std::string IPAProxy::configurationFile(const std::string &name, + } + } + +- std::string root = utils::libcameraSourcePath(); +- if (!root.empty()) { +- /* +- * When libcamera is used before it is installed, load +- * configuration files from the source directory. The +- * configuration files are then located in the 'data' +- * subdirectory of the corresponding IPA module. +- */ +- std::string ipaConfDir = root + "src/ipa/" + ipaName + "/data"; +- +- LOG(IPAProxy, Info) +- << "libcamera is not installed. Loading IPA configuration from '" +- << ipaConfDir << "'"; +- +- std::string confPath = ipaConfDir + "/" + name; ++ for (const auto &dir : utils::split(IPA_CONFIG_DIR, ":")) { ++ std::string confPath = dir + "/" + ipaName + "/" + name; + ret = stat(confPath.c_str(), &statbuf); + if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG) + return confPath; +- +- } else { +- /* Else look in the system locations. */ +- for (const auto &dir : utils::split(IPA_CONFIG_DIR, ":")) { +- std::string confPath = dir + "/" + ipaName + "/" + name; +- ret = stat(confPath.c_str(), &statbuf); +- if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG) +- return confPath; +- } + } + + if (fallbackName.empty()) { +@@ -197,28 +175,6 @@ std::string IPAProxy::resolvePath(const std::string &file) const + } + } + +- /* +- * When libcamera is used before it is installed, load proxy workers +- * from the same build directory as the libcamera directory itself. +- * This requires identifying the path of the libcamera.so, and +- * referencing a relative path for the proxy workers from that point. +- */ +- std::string root = utils::libcameraBuildPath(); +- if (!root.empty()) { +- std::string ipaProxyDir = root + "src/libcamera/proxy/worker"; +- +- LOG(IPAProxy, Info) +- << "libcamera is not installed. Loading proxy workers from '" +- << ipaProxyDir << "'"; +- +- std::string proxyPath = ipaProxyDir + proxyFile; +- if (!access(proxyPath.c_str(), X_OK)) +- return proxyPath; +- +- return std::string(); +- } +- +- /* Else try finding the exec target from the install directory. */ + std::string proxyPath = std::string(IPA_PROXY_DIR) + proxyFile; + if (!access(proxyPath.c_str(), X_OK)) + return proxyPath; +diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp +index 5ea2ca78..fd8555ca 100644 +--- a/src/libcamera/pipeline_handler.cpp ++++ b/src/libcamera/pipeline_handler.cpp +@@ -561,25 +561,8 @@ std::string PipelineHandler::configurationFile(const std::string &subdir, + struct stat statbuf; + int ret; + +- std::string root = utils::libcameraSourcePath(); +- if (!root.empty()) { +- /* +- * When libcamera is used before it is installed, load +- * configuration files from the source directory. The +- * configuration files are then located in the 'data' +- * subdirectory of the corresponding pipeline handler. +- */ +- std::string confDir = root + "src/libcamera/pipeline/"; +- confPath = confDir + subdir + "/data/" + name; +- +- LOG(Pipeline, Info) +- << "libcamera is not installed. Loading platform configuration file from '" +- << confPath << "'"; +- } else { +- /* Else look in the system locations. */ +- confPath = std::string(LIBCAMERA_DATA_DIR) +- + "/pipeline/" + subdir + '/' + name; +- } ++ confPath = std::string(LIBCAMERA_DATA_DIR) ++ + "/pipeline/" + subdir + '/' + name; + + ret = stat(confPath.c_str(), &statbuf); + if (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG) +-- +2.44.1 + diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index 4ed9aa3..cdbb7ec 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -1,48 +1,25 @@ -{ libcamera-src -, libpisp-src -, ... -}: final: prev: { - libpisp = final.stdenv.mkDerivation { - name = "libpisp"; - version = "1.0.6"; - src = libpisp-src; - nativeBuildInputs = with final; [ pkg-config meson ninja ]; - buildInputs = with final; [ nlohmann_json boost ]; - # Meson is no longer able to pick up Boost automatically. - # https://github.com/NixOS/nixpkgs/issues/86131 - BOOST_INCLUDEDIR = "${prev.lib.getDev final.boost}/include"; - BOOST_LIBRARYDIR = "${prev.lib.getLib final.boost}/lib"; - }; - libcamera = prev.libcamera.overrideAttrs (old: { - version = "0.2.0"; - src = libcamera-src; - buildInputs = old.buildInputs ++ (with final; [ - libpisp openssl libtiff - (python3.withPackages (ps: with ps; [ - python3-gnutls pybind11 pyyaml ply - ])) - libglibutil gst_all_1.gst-plugins-base - ]); - patches = [ ./0001-Always-installed.patch ]; postPatch = '' - patchShebangs utils/ - patchShebangs src/py/ + patchShebangs utils/ src/py/ ''; - mesonFlags = [ + + patches = [ + ./0001-Remove-relative-config-lookups.patch + ]; + + mesonFlags = old.mesonFlags ++ [ "--buildtype=release" - "-Dpipelines=rpi/vc4,rpi/pisp" - "-Dipas=rpi/vc4,rpi/pisp" - "-Dv4l2=true" + "-Dpipelines=rpi/vc4" + "-Dipas=rpi/vc4" "-Dgstreamer=enabled" "-Dtest=false" - "-Dlc-compliance=disabled" - "-Dcam=disabled" - "-Dqcam=disabled" - "-Ddocumentation=enabled" - "-Dpycamera=enabled" + "-Dcam=enabled" ]; }); + + camera-streamer = prev.callPackage ../pkgs/camera-streamer/package.nix { + libcamera = final.libcamera; + }; } From ad9f4e52efc4735cce52e5188fd21b8e71191c48 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Tue, 6 Aug 2024 08:29:32 +0100 Subject: [PATCH 4/7] Revert "Update rpi base" This reverts commit 5903eb650a3edd2c0310bcfebeb665ec21b1b7b7. --- flake.lock | 193 ------------------------ flake.nix | 5 +- hosts/common.nix | 2 - hosts/skycam/default.nix | 44 +++++- hosts/skycam/hardware-configuration.nix | 18 +++ modules/options.nix | 2 +- overlays/0001-Always-installed.patch | 32 ---- 7 files changed, 61 insertions(+), 235 deletions(-) delete mode 100644 overlays/0001-Always-installed.patch diff --git a/flake.lock b/flake.lock index a0a9396..d3e6941 100644 --- a/flake.lock +++ b/flake.lock @@ -365,40 +365,6 @@ "type": "github" } }, - "libcamera-src": { - "flake": false, - "locked": { - "lastModified": 1718617480, - "narHash": "sha256-qqEMJzMotybf1nJp1dsz3zc910Qj0TmqCm1CwuSb1VY=", - "owner": "raspberrypi", - "repo": "libcamera", - "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "repo": "libcamera", - "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", - "type": "github" - } - }, - "libpisp-src": { - "flake": false, - "locked": { - "lastModified": 1718613892, - "narHash": "sha256-V/d4RrXoq8HNc8r/Kr1gH3E7YTZzfIdgbaJtq/Xi7uQ=", - "owner": "raspberrypi", - "repo": "libpisp", - "rev": "b567f04556801ca350331ed21a1ae3eef4675c23", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "v1.0.6", - "repo": "libpisp", - "type": "github" - } - }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -537,22 +503,6 @@ "type": "indirect" } }, - "nixpkgs_4": { - "locked": { - "lastModified": 1722651103, - "narHash": "sha256-IRiJA0NVAoyaZeKZluwfb2DoTpBAj+FLI0KfybBeDU0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a633d89c6dc9a2a8aae11813a62d7c58b2c0cc51", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, "nixvim": { "inputs": { "devshell": "devshell", @@ -604,33 +554,6 @@ "type": "github" } }, - "raspberry-pi-nix": { - "inputs": { - "libcamera-src": "libcamera-src", - "libpisp-src": "libpisp-src", - "nixpkgs": "nixpkgs_4", - "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", - "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", - "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_10_0-rc5-src": "rpi-linux-6_10_0-rc5-src", - "rpi-linux-6_6_31-src": "rpi-linux-6_6_31-src", - "rpicam-apps-src": "rpicam-apps-src", - "u-boot-src": "u-boot-src" - }, - "locked": { - "lastModified": 1722525809, - "narHash": "sha256-LTCbMSKbSHvKubfXolss39UeTKDIoP9wWTyXV/tDPHU=", - "owner": "nix-community", - "repo": "raspberry-pi-nix", - "rev": "35bb455fdeb495043a94433f67e05fa88980cdad", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "raspberry-pi-nix", - "type": "github" - } - }, "root": { "inputs": { "agenix": "agenix", @@ -646,113 +569,10 @@ "nixpkgs-unstable": "nixpkgs-unstable", "nixvim": "nixvim", "plasma-manager": "plasma-manager", - "raspberry-pi-nix": "raspberry-pi-nix", "secrets": "secrets", "thunderbird-gnome-theme": "thunderbird-gnome-theme" } }, - "rpi-bluez-firmware-src": { - "flake": false, - "locked": { - "lastModified": 1708969706, - "narHash": "sha256-KakKnOBeWxh0exu44beZ7cbr5ni4RA9vkWYb9sGMb8Q=", - "owner": "RPi-Distro", - "repo": "bluez-firmware", - "rev": "78d6a07730e2d20c035899521ab67726dc028e1c", - "type": "github" - }, - "original": { - "owner": "RPi-Distro", - "ref": "bookworm", - "repo": "bluez-firmware", - "type": "github" - } - }, - "rpi-firmware-nonfree-src": { - "flake": false, - "locked": { - "lastModified": 1708967191, - "narHash": "sha256-BGq0+cr+xBRwQM/LqiQuRWuZpQsKM5jfcrNCqWMuVzM=", - "owner": "RPi-Distro", - "repo": "firmware-nonfree", - "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", - "type": "github" - }, - "original": { - "owner": "RPi-Distro", - "ref": "bookworm", - "repo": "firmware-nonfree", - "type": "github" - } - }, - "rpi-firmware-src": { - "flake": false, - "locked": { - "lastModified": 1716978780, - "narHash": "sha256-KsCo7ZG6vKstxRyFljZtbQvnDSqiAPdUza32xTY/tlA=", - "owner": "raspberrypi", - "repo": "firmware", - "rev": "3590de0c181d433af368a95f15bc480bdaff8b47", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "1.20240529", - "repo": "firmware", - "type": "github" - } - }, - "rpi-linux-6_10_0-rc5-src": { - "flake": false, - "locked": { - "lastModified": 1719265450, - "narHash": "sha256-xd/Pz/uZFYW9hJIFKryWDE9Aks6f2EIvEDCmfk0C70c=", - "owner": "raspberrypi", - "repo": "linux", - "rev": "f61d3aca8045e70d64b55f7b98f083738f639ad2", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "rpi-6.10.y", - "repo": "linux", - "type": "github" - } - }, - "rpi-linux-6_6_31-src": { - "flake": false, - "locked": { - "lastModified": 1716545726, - "narHash": "sha256-UWUTeCpEN7dlFSQjog6S3HyEWCCnaqiUqV5KxCjYink=", - "owner": "raspberrypi", - "repo": "linux", - "rev": "c1432b4bae5b6582f4d32ba381459f33c34d1424", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "stable_20240529", - "repo": "linux", - "type": "github" - } - }, - "rpicam-apps-src": { - "flake": false, - "locked": { - "lastModified": 1717081637, - "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", - "owner": "raspberrypi", - "repo": "rpicam-apps", - "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "v1.5.0", - "repo": "rpicam-apps", - "type": "github" - } - }, "secrets": { "flake": false, "locked": { @@ -851,19 +671,6 @@ "type": "github" } }, - "u-boot-src": { - "flake": false, - "locked": { - "lastModified": 1712055538, - "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", - "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" - }, - "original": { - "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" - } - }, "utils": { "inputs": { "systems": "systems_2" diff --git a/flake.nix b/flake.nix index 3da5acb..2ae8f66 100644 --- a/flake.nix +++ b/flake.nix @@ -41,9 +41,6 @@ inputs.nixpkgs.follows = "nixpkgs"; inputs.home-manager.follows = "home-manager"; }; - raspberry-pi-nix = { - url = "github:nix-community/raspberry-pi-nix"; - }; secrets = { url = "git+ssh://git@git.vimium.com/jordan/nix-secrets.git"; flake = false; @@ -123,7 +120,7 @@ mail = mkNixosSystem { system = "x86_64-linux"; name = "mail"; }; odyssey = mkNixosSystem { system = "x86_64-linux"; name = "odyssey"; }; pi = mkNixosSystem { system = "aarch64-linux"; name = "pi"; extraModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ]; }; - skycam = mkNixosSystem { system = "aarch64-linux"; name = "skycam"; extraModules = [ inputs.raspberry-pi-nix.nixosModules.raspberry-pi ]; }; + skycam = mkNixosSystem { system = "aarch64-linux"; name = "skycam"; extraModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ]; }; vps1 = mkNixosSystem { system = "x86_64-linux"; name = "vps1"; }; }; diff --git a/hosts/common.nix b/hosts/common.nix index 655cfd9..816a65c 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -62,12 +62,10 @@ auto-optimise-store = true; substituters = [ "http://odyssey.mesh.vimium.net" - "https://nix-community.cachix.org" "https://cache.nixos.org" ]; trusted-public-keys = [ "odyssey.mesh.vimium.net:ZhQhjscPWjoN4rlZwoMELznEiBnZ9O26iyGA27ibilQ=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ]; }; gc = { diff --git a/hosts/skycam/default.nix b/hosts/skycam/default.nix index e8e2a9f..f331df1 100644 --- a/hosts/skycam/default.nix +++ b/hosts/skycam/default.nix @@ -6,11 +6,49 @@ ../server.nix ]; - raspberry-pi-nix = { - board = "bcm2711"; - libcamera-overlay.enable = false; + hardware = { + raspberry-pi."4" = { + apply-overlays-dtmerge.enable = true; + audio.enable = false; + xhci.enable = false; + }; + deviceTree = { + enable = true; + filter = "*rpi-4-*.dtb"; + # From https://github.com/Electrostasy/dots/blob/3b81723feece67610a252ce754912f6769f0cd34/hosts/phobos/klipper.nix#L43-L65 + overlays = + let + mkCompatibleDtsFile = dtbo: + let + drv = pkgs.runCommand "fix-dts" { nativeBuildInputs = with pkgs; [ dtc gnused ]; } '' + mkdir "$out" + dtc -I dtb -O dts ${dtbo} | sed -e 's/bcm2835/bcm2711/' > $out/overlay.dts + ''; + in + "${drv}/overlay.dts"; + + inherit (config.boot.kernelPackages) kernel; + in + [ + { + name = "imx708.dtbo"; + dtsFile = mkCompatibleDtsFile "${kernel}/dtbs/overlays/imx708.dtbo"; + } + { + name = "vc4-kms-v3d-pi4.dtbo"; + dtsFile = mkCompatibleDtsFile "${kernel}/dtbs/overlays/vc4-kms-v3d-pi4.dtbo"; + } + ]; + }; + firmware = with pkgs; [ + firmwareLinuxNonfree + ]; }; + services.udev.extraRules = '' + SUBSYSTEM="dma_heap", GROUP="video", MODE="0600" + ''; + networking = { hostId = "731d1660"; firewall = { diff --git a/hosts/skycam/hardware-configuration.nix b/hosts/skycam/hardware-configuration.nix index 20155b8..65f519a 100644 --- a/hosts/skycam/hardware-configuration.nix +++ b/hosts/skycam/hardware-configuration.nix @@ -1,6 +1,24 @@ { config, lib, modulesPath, ... }: { + imports = [ + (modulesPath + "/installer/sd-card/sd-image-aarch64.nix") + ]; + + boot = { + kernelModules = [ "bcm2835-v4l2" ]; + kernelParams = [ "cma=512M" ]; + supportedFilesystems = lib.mkForce [ "f2fs" "vfat xfs" ]; + tmp.cleanOnBoot = true; + }; + + nixpkgs.overlays = [ + (final: super: { + makeModulesClosure = x: + super.makeModulesClosure (x // { allowMissing = true; }); + }) + ]; + fileSystems = { "/" = { device = "/dev/disk/by-label/NIXOS_SD"; diff --git a/modules/options.nix b/modules/options.nix index 014ea98..0ab1d70 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -36,7 +36,7 @@ with lib; in { inherit name; isNormalUser = true; - extraGroups = [ "networkmanager" "wheel" "lxd" "video" ]; + extraGroups = [ "networkmanager" "wheel" "lxd" ]; description = "Jordan Holt"; useDefaultShell = true; openssh.authorizedKeys.keys = [ diff --git a/overlays/0001-Always-installed.patch b/overlays/0001-Always-installed.patch deleted file mode 100644 index 42b275a..0000000 --- a/overlays/0001-Always-installed.patch +++ /dev/null @@ -1,32 +0,0 @@ -From ff76624c4407c6132cd4068e6ce065a7b429351f Mon Sep 17 00:00:00 2001 -From: Jordan Holt -Date: Sun, 4 Aug 2024 15:46:04 +0100 -Subject: [PATCH] Always installed - ---- - src/libcamera/source_paths.cpp | 9 --------- - 1 file changed, 9 deletions(-) - -diff --git a/src/libcamera/source_paths.cpp b/src/libcamera/source_paths.cpp -index 1af5386a..3fc7d044 100644 ---- a/src/libcamera/source_paths.cpp -+++ b/src/libcamera/source_paths.cpp -@@ -39,15 +39,6 @@ namespace { - */ - bool isLibcameraInstalled() - { -- /* -- * DT_RUNPATH (DT_RPATH when the linker uses old dtags) is removed on -- * install. -- */ -- for (const ElfW(Dyn) *dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn) { -- if (dyn->d_tag == DT_RUNPATH || dyn->d_tag == DT_RPATH) -- return false; -- } -- - return true; - } - --- -2.44.1 - From 0c564903abd939f4397cf5729296f233c9bc0c5e Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Tue, 6 Aug 2024 08:58:05 +0100 Subject: [PATCH 5/7] Fix ustreamer --- flake.lock | 6 +++--- hosts/skycam/default.nix | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index d3e6941..e091924 100644 --- a/flake.lock +++ b/flake.lock @@ -459,11 +459,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1722630782, - "narHash": "sha256-hMyG9/WlUi0Ho9VkRrrez7SeNlDzLxalm9FwY7n/Noo=", + "lastModified": 1722813957, + "narHash": "sha256-IAoYyYnED7P8zrBFMnmp7ydaJfwTnwcnqxUElC1I26Y=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d04953086551086b44b6f3c6b7eeb26294f207da", + "rev": "cb9a96f23c491c081b38eab96d22fa958043c9fa", "type": "github" }, "original": { diff --git a/hosts/skycam/default.nix b/hosts/skycam/default.nix index f331df1..4b6cad4 100644 --- a/hosts/skycam/default.nix +++ b/hosts/skycam/default.nix @@ -78,8 +78,6 @@ --host=0.0.0.0 \ --resolution=4608x2592 ''; - DynamicUser = "yes"; - SupplementaryGroups = [ "video" "i2c" ]; Restart = "always"; RestartSec = 10; }; From 91d66003aafc215a2672c296acadcfeefeb38b56 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Fri, 9 Aug 2024 19:36:15 +0100 Subject: [PATCH 6/7] Add build instructions for skycam to README --- hosts/skycam/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hosts/skycam/README.md b/hosts/skycam/README.md index de64288..29f932d 100644 --- a/hosts/skycam/README.md +++ b/hosts/skycam/README.md @@ -20,3 +20,10 @@ SD card | `/dev/mmcblk0` (ext4, NixOS Root) ## Devices and connections - Camera Module 3 with wide-angle lens +## Building +To generate a compressed SD card image for Skycam, run: +`nix build '.#nixosConfigurations.skycam.config.system.build.sdImage'` + +Once a card is imaged, the existing SSH host keys should be copied to +`/etc/ssh` manually to enable secret decryption. + From 7943e063c2200ff81abbad8fc778ff8eb57fa3c2 Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Fri, 9 Aug 2024 20:03:42 +0100 Subject: [PATCH 7/7] Prevent skycam reboot on panic --- hosts/skycam/hardware-configuration.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hosts/skycam/hardware-configuration.nix b/hosts/skycam/hardware-configuration.nix index 65f519a..a3a3728 100644 --- a/hosts/skycam/hardware-configuration.nix +++ b/hosts/skycam/hardware-configuration.nix @@ -7,9 +7,12 @@ boot = { kernelModules = [ "bcm2835-v4l2" ]; - kernelParams = [ "cma=512M" ]; - supportedFilesystems = lib.mkForce [ "f2fs" "vfat xfs" ]; - tmp.cleanOnBoot = true; + kernelParams = [ + "cma=512M" + "panic=0" + ]; + supportedFilesystems = lib.mkForce [ "f2fs" "vfat" "xfs" ]; + tmp.cleanOnBoot = false; }; nixpkgs.overlays = [