diff options
Diffstat (limited to 'pkgs/games/build-support/build-sandbox')
-rw-r--r-- | pkgs/games/build-support/build-sandbox/default.nix | 25 | ||||
-rw-r--r-- | pkgs/games/build-support/build-sandbox/src/Makefile | 17 | ||||
-rw-r--r-- | pkgs/games/build-support/build-sandbox/src/get-closure.cc | 23 | ||||
-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) { |