Skip to content

Commit 4dabde1

Browse files
committed
nix: Add Nix Flake support
This commit consists of the following changes: - `default.nix`/`shell.nix` This allows for legacy Nix tooling like `nix-build`/`nix-shell` to work. - `flake.nix` This is for the (new) Nix Flake support. - `flake.lock` As above, but for tracking Flake inputs. - `.envrc` This allows for a fully self-contained developer environment to be setup with Nix. - `nix/default.nix` This is the main package derivation. Both this repo & Nixpkgs are derived from the same codebase. Closes: #38
1 parent 7dd1e8e commit 4dabde1

File tree

7 files changed

+256
-0
lines changed

7 files changed

+256
-0
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
with pkgs; {
30+
packages = {
31+
xrlinuxdriver = callPackage ./nix {inherit self;};
32+
default = self.packages.${system}.xrlinuxdriver;
33+
};
34+
35+
devShells.default = mkShell {inputsFrom = lib.singleton self.packages.${system}.default;};
36+
}
37+
)
38+
// {
39+
overlays.default = final: prev: {inherit (self.packages.${final.system}) xrlinuxdriver;};
40+
};
41+
}

nix/default.nix

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 = "0.12.0.1";
43+
44+
srcs = [
45+
(fetchFromGitLab rec {
46+
domain = "gitlab.com";
47+
owner = "TheJackiMonster";
48+
repo = "nrealAirLinuxDriver";
49+
rev = "d101fae45797e1bc6bfa3716cacb8a1002cb6252";
50+
hash = "sha256-cohOFhdIIBfvO5gbF5fvPIXQFFsdWW2TTkdHzWNdUcc=";
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/usr/lib/systemd/user $out/usr/lib/udev/rules.d $out/usr/lib/${arch}
85+
cp xrDriver ../bin/xr_driver_cli ../bin/xr_driver_verify $out/bin
86+
cp ../udev/* $out/usr/lib/udev/rules.d/
87+
cp ../lib/${arch}/* $out/usr/lib/${arch}/
88+
cp ../systemd/xr-driver.service $out/usr/lib/systemd/user/
89+
cp ${hidapi}/lib/libhidapi-hidraw.so.0 $out/usr/lib/
90+
'';
91+
92+
preBuild = ''
93+
addAutoPatchelfSearchPath $out/usr/lib/${arch}
94+
'';
95+
96+
postInstall = ''
97+
substituteInPlace $out/usr/lib/systemd/user/xr-driver.service \
98+
--replace-fail "ExecStart={bin_dir}/xrDriver" "ExecStart=$out/bin/xrDriver" \
99+
--replace-fail "{ld_library_path}" "$out/usr/lib/${arch}"
100+
'';
101+
102+
doInstallCheck = false;
103+
# The default release is a script which will do an impure download
104+
# just ensure that the application can run without network
105+
106+
meta = with lib; {
107+
homepage = "https://github.com/wheaney/XRLinuxDriver";
108+
license = licenses.mit;
109+
description = "Linux service for interacting with XR devices.";
110+
mainProgram = "xrDriver";
111+
maintainers = with maintainers; [shymega];
112+
platforms = platforms.linux;
113+
};
114+
}

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)