about summary refs log tree commit diff
path: root/pkgs/games/build-support/build-game.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-09-27 19:58:21 +0200
committeraszlig <aszlig@redmoonstudios.org>2017-10-03 23:41:20 +0200
commit2554e3ce9096c7036cbea55d78828794085734af (patch)
treeadc363f46193c1ab3368325d900525e23d6918b9 /pkgs/games/build-support/build-game.nix
parent673cf2b1b38fb9a6fc4a5b01716feda7d3b861e4 (diff)
pkgs/build-game: Add preliminary sandbox hook
This is basically to make sure various games can't write to whatever
they want in the file system, so it's not a complete sandboxing
solution.

Currently there's a drawback in that we can't easily determine the
runtime dependencies while building a particular game, so we need to
recursively dig through all referenced store paths to look them up.

A better solution for this would be to gather the build time reference
graph prior to building so that we can limit searching for these
references within only the actual build outputs instead of churning
through all inputs.

In addition to that, we currently mount the namespaced root file system
on top of /tmp, which makes the real /tmp unavailable to us. While in
theory this shouldn't be a problem, it actually turns out it is indeed a
problem if the application wants to connect to the X server socket,
which is at something like /tmp/.X11-unix/X0 for display :0.

Apart from these drawbacks we have a working solution for simple
applications (not games, because they usually require X), which now get
its own chroot with only the paths accessible that are strictly
necessary.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/games/build-support/build-game.nix')
-rw-r--r--pkgs/games/build-support/build-game.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/pkgs/games/build-support/build-game.nix b/pkgs/games/build-support/build-game.nix
index b64f7457..e402787c 100644
--- a/pkgs/games/build-support/build-game.nix
+++ b/pkgs/games/build-support/build-game.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, file, unzip
+{ stdenv, lib, file, unzip, gcc, makeSetupHook
 
 , withPulseAudio ? true, libpulseaudio ? null
 , alsaLib
@@ -12,10 +12,19 @@ assert withPulseAudio -> libpulseaudio != null;
 , setSourceRoot ? ""
 , installCheckPhase ? ""
 , runtimeDependencies ? []
+, extraSandboxPaths ? [ "$XDG_DATA_HOME" "$XDG_CONFIG_HOME" ]
 , ...
 }@attrs:
 
-stdenv.mkDerivation ({
+let
+  sandboxHook = makeSetupHook {
+    substitutions = {
+      inherit gcc;
+      sandbox_main = ./sandbox.c;
+    };
+  } ./setup-hooks/make-sandbox.sh;
+
+in stdenv.mkDerivation ({
   buildInputs = [ stdenv.cc.cc ] ++ buildInputs;
 
   nativeBuildInputs = [
@@ -39,6 +48,11 @@ stdenv.mkDerivation ({
     fi
   '';
 
+  # Use ":!*!:" as delimiter as we can consider this highly unlikely to
+  # be part of a real path component and we're out of Nix territory, so
+  # the path components could contain almost anything.
+  extraSandboxPaths = lib.concatStringsSep ":!*!:" extraSandboxPaths;
+
   runtimeDependencies = let
     deps = lib.singleton alsaLib
         ++ lib.optional withPulseAudio libpulseaudio
@@ -71,5 +85,5 @@ stdenv.mkDerivation ({
   dontPatchELF = true;
 } // removeAttrs attrs [
   "buildInputs" "nativeBuildInputs" "preUnpack" "setSourceRoot"
-  "installCheckPhase" "runtimeDependencies"
+  "installCheckPhase" "runtimeDependencies" "extraSandboxPaths"
 ])