about summary refs log tree commit diff
path: root/pkgs/games/build-support
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-10-03 15:27:24 +0200
committeraszlig <aszlig@redmoonstudios.org>2017-10-03 23:41:31 +0200
commitcf6a986d822fc99e4fde3b82dd8f03aca58482bc (patch)
tree84fd38721d5f7e89dd705cb276ec3619879a9cd3 /pkgs/games/build-support
parentc82d21271656400f5e87e0baf46e61224fe1aaa9 (diff)
pkgs/sandbox: Prepare for querying runtime paths
We're now using a makefile for building the sandbox and use pkg-config
to pass in the flags we need for compiling against lib(nix)store.

Right now the sandbox itself doesn't do anything different because we're
not actually using the (incomplete) code for querying the store.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/games/build-support')
-rw-r--r--pkgs/games/build-support/build-sandbox/default.nix25
-rw-r--r--pkgs/games/build-support/build-sandbox/src/Makefile17
-rw-r--r--pkgs/games/build-support/build-sandbox/src/get-closure.cc23
-rw-r--r--pkgs/games/build-support/build-sandbox/src/sandbox.c (renamed from pkgs/games/build-support/build-sandbox/sandbox.c)2
4 files changed, 49 insertions, 18 deletions
diff --git a/pkgs/games/build-support/build-sandbox/default.nix b/pkgs/games/build-support/build-sandbox/default.nix
index 2b45f3e5..3bb41093 100644
--- a/pkgs/games/build-support/build-sandbox/default.nix
+++ b/pkgs/games/build-support/build-sandbox/default.nix
@@ -1,17 +1,17 @@
-{ stdenv, lib }:
+{ stdenv, lib, pkgconfig, nix }:
 
 drv: { extraSandboxPaths ? [], ... }@attrs:
 
 stdenv.mkDerivation ({
   name = "${drv.name}-sandboxed";
 
-  src = drv;
+  src = ./src;
 
-  phases = [ "buildPhase" "installPhase" ];
+  inherit drv;
 
   exportReferencesGraph = [ "sandbox-closure" drv ];
 
-  buildPhase = ''
+  configurePhase = ''
     runtimeDeps="$(sed -ne '
       p; n; n
 
@@ -28,7 +28,7 @@ stdenv.mkDerivation ({
       y/X/9/
       x; n; p; x
       bcdown
-    ' sandbox-closure | sort -u)"
+    ' ../sandbox-closure | sort -u)"
 
     echo 'static bool setup_app_paths(void) {' > params.c
 
@@ -45,17 +45,8 @@ stdenv.mkDerivation ({
     cat params.c
   '';
 
-  installPhase = ''
-    mkdir -p "$out/bin"
-    for bin in "$src"/bin/*; do
-      progname="$(basename "$bin")"
-      gcc -g -std=gnu11 -Wall \
-        -DWRAPPED_PATH=\""$bin"\" \
-        -DWRAPPED_PROGNAME=\""$progname"\" \
-        -DPARAMS_FILE=\""$(pwd)/params.c"\" \
-        -DFS_ROOT_DIR=\""$out"\" \
-        -o "$out/bin/$progname" ${./sandbox.c}
-    done
-  '';
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ nix ];
+  makeFlags = [ "BINDIR=${drv}/bin" ];
 
 } // removeAttrs attrs [ "extraSandboxPaths" ])
diff --git a/pkgs/games/build-support/build-sandbox/src/Makefile b/pkgs/games/build-support/build-sandbox/src/Makefile
new file mode 100644
index 00000000..57c732af
--- /dev/null
+++ b/pkgs/games/build-support/build-sandbox/src/Makefile
@@ -0,0 +1,17 @@
+BINARIES = $(wildcard $(BINDIR)/*)
+WRAPPERS = $(subst $(BINDIR),$(out)/bin,$(BINARIES))
+
+CFLAGS = -Wall -std=gnu11 -DFS_ROOT_DIR=\"$(out)\"
+CXXFLAGS = -Wall -std=c++14 `pkg-config --cflags nix-main`
+LDFLAGS = `pkg-config --libs nix-main`
+
+all: get-closure.o
+
+$(out)/bin/%: CFLAGS += -DWRAPPED_PROGNAME=\"$(@F)\"
+$(out)/bin/%: CFLAGS += -DWRAPPED_PATH=\"$(BINDIR)/$(@F)\"
+$(out)/bin/%: get-closure.o
+	mkdir -p $(out)/bin
+	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $? sandbox.c
+
+.PHONY: install
+install: $(WRAPPERS)
diff --git a/pkgs/games/build-support/build-sandbox/src/get-closure.cc b/pkgs/games/build-support/build-sandbox/src/get-closure.cc
new file mode 100644
index 00000000..11330a9c
--- /dev/null
+++ b/pkgs/games/build-support/build-sandbox/src/get-closure.cc
@@ -0,0 +1,23 @@
+#include <nix/util.hh>
+#include <nix/local-store.hh>
+#include <nix/store-api.hh>
+#include <nix/misc.hh>
+
+using namespace nix;
+
+int get_closure(const char *path)
+{
+    Path query(path);
+    PathSet paths;
+    auto store = openStore(false);
+
+    computeFSClosure(
+        *store, followLinksToStorePath(query), paths, false, true
+    );
+
+    for (auto i = paths.begin(); i != paths.end(); ++i) {
+        // TODO!
+    }
+
+    return 1;
+}
diff --git a/pkgs/games/build-support/build-sandbox/sandbox.c b/pkgs/games/build-support/build-sandbox/src/sandbox.c
index 9df02296..dd0fe845 100644
--- a/pkgs/games/build-support/build-sandbox/sandbox.c
+++ b/pkgs/games/build-support/build-sandbox/src/sandbox.c
@@ -479,7 +479,7 @@ static bool setup_xauthority(void)
     return result;
 }
 
-#include PARAMS_FILE
+#include "params.c"
 
 static bool setup_chroot(void)
 {