about summary refs log tree commit diff
path: root/pkgs/build-support/build-sandbox/src
Commit message (Collapse)AuthorAgeFilesLines
* sandbox: Fix linking against libnixmainaszlig2019-01-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since add_DT_NEEDED_for_dynamic is no longer the default for ld[1], we'll get a linking error like this: nix-query.o: undefined reference to symbol '_ZNK3nix5Store22followLinksToStorePathERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE' Unfortunately, the only way to work around this without re-enabling the same flag is directly specify dependencies we really *should* not need to specify because they're a transient dependency of libnixmain. So for now I'm reverting back to the previous behaviour with --copy-dt-needed-entries until I got time to look into it in detail. From the ld(1) manual page: --copy-dt-needed-entries --no-copy-dt-needed-entries This option affects the treatment of dynamic libraries referred to by DT_NEEDED tags inside ELF dynamic libraries mentioned on the command line. Normally the linker will add a DT_NEEDED tag to the output binary for each library mentioned in a DT_NEEDED tag in an input dynamic library. With --no-copy-dt-needed-entries specified on the command line however any dynamic libraries that follow it will have their DT_NEEDED entries ignored. The default behaviour can be restored with --copy-dt-needed-entries. This option also has an effect on the resolution of symbols in dynamic libraries. With the default setting dynamic libraries mentioned on the command line will be recursively searched, following their DT_NEEDED tags to other libraries, in order to resolve symbols required by the output binary. With --no-copy-dt-needed-entries specified however the searching of dynamic libraries that follow it will stop with the dynamic library itself. No DT_NEEDED links will be traversed to resolve symbols. [1]: https://github.com/NixOS/nixpkgs/commit/bcfe7af84b3628a31bfcc43dde30fc553a73adac Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Add UTS/PID/IPC namespacingaszlig2018-09-201-2/+21
| | | | | | | | | | | | | | | | | | | In order to isolate processes even further it's a good idea to not let them access information about other PIDs, eg. by enumerating /proc. However, this still bind-mounts /sys from the root namespace, so we might want to restrict /sys further. For our games however we will need /sys because it is used to enumerate gamepads and other input devices. Currently the processes will now be PID 1. I've tested this against a few games and none of them had problems with that so far, so let's keep it that way. Another thing we might want to add and which currently isn't there is a subreaper, which is useful if we have a process that leaves zombie processes around. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Support overlaying files at runtimeaszlig2018-07-221-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | | This introduces a new environment variable called NIX_SANDBOX_DEBUG_INJECT_FILES. The name is intentionally very long so that people hopefully *only* use it for debugging. What this does is to just bind-mount the given source file to a given destination file in the chroot. For example: NIX_SANDBOX_DEBUG_INJECT_FILES=/foo/bar=/bar/foo somethingSandboxed The file /foo/bar outside of the sandbox will be bind-mounted to /bar/foo within the sandbox. Several files can be separated via colon. Of course the most interesting use case here (and the reason for this feature) is that we can overlay files in the Nix store without the need to rebuild anything, so we can quickly patch specific files. In my case I'm using this so I can use radare2 to patch the assembly of some binaries quickly for debugging/reverse engineering. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Expose get_mount_target()aszlig2018-07-022-1/+2
| | | | | | | | I'm going to use the sandboxing implementation as the basis for something else where I'm going to do additional mounts on top of the existing ones. This is just to make it easier to find the mount target. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Fix mount flagsaszlig2018-07-021-9/+20
| | | | | | | | | | | | When using MS_BIND the mount flags aren't actually applied, so we need to remount the bind mount with the flags we wanted if additional flags are desired for the mount. I've also removed the MS_NOATIME, because this doesn't work for kernel 4.14 (returns -EPERM) and it's really not necessary to change the atime flags for our bind mounts. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Add flag to bind-mount read-onlyaszlig2018-07-022-11/+14
| | | | | | | | | | | | | | While the Nix store should be read-only by default, we can't guarantee this as the Nix store could be mounted read-write (for example on non-NixOS systems). For paths other than store directories, I took a conservative approach here where only /etc is mounted read-only, for all the pseudo- filesystems such as /proc, /sys or /dev write access might still be needed, for example to write to a hardware device exposed via /dev (eg. a gamepad with rumble support). Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Handle store paths that are symlinksaszlig2018-06-091-0/+63
| | | | | | | | | | | | | | | For example the store path of libGL-1.0.0 is a symlink pointing to libglvnd-1.0.0 right now on my machine. If we have such a symlink the sandbox would just silently skip it and only mount the *resolved* path instead of creating the symlink leading to the target. Now whenever bind_mount() with the resolve argument being true is used, we create all the symlinks leading to the target path determined by realpath(). Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/build-sandbox: Zero-pad minor Nix versionaszlig2018-02-021-1/+2
| | | | | | | | | | | In order to do integer comparisons on the Nix version, we need to zero-pad the minor version, so that we always have two digits. Since the change of Nix version 1.12 to 2.0 the minor version no longer has two digits, so we get 20 instead of 112 and when compared the former is smaller than the latter but it has to be the opposite. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Check for absolute path in makedirsaszlig2017-11-301-0/+5
| | | | | | | | Though we're already checking the realpath() let's actually make sure that the path begins with a slash, otherwise we'll run into a segfault later when we try to access the second byte of path. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Add handling for XDG_CACHE_HOMEaszlig2017-11-301-19/+15
| | | | | | | | | | | | We only handle XDG_DATA_HOME and XDG_CONFIG_HOME, but we've missed XDG_CACHE_HOME. While the latter is used very rarely as it doesn't matter a lot if it ends up within a tmpfs anyway. However if the cache directory gets pretty large we might run out of space. Not only do we now have proper fallbacks but this also adds tests for all of the XDG environment variables we're using. Signed-off-by: aszlig <aszlig@nix.build>
* pkgs/sandbox: Handle mounting of regular filesaszlig2017-11-301-33/+43
| | | | | | | | | | | | | | | While we already have support for mounting plain files, this is done on a very specific basis, mainly the .Xauthority file. Whenever we use bind_mount() and the file is a regular file, mounting that file will fail. So let's actually do a stat on the file and decide whether we want to do bind_file() or bind_mount(). I've stumbled on this because one of the store paths of the run time dependency graph was a plain file and thus the sandbox wrapper was unable to mount it. Signed-off-by: aszlig <aszlig@nix.build>
* build-sandbox: Move to top-level build-supportaszlig2017-11-309-0/+932
This is not only useful for packaging games, so let's make it available from the vuizvui scope, so we can use it from other packages as well. Signed-off-by: aszlig <aszlig@nix.build>