0

1 Context

I am trying to build nix expressions for two packages:

  1. OSVR-Core
  2. OSVR-Vive

I have successfully written (1); however, I am having a problem with (2). This is partially because in order to build (2), you need (1) as a dependency. But here's the problem: (2) tries to paste a file into (1).

2 Error Message

Here is the error message I'm getting when trying to build (2):

-- Installing: /nix/store/9y6p1npy94sbpb39l0rd8rgdhbknll6r-OSVR-Core/lib/osvr-plugins-0/com_osvr_Vive.so
CMake Error at cmake_install.cmake:50 (file):
  file INSTALL cannot copy file
  "/tmp/nix-build-OSVR-Core.drv-0/OSVR-Vive-e0ebcdb/build/nix/store/9y6p1npy94sbpb39l0rd8rgdhbknll6r-OSV
R-Core/lib/osvr-plugins-0/com_osvr_Vive.so"                                                            
  to
  "/nix/store/9y6p1npy94sbpb39l0rd8rgdhbknll6r-OSVR-Core/lib/osvr-plugins-0/com_osvr_Vive.so".


make: *** [Makefile:74: install] Error 1
builder for ‘/nix/store/cj1yzm9x1pdyzwd76dh7xn1vq6zvcnq2-OSVR-Core.drv’ failed with exit code 2

As you can see, OSVR-Vive tries to paste a file into /nix/store/*-OSVR-Core/lib/osvr-plugins-0, and fails.

3 Nix Expressions (in case relevant)

OSVR-Core.nix

{ pkgs, stdenv, fetchgit, cmake, jsoncpp, opencv, python27, libusb1, boost }:

stdenv.mkDerivation {
  name = "OSVR-Core";
  buildInputs = with pkgs; [ cmake
                            jsoncpp
                            opencv
                            python27
                            libusb1
                            boost
                            (callPackage ./libfunctionality.nix { })
                            ];
  src = fetchgit {
    url       = "https://github.com/OSVR/OSVR-Core.git";
    rev       = "95655d3174851670b85e9be8e8620ba28f9872f4";
    sha256    = "16sbfv4fxcvxqhm81in8lkvjpfbiz312kh7pm4vipj7dja1fchy8";
    deepClone = true; # git clone --recursive
  };
}

OSVR-Vive.nix

{ pkgs, stdenv, fetchgit, cmake, eigen3_3, boost, jsoncpp }:

stdenv.mkDerivation {
  name = "OSVR-Vive";
  buildInputs = with pkgs; [ cmake
                            (callPackage ./libfunctionality.nix { })
                            (callPackage ./OSVR-Core.nix { })
                            eigen3_3
                            boost
                            jsoncpp
                            ];
  src = fetchgit {
    url    = "https://github.com/OSVR/OSVR-Vive.git";
    rev    = "e0ebcdbe2d065448fcebacc2828712a946695004";
    #sha256 = "1cf90x2ddqgylh98ssigr5c86l8psa3q512rl933kpz93n2can5g";
    sha256 = "1d10gp7xalqdclskxc804fp56gz3k1sqzzqbdm3y54iwshmahwfw";
    deepClone = true; # git clone --recursive
  };
}
George
  • 6,927
  • 4
  • 34
  • 67

1 Answers1

1

From your post, it looks like OSVR-Core is some kind of software that accepts plugins, and OSVR-Vive is a plugin for OSVR-Core. Plugins are meant to be stored as shared objects in the lib/osvr-plugins-0 directory wherever OSVR-Core is installed.

That plan would work fine on a normal Linux system where the filesystem is a free-for-all and programs just install themselves wherever they want to, but that is not how Nix behaves.

First of all, you should make and apply a patch to OSVR-Vive so that it installs its plugin to somewhere in its own Nix store output.

Next, you should change OSVR-Core so that it knows how to find such plugins at runtime. I would suggest there should be an environment variable called OSVR_PLUGIN_PATH and that OSVR-Core should search all the directories listed in that variable for plugins. That mechanism might already exist; you can check the documentation and source code of OSVR-Core to see if it does.

Another plan would be to build OSVR-Core and OSVR-Vive in the same derivation so they can both write files to the same lib directory. That does not sound ideal in general, but you could probably get it to work without doing any patching.

How to patch software in Nix

To make a patch, what should do is extract two copies of the software's source code in one directory, and name one of them with a suffix that is something like "-orig". Then modify the other copy. Then run:

diff -ur mysoftware-orig mysoftware > mypatch.patch

Then you can include that in your Nix derivation. If you are using the standard nixpkgs setup for building, I think you just write something like:

patches = [ ./mypatch.patch; ];

Anyway, you can look in the nixpkgs repository for lots of examples of how to patch software.

David Grayson
  • 84,103
  • 24
  • 152
  • 189