Skip to content

Commit 17a67cd

Browse files
committed
nix: Add Nix package manager support
- Add Nix Flake support, with devShells and an Nix overlay. - Add support for legacy Nix with `default.nix` and `shell.nix` for the package and devShell, respectively. - Add `.envrc` to automatically enter a Nix devShell. - Add a package in `nix/default.nix` for the main package entrypoint. Closes: #38
1 parent b8e9ad1 commit 17a67cd

File tree

8 files changed

+254
-1
lines changed

8 files changed

+254
-1
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pkg_check_modules(LIBWAYLAND_CLIENT REQUIRED wayland-client)
4242

4343
execute_process(COMMAND git submodule update --init --recursive
4444
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
45+
4546
add_subdirectory(modules/xrealInterfaceLibrary/interface_lib)
4647

4748
# Set the library directory based on architecture

default.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
in
5+
fetchTarball {
6+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
7+
sha256 = lock.nodes.flake-compat.locked.narHash;
8+
}
9+
) {src = ./.;}).defaultNix

flake.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
description = "Nix Flake for XRLinuxDriver";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
flake-compat = {
7+
url = "github:edolstra/flake-compat";
8+
flake = false;
9+
};
10+
};
11+
outputs = {
12+
self,
13+
nixpkgs,
14+
flake-utils,
15+
...
16+
}: let
17+
systems = [
18+
"x86_64-linux"
19+
"aarch64-linux"
20+
];
21+
in
22+
flake-utils.lib.eachSystem systems
23+
(
24+
system: let
25+
pkgs = import nixpkgs {
26+
inherit system;
27+
};
28+
in {
29+
packages = {
30+
xrlinuxdriver = pkgs.callPackage ./nix {inherit self;};
31+
default = self.packages.${pkgs.system}.xrlinuxdriver;
32+
};
33+
34+
devShells.default = pkgs.mkShell {inputsFrom = with self.packages.${pkgs.system}; [default];};
35+
}
36+
)
37+
// {
38+
overlays.default = final: prev: {inherit (self.packages.${final.system}) xrlinuxdriver;};
39+
};
40+
}

modules/xrealInterfaceLibrary

Submodule xrealInterfaceLibrary updated from d101fae to 3225fcc

nix/default.nix

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
self,
3+
lib,
4+
pkgs,
5+
stdenv,
6+
fetchFromGitLab,
7+
libusb1,
8+
curl,
9+
openssl,
10+
libevdev,
11+
json_c,
12+
hidapi,
13+
wayland,
14+
cmake,
15+
pkg-config,
16+
python3,
17+
libffi,
18+
autoPatchelfHook,
19+
...
20+
}: let
21+
pythonEnv = python3.withPackages (ps: [ps.pyyaml]);
22+
buildInputs = [
23+
curl
24+
hidapi
25+
json_c
26+
libevdev
27+
libffi
28+
libusb1
29+
openssl
30+
stdenv.cc.cc.lib
31+
wayland
32+
];
33+
arch =
34+
if pkgs.system == "aarch64-linux"
35+
then "aarch64"
36+
else if pkgs.system == "x86_64-linux"
37+
then "x86_64"
38+
else throw "Unsupported system ${pkgs.system}";
39+
in
40+
stdenv.mkDerivation rec {
41+
pname = "xrlinuxdriver";
42+
version = "unstable";
43+
44+
srcs = [
45+
(fetchFromGitLab rec {
46+
domain = "gitlab.com";
47+
owner = "TheJackiMonster";
48+
repo = "nrealAirLinuxDriver";
49+
rev = "3225fcc575e19a8407d5019903567cff1c3ed1a8";
50+
hash = "sha256-NRbcANt/CqREQZoYIYtTGVbvkZ7uo2Tm90s6prlsrQE=";
51+
fetchSubmodules = true;
52+
name = "${repo}-src";
53+
})
54+
(lib.cleanSourceWith {
55+
src = self;
56+
name = "${pname}-src";
57+
})
58+
];
59+
sourceRoot = "${(builtins.elemAt srcs 1).name}";
60+
61+
postUnpack = let
62+
nrealAirLinuxDriver = (builtins.elemAt srcs 0).name;
63+
in ''
64+
mkdir -p $sourceRoot/modules/xrealInterfaceLibrary
65+
cp -R ${nrealAirLinuxDriver}/* $sourceRoot/modules/xrealInterfaceLibrary
66+
chmod -R u+w $sourceRoot
67+
'';
68+
69+
nativeBuildInputs = [
70+
cmake
71+
pkg-config
72+
pythonEnv
73+
autoPatchelfHook
74+
];
75+
inherit buildInputs;
76+
77+
cmakeFlags = [
78+
"-DCMAKE_SKIP_RPATH=ON"
79+
];
80+
cmakeBuildDir = "build";
81+
cmakeBuildType = "RelWithDebInfo";
82+
83+
installPhase = ''
84+
mkdir -p $out/bin $out/lib/systemd/user $out/lib/udev/rules.d $out/lib/${arch}
85+
cp xrDriver ../bin/xr_driver_cli ../bin/xr_driver_verify $out/bin
86+
cp ../udev/* $out/lib/udev/rules.d/
87+
cp ../lib/${arch}/* $out/lib/${arch}/
88+
cp ../systemd/xr-driver.service $out/lib/systemd/user/xr-driver.service
89+
cp ${hidapi}/lib/libhidapi-hidraw.so.0 $out/lib/
90+
substituteInPlace \
91+
$out/lib/systemd/user/xr-driver.service \
92+
--replace-fail "ExecStart={bin_dir}/xrDriver" "ExecStart=$out/bin/xrDriver" \
93+
--replace-fail "{ld_library_path}" "$out/lib/${arch}"
94+
'';
95+
96+
preBuild = ''
97+
addAutoPatchelfSearchPath $out/usr/lib/${arch}
98+
'';
99+
100+
doInstallCheck = false;
101+
# The default release is a script which will do an impure download
102+
# just ensure that the application can run without network
103+
104+
meta = {
105+
homepage = "https://github.com/wheaney/XRLinuxDriver";
106+
license = lib.licenses.mit;
107+
description = "Linux service for interacting with XR devices.";
108+
mainProgram = "xrDriver";
109+
maintainers = with lib.maintainers; [shymega];
110+
platforms = lib.platforms.linux;
111+
};
112+
}

shell.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2023 Dom Rodriguez <shymega@shymega.org.uk>
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-only
4+
(import (
5+
let
6+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
7+
in
8+
fetchTarball {
9+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.flake-compat.locked.narHash;
11+
}
12+
) {src = ./.;}).shellNix

0 commit comments

Comments
 (0)