Skip to content

Instantly share code, notes, and snippets.

@cipharius
Forked from egasimus/Arcan.nix
Last active May 1, 2021 11:43
Show Gist options
  • Save cipharius/829fb6baacfcbc668af23488db95fe11 to your computer and use it in GitHub Desktop.
Save cipharius/829fb6baacfcbc668af23488db95fe11 to your computer and use it in GitHub Desktop.
Building Arcan on NixOS, 2021 version
See also:
* https://github.com/NixOS/nixpkgs/issues/49626
* https://gist.github.com/telent/4a92294a767656759959006fe8440122
({ lib, newScope, stdenv, pkgs }: let
# nicer aliases
derive = stdenv.mkDerivation;
concat = builtins.concatStringsSep " ";
# vendored libuvc: don't build, just make sources available
libuvc-src = derive {
name = "libuvc-src";
# using fetchgit instead fetchFromGitHub because
# the .git directory is needed by arcan's cmake scripts
src = pkgs.fetchgit {
leaveDotGit = true;
url = "https://github.com/letoram/libuvc.git";
rev = "v0.0.6";
sha256 = "1jdmiinsd91nnli5hgcn9c6ifj0s6ngbyjwm0z6fim4f8krnh0sf";
};
nativeBuildInputs = with pkgs; [ git ];
# fetchgit strips all refs, leaving just a fetchgit branch
# but cmake needs to check out the ref called 'master':
installPhase = ''
git tag master
cp -r . $out/
cd $out
'';
};
# cmake flags pointing to locations of arcan headers
arcanIncludeDirs = arcan: [
"-DARCAN_SHMIF_INCLUDE_DIR=${arcan}/include/arcan/shmif"
"-DARCAN_TUI_INCLUDE_DIR=${arcan}/include/arcan"
];
# cmake flags pointing to locations of libusb1 headers and binaries
libusbDirs = libusb1: [
"-DLIBUSB_1_INCLUDE_DIRS=${libusb1.dev}/include/libusb-1.0"
"-DLIBUSB_1_LIBRARIES=${libusb1}/lib/libusb-1.0.so"
];
in lib.makeScope newScope (self: with self; let
mkArcanAppl = { name, src, applRoot }: callPackage ({ pkgs }: derive {
name = name;
src = src;
nativeBuildInputs = with pkgs; [ envsubst ];
buildInputs = [ arcan ];
installPhase = ''
mkdir -p $out/${name} $out/bin
cp -r ./${applRoot}/* $out/${name}/
Arcan=${arcan} Appls=$out Appl=${name} envsubst \
< ${./Arcan.wrapper} \
> $out/bin/arcan.${name}
chmod +x $out/bin/arcan.${name}
'';
}) {};
arcanRev = "6afc67b1aca51adf298754c91c363bee9d79be42";
arcanCoreSrc = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "arcan";
rev = arcanRev;
sha256 = "sha256-fY70Z45k1haHqV7hUTKr6s97dT+xgZNioclPBazCkqI=";
};
in {
# arcan core:
arcan = callPackage ({ pkgs }: derive {
name = "arcan";
src = arcanCoreSrc;
patches = [ ./Arcan.nosuid.patch ]; # nix refuses to build suid binaries
postUnpack = '' # add vendored libuvc
mkdir -p ./arcan/external/git/libuvc
pushd ./arcan/external/git/
shopt -s dotglob nullglob # bashism: * now also matches dotfiles
cp -r ${libuvc-src}/* libuvc/
shopt -u dotglob nullglob # phases are stateful
popd
'';
nativeBuildInputs = with pkgs; [ cmake gcc git pkgconfig ];
buildInputs = with pkgs; [
apr
espeak-classic
file
ffmpeg-full
freetype
harfbuzzFull
leptonica
libGL
libdrm
libjpeg
libusb1
libvncserver
libxkbcommon
luajit
lzma
mesa
openal
SDL2
sqlite
tesseract
vlc
wayland
wayland-protocols
xorg.libxcb
xorg.xcbutil
xorg.xcbutilwm
];
PKG_CONFIG_PATH = concat [ # make wayland protocols available
"${pkgs.wayland-protocols}/share/pkgconfig"
"${pkgs.libusb1.dev}/lib/pkgconfig"
];
CFLAGS = concat [ # don't warn on read()/write() without a format
"-Wno-format" # (Arcan code uses them on SHMIFs)
"-Wno-format-security"
];
cmakeFlags = concat (
# cmake won't be able to find these paths on its own:
(libusbDirs pkgs.libusb) ++ [
"-DDRM_INCLUDE_DIR=${pkgs.libdrm.dev}/include/libdrm"
"-DGBM_INCLUDE_DIR=${pkgs.libGL.dev}/include"
"-DWAYLANDPROTOCOLS_PATH=${pkgs.wayland-protocols}/share/wayland-protocols"
# enable features:
"-DVIDEO_PLATFORM=egl-dri"
"-DSHMIF_TUI_ACCEL=ON"
"-DENABLE_LWA=ON"
"-DNO_BUILTIN_OPENHMD=ON"
"-DHYBRID_SDL=On"
"-DHYBRID_HEADLESS=On"
"-DFSRV_DECODE_UVC=Off"
# optional
"-DVERBOSE=ON"
#"--debug-output"
#"--trace"
"../src"
]);
}) {};
# arcan utilities:
acfgfs = callPackage ({ pkgs }: derive {
name = "acfgfs";
src = arcanCoreSrc;
nativeBuildInputs = with pkgs; [ cmake gcc git ];
buildInputs = [ arcan ] ++ (with pkgs; [ fuse3 ]);
cmakeFlags = concat ((arcanIncludeDirs arcan) ++ [ "../src/tools/acfgfs" ]);
}) {};
aclip = callPackage ({ pkgs }: derive {
name = "aclip";
src = arcanCoreSrc;
nativeBuildInputs = with pkgs; [ cmake gcc git pkgconfig ];
buildInputs = [ arcan ];
PKG_CONFIG_PATH = concat [ "${arcan}/lib/pkgconfig" ];
cmakeFlags = concat ((arcanIncludeDirs arcan) ++ [ "../src/tools/aclip" ]);
}) {};
aloadimage = callPackage ({ pkgs }: derive {
name = "aloadimage";
src = arcanCoreSrc;
nativeBuildInputs = with pkgs; [ cmake gcc git ];
buildInputs = [ arcan ];
cmakeFlags = concat ((arcanIncludeDirs arcan) ++ [ "../src/tools/aloadimage" ]);
}) {};
shmmon = callPackage ({ pkgs }: derive {
name = "shmmon";
src = arcanCoreSrc;
nativeBuildInputs = with pkgs; [ cmake gcc git ];
buildInputs = [ arcan ];
cmakeFlags = concat ((arcanIncludeDirs arcan) ++ [ "../src/tools/shmmon" ]);
}) {};
# TODO: provide <hidapi/hidapi.h> include path
#vrbridge = callPackage ({ pkgs }: derive {
#name = "vrbridge";
#src = ./arcan;
#nativeBuildInputs = with pkgs; [ cmake gcc git pkgconfig ];
#buildInputs = [ arcan ] ++ (with pkgs; [ libusb1 ]);
#cmakeFlags = concat (
#(arcanIncludeDirs arcan) ++
#(libusbDirs pkgs.libusb1) ++
#[ "../src/tools/vrbridge" ]
#);
#}) {};
# arcan appls
awb = mkArcanAppl {
name = "awb";
src = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "awb";
rev = "271ef7ffd7f24569d2f836198e4c96b8c617e372";
sha256 = "sha256-vRewHxl0bo7nmosuljhiDOF0k5VnKojRVvr5K+77bVA=";
};
applRoot = "";
};
prio = mkArcanAppl {
name = "prio";
src = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "prio";
rev = "c3f97491339d15f063d6937d5f89bcfaea774dd1";
sha256 = "sha256-Idv/duEYmDk/rO+TI8n+FY3VFDtUEh8C292jh12BJuM=";
};
applRoot = "";
};
durden = mkArcanAppl {
name = "durden";
src = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "durden";
rev = "0a9abe18d38c4a1d55a20b10ae0cab3eb712416c";
sha256 = "sha256-1zAVkuAZGSCuIs1bFRyESCwVyhTNKXJJFuFo/bmknkE=";
};
applRoot = "durden";
};
pipeworld = mkArcanAppl {
name = "pipeworld";
src = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "pipeworld";
rev = "7aaf8487e587b6d6feb37c3df199f5347757a749";
sha256 = "sha256-kCiK+BeXHn7Hdp0qfjGK5voydVV3jfszvsd7awnV1EE=";
};
applRoot = "pipeworld";
};
safespaces = mkArcanAppl {
name = "safespaces";
src = pkgs.fetchFromGitHub {
owner = "letoram";
repo = "safespaces";
rev = "58eef59afba091293cab4d2b156e725f75d92eaf";
sha256 = "sha256-ySOnIpKh2EswYUkwgfv/l3tPEfgXXpGvf0D0Tv+y/VU=";
};
applRoot = "safespaces";
};
}))
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d37b6a4a..03dc4d0b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -802,7 +802,6 @@ else()
amsg("${CL_YEL}egl-dri+privsep${CL_RST}\t${CL_GRN}installing SUID${CL_RST}")
install(TARGETS arcan DESTINATION bin
PERMISSIONS
- SETUID
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
#!/bin/sh
pushd $Arcan/bin # otherwise `arcan doesn't find system-binaries`
trap "popd" EXIT # let's not leave the user stranded, though
./arcan \
-T ../share/arcan/scripts \
-p ../share/arcan/resources \
-t $Appls $@ $Appl
# A minimal configuration.nix containing just Arcan.
{pkgs,...}:{
environment.systemPackages = let
arcan = (pkgs.callPackage (import ./Arcan.nix) {});
in [
arcan.arcan
arcan.acfgfs
arcan.aloadimage
arcan.aclip
arcan.shmmon
arcan.prio
arcan.durden
];
users.groups.input.members = ["user"];
}
@bhankas
Copy link

bhankas commented May 1, 2021

Hi, I imported the files as instructed, and tried to 'nixos-rebuild boot', but got error while building shmmon. Here's the relevant part:

building '/nix/store/8yxkrxpz6r83a137s9sqcwin388rq73n-arcan.drv'...
building '/nix/store/hzl94rdqb18h3n2p3bhxlk3cdi59ig3k-acfgfs.drv'...
building '/nix/store/x2z3lc8cl4snj68yiklmx503v8mln3n5-aclip.drv'...
building '/nix/store/msglyd496x1chf3cdb4532444m7y7pqk-aloadimage.drv'...
building '/nix/store/5sb8bn9pcmg1hmbzz65saxjkxig9cjd3-arcan_fish-completions.drv'...
building '/nix/store/v61i8w0i1z5a5r02lgcpw1r2hpa96rsm-durden.drv'...
building '/nix/store/v8v3pbdvp19w8z8k1ajbxdzrv4g94ddh-shmmon.drv'...
error: builder for '/nix/store/hzl94rdqb18h3n2p3bhxlk3cdi59ig3k-acfgfs.drv' failed with exit code 1;
       last 10 log lines:
       > CMake Error at /nix/store/jhywvw19lcgwgshqycfh44bz8izdr73p-cmake-3.19.7/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
       >   Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
       > Call Stack (most recent call first):
       >   /nix/store/jhywvw19lcgwgshqycfh44bz8izdr73p-cmake-3.19.7/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
       >   /build/source/src/platform/cmake/modules/FindPkgConfig.cmake:41 (find_package_handle_standard_args)
       >   CMakeLists.txt:9 (find_package)
       >
       >
       > -- Configuring incomplete, errors occurred!
       > See also "/build/source/build/CMakeFiles/CMakeOutput.log".
       For full logs, run 'nix log /nix/store/hzl94rdqb18h3n2p3bhxlk3cdi59ig3k-acfgfs.drv'.
error: 1 dependencies of derivation '/nix/store/9vlfpb2s1mf85i3xjzzyv6116m5bssmh-acfgfs_fish-completions.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-durden.drv-0/source/durden': Directory not empty
error (ignored): error: cannot unlink '/tmp/nix-build-aloadimage.drv-0/source': Directory not empty
error: 1 dependencies of derivation '/nix/store/rrn958spzx1f2sawnz6z5nja2vz3rfj6-man-paths.drv' failed to build
error: 1 dependencies of derivation '/nix/store/hgrcxky0ncwhxrwhc69qdpsrj6i60wvp-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/i2p0fgl3pkl08lvb1jljhqgvck5hsb4s-nixos-system-enterprise-21.05.20210426.8e4fe32.drv' failed to build

@bhankas
Copy link

bhankas commented May 1, 2021

I added pkg-config in nativeBuildInputs for acfgfs and then build went smooth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment