From b681ad32540c5bcb93d3cb98dfd25f22f2eb5503 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 25 Jun 2021 18:08:56 +0200 Subject: [PATCH] buildFHSUserEnv: Allow having custom /opt in the FHS environment buildFHSUserEnv is meant primarily for running 3rd-party software which is difficult to patch for NixOS. Such software is often built to run from /opt. Currently, running such a software from FHS environment is difficult for two reasons: 1. If the 3rd-party software is put into the Nix store via a simple derivation (with e.g. installPhase = "dpkg-deb -x $src $out"), the content of /opt directory of that derivation does not appear in the FHSEnv even if the derivation is specified in targetPkgs. This is why we change env.nix. 2. If using buildFHSUserEnvChroot and the host system has the /opt directory, it always gets bind-mounted to the FHSEnv even if some targetPkgs contain /opt (NB buildFHSUserEnvBubblewrap does not have this problem). If that directory is not accessible for non-root users (which is what docker's containerd does with /opt :-(), the user running the FHSEnv cannot use it. With the change in chrootenv.c, /opt is not bind-mounted to the container, but instead created as user-modifiable symlink to /host/opt (see the init attribute in build-fhs-userenv/default.nix). If needed, the user can remove this symlink and create an empty /opt directory which is under his/her control. --- pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix | 2 +- pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c | 2 +- pkgs/build-support/build-fhs-userenv/env.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix index b9c719a4c78b..0051961d9f17 100644 --- a/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix +++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix @@ -156,7 +156,7 @@ let done cd .. - for i in var etc; do + for i in var etc opt; do if [ -d "${staticUsrProfileTarget}/$i" ]; then cp -rsHf "${staticUsrProfileTarget}/$i" "$i" fi diff --git a/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c b/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c index 27e70e3fe5c4..d8d87cd7dacf 100644 --- a/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c +++ b/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c @@ -18,7 +18,7 @@ if (expr) \ fail(#expr, errno); -const gchar *bind_blacklist[] = {"bin", "etc", "host", "real-host", "usr", "lib", "lib64", "lib32", "sbin", NULL}; +const gchar *bind_blacklist[] = {"bin", "etc", "host", "real-host", "usr", "lib", "lib64", "lib32", "sbin", "opt", NULL}; int pivot_root(const char *new_root, const char *put_old) { return syscall(SYS_pivot_root, new_root, put_old); diff --git a/pkgs/build-support/build-fhs-userenv/env.nix b/pkgs/build-support/build-fhs-userenv/env.nix index 226904f311b6..f24af87037f7 100644 --- a/pkgs/build-support/build-fhs-userenv/env.nix +++ b/pkgs/build-support/build-fhs-userenv/env.nix @@ -180,7 +180,7 @@ let done cd .. - for i in var etc; do + for i in var etc opt; do if [ -d "${staticUsrProfileTarget}/$i" ]; then cp -rsHf "${staticUsrProfileTarget}/$i" "$i" fi