diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/CMakeLists.txt b/CMakeLists.txt index 91cbb83..3aa1cff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ pkg_check_modules(LIBWAYLAND_CLIENT REQUIRED wayland-client) execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_subdirectory(modules/xrealInterfaceLibrary/interface_lib) # Set the library directory based on architecture diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..fa53d4c --- /dev/null +++ b/default.nix @@ -0,0 +1,9 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } +) {src = ./.;}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..424711a --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1748693115, + "narHash": "sha256-StSrWhklmDuXT93yc3GrTlb0cKSS0agTAxMGjLKAsY8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "910796cabe436259a29a72e8d3f5e180fc6dfacc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ae216b7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Nix Flake for XRLinuxDriver"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + outputs = { + self, + nixpkgs, + flake-utils, + ... + }: let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + in + flake-utils.lib.eachSystem systems + ( + system: let + pkgs = import nixpkgs { + inherit system; + }; + in { + packages = { + xrlinuxdriver = pkgs.callPackage ./nix {inherit self;}; + default = self.packages.${pkgs.system}.xrlinuxdriver; + }; + + devShells.default = pkgs.mkShell {inputsFrom = with self.packages.${pkgs.system}; [default];}; + } + ) + // { + overlays.default = final: prev: {inherit (self.packages.${final.system}) xrlinuxdriver;}; + }; +} diff --git a/modules/xrealInterfaceLibrary b/modules/xrealInterfaceLibrary index d101fae..3225fcc 160000 --- a/modules/xrealInterfaceLibrary +++ b/modules/xrealInterfaceLibrary @@ -1 +1 @@ -Subproject commit d101fae45797e1bc6bfa3716cacb8a1002cb6252 +Subproject commit 3225fcc575e19a8407d5019903567cff1c3ed1a8 diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..cb3c695 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,112 @@ +{ + self, + lib, + pkgs, + stdenv, + fetchFromGitLab, + libusb1, + curl, + openssl, + libevdev, + json_c, + hidapi, + wayland, + cmake, + pkg-config, + python3, + libffi, + autoPatchelfHook, + ... +}: let + pythonEnv = python3.withPackages (ps: [ps.pyyaml]); + buildInputs = [ + curl + hidapi + json_c + libevdev + libffi + libusb1 + openssl + stdenv.cc.cc.lib + wayland + ]; + arch = + if pkgs.system == "aarch64-linux" + then "aarch64" + else if pkgs.system == "x86_64-linux" + then "x86_64" + else throw "Unsupported system ${pkgs.system}"; +in + stdenv.mkDerivation rec { + pname = "xrlinuxdriver"; + version = "unstable"; + + srcs = [ + (fetchFromGitLab rec { + domain = "gitlab.com"; + owner = "TheJackiMonster"; + repo = "nrealAirLinuxDriver"; + rev = "3225fcc575e19a8407d5019903567cff1c3ed1a8"; + hash = "sha256-NRbcANt/CqREQZoYIYtTGVbvkZ7uo2Tm90s6prlsrQE="; + fetchSubmodules = true; + name = "${repo}-src"; + }) + (lib.cleanSourceWith { + src = self; + name = "${pname}-src"; + }) + ]; + sourceRoot = "${(builtins.elemAt srcs 1).name}"; + + postUnpack = let + nrealAirLinuxDriver = (builtins.elemAt srcs 0).name; + in '' + mkdir -p $sourceRoot/modules/xrealInterfaceLibrary + cp -R ${nrealAirLinuxDriver}/* $sourceRoot/modules/xrealInterfaceLibrary + chmod -R u+w $sourceRoot + ''; + + nativeBuildInputs = [ + cmake + pkg-config + pythonEnv + autoPatchelfHook + ]; + inherit buildInputs; + + cmakeFlags = [ + "-DCMAKE_SKIP_RPATH=ON" + ]; + cmakeBuildDir = "build"; + cmakeBuildType = "RelWithDebInfo"; + + installPhase = '' + mkdir -p $out/bin $out/lib/systemd/user $out/lib/udev/rules.d $out/lib/${arch} + cp xrDriver ../bin/xr_driver_cli ../bin/xr_driver_verify $out/bin + cp ../udev/* $out/lib/udev/rules.d/ + cp ../lib/${arch}/* $out/lib/${arch}/ + cp ../systemd/xr-driver.service $out/lib/systemd/user/xr-driver.service + cp ${hidapi}/lib/libhidapi-hidraw.so.0 $out/lib/ + substituteInPlace \ + $out/lib/systemd/user/xr-driver.service \ + --replace-fail "ExecStart={bin_dir}/xrDriver" "ExecStart=$out/bin/xrDriver" \ + --replace-fail "{ld_library_path}" "$out/lib/${arch}" + ''; + + preBuild = '' + addAutoPatchelfSearchPath $out/usr/lib/${arch} + ''; + + doInstallCheck = false; + # The default release is a script which will do an impure download + # just ensure that the application can run without network + + meta = { + homepage = "https://github.com/wheaney/XRLinuxDriver"; + license = lib.licenses.mit; + description = "Linux service for interacting with XR devices."; + mainProgram = "xrDriver"; + maintainers = with lib.maintainers; [shymega]; + platforms = lib.platforms.linux; + }; + } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..438e069 --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2023 Dom Rodriguez +# +# SPDX-License-Identifier: GPL-3.0-only +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } +) {src = ./.;}).shellNix