Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-rebuild boot fails when xorg-server build script tries to open directories under /var/tmp #19673

Closed
peterhoeg opened this issue Oct 19, 2016 · 29 comments
Assignees
Labels
0.kind: bug Something is broken

Comments

@peterhoeg
Copy link
Member

Issue description

nixos-rebuild boot fails to run due to this:

  1. systemd will create directories under /var/tmp which no user has access to for services with PrivateTmp=true set.
  2. https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/x11/xorg/overrides.nix#L462 replaces the "compiled" directory for the xorg-server package with a link to /var/tmp.
  3. the build script will try to descend into sub directories and fail due to 1.

This is the error:

cannot open `/nix/store/gv307dkp3r5hzj6jmqq2nxlsj2l31i90-xorg-server-1.18.3/share/X11/xkb/compiled/systemd-private-fc254f6d36da46a69c448c429d105be3-firefox@default.service-CgnwMR':
Permission denied at /nix/store/9g4wc31j7a2xp22xpgwr0qssfxahxdzl-builder.pl line 58.

If x/xkb needs to dynamically compile keymaps (I'm guessing that is what that $out/share/X11/xkb/compiled directory is for), shouldn't we instead give it its own directory under
/var/lib/xkb or similar instead?

Cc: @groxxda

Technical details

  • NixOS: 17.03.git.014efa9M (Gorilla)
  • Nix: nix-env (Nix) 1.11.4
  • nixpkgs: 17.03.git.e09f343M
@peterhoeg peterhoeg changed the title nixos-rebuild boot fails when xorg-server build script is trying to open directories under /var/tmp nixos-rebuild boot fails when xorg-server build script tries to open directories under /var/tmp Oct 19, 2016
@NeQuissimus NeQuissimus added the 0.kind: bug Something is broken label Oct 19, 2016
@groxxda
Copy link
Contributor

groxxda commented Oct 19, 2016

Maybe relevant for #19629

@peterhoeg can you please confirm my assumptions

  • this only happens without sandboxing
  • you have no special settings for the xkb stuff

I'm not convinced this is a xkb specific problem, it may as well be a bug in builder.pl.
At least the path that it tries to access looks very suspicious..

@peterhoeg
Copy link
Member Author

@groxxda

  1. it happens with and without useSandbox = true;
  2. it happens with and without setting xkbOptions

@groxxda
Copy link
Contributor

groxxda commented Oct 19, 2016

@peterhoeg any idea why this failure does not show up on hydra?

@dezgeg
Copy link
Contributor

dezgeg commented Oct 19, 2016

Probably it happens only when systemPackages (or maybe something else that is being buildEnv'd) contains more than one package having a share/X11/xkb directory.

@dezgeg
Copy link
Contributor

dezgeg commented Oct 19, 2016

I wonder if that symlink is needed anymore? Such directory doesn't exist on my Arch Linux installation for instance (edit: nvm, they just override the location to /var/lib/xkb). The code which added that is pretty old: 9d15693

@peterhoeg
Copy link
Member Author

Now this is getting odd.

  1. Everything was working for the longest time.
  2. { nix.useSandbox = true; } all along except for
  3. I started making some changes to the KDE packages, which caused massive rebuilds. I disabled useSandbox in the hope that I could speed up the compilation (that basically the previously compiled stuff wouldn't be thrown away every time)
  4. My machine was now booted with a generation that was built with useSandbox disabled.

And this is where the problems started.

Checking /etc/nix/nix.conf it would show that useSandbox was disabled, but trying to build with (and without) useSandbox enabled would give the error I mentioned.

Stupid me had run nix-collect-garbage -d earlier as the drive was getting VERY full.

So in under to work around it, I did mount -o remount,rw /nix/store and edited /etc/nix/nix.conf to enable useSandbox but keep in mind that in my configuration it was still enabled all along and after a reboot nixos-rebuild works again.

Why would /etc/nix/nix.conf override? Is it because nix-daemon was already started without useSandbox so that takes priority?

@dezgeg
Copy link
Contributor

dezgeg commented Oct 20, 2016

Why would /etc/nix/nix.conf override? Is it because nix-daemon was already started without useSandbox so that takes priority?

Yes, if you modify nix.conf you generally need to restart nix-daemon.

BTW, a safer way to do that is to NOT remount /nix/store rw but instead, make /etc/nix/nix.conf not a symlink but a normal file.

@peterhoeg
Copy link
Member Author

Let's say I boot the machine using a generation built with useSandbox = false.

If I then enable useSandbox, I would imagine that the new generation is built in a sandbox as I would otherwise have to do it twice because my first round would not be. Then when rebooting nix.conf would tell me that useSandbox is true but it wasn't true when the generation was built.

@joelmo
Copy link
Contributor

joelmo commented Oct 26, 2016

I have the same problem. Everything under /var/tmp gets copied to /nix/store/...-xorg-server-1.18.4/share/X11/xkb/compiled.

Maybe it can be fixed by being more specific here: https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/x11/xorg/overrides.nix#L462

Say ln -s /var/tmp/systemd-private-* $out...?

@peterhoeg
Copy link
Member Author

@joelmo, does it work with nix.useSandbox = true;?

@groxxda, any thoughts on using /var/lib/xkb or similar?

@stapelberg
Copy link
Contributor

I ran into the same problem. Setting nix.useSandbox = true fixes the problem for me.

@vcunat
Copy link
Member

vcunat commented Oct 29, 2016

@joelmo: does it really get copied for you? I see only a symlink in the code.

@joelmo
Copy link
Contributor

joelmo commented Oct 30, 2016

Sorry /nix/store/...-xorg-server-1.18.4/share/X11/xkb/compiled is a symlink. I haven't tried useSandbox but that would probably solve my problem.

@dezgeg
Copy link
Contributor

dezgeg commented Nov 7, 2016

I think we can just do this:

diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix
index 930132b..60a7354 100644
--- a/pkgs/servers/x11/xorg/overrides.nix
+++ b/pkgs/servers/x11/xorg/overrides.nix
@@ -509,7 +509,6 @@ in
         '';
         postInstall = ''
           rm -fr $out/share/X11/xkb/compiled
-          ln -s /var/tmp $out/share/X11/xkb/compiled

           cp -rT ${darwinOtherX}/bin $out/bin
           rm -f $out/bin/X

That should just fall back to /tmp/ as per the code:

 48         /*
 49          * If XKM_OUTPUT_DIR specifies a path without a leading slash, it is
 50          * relative to the top-level XKB configuration directory.
 51          * Making the server write to a subdirectory of that directory
 52          * requires some work in the general case (install procedure
 53          * has to create links to /var or somesuch on many machines),
 54          * so we just compile into /usr/tmp for now.
 55          */
 56 #ifndef XKM_OUTPUT_DIR
 57 #define XKM_OUTPUT_DIR  "compiled/"
 58 #endif
 59 
...
 73 
 74 static void
 75 OutputDirectory(char *outdir, size_t size)
 76 {
 77 #ifndef WIN32
 78     /* Can we write an xkm and then open it too? */
 79     if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0 &&
 80         (strlen(XKM_OUTPUT_DIR) < size)) {
 81         (void) strcpy(outdir, XKM_OUTPUT_DIR);
 82     }
 83     else
 84 #else
 85     if (strlen(Win32TempDir()) + 1 < size) {
 86         (void) strcpy(outdir, Win32TempDir());
 87         (void) strcat(outdir, "\\");
 88     }
 89     else
 90 #endif
 91     if (strlen("/tmp/") < size) {
 92         (void) strcpy(outdir, "/tmp/");
 93     }
 94 }

Or would an explicit patch to that function be better?

(Arguably though, buildEnv should be fixed to not follow non-store symlinks.)

@vcunat
Copy link
Member

vcunat commented Nov 7, 2016

Sounds OK to me.

@sorpaas
Copy link
Member

sorpaas commented Nov 13, 2016

Still the same error after applying patch from @dezgeg. Running 16.09. Any suggestions?

@joelmo
Copy link
Contributor

joelmo commented Nov 13, 2016

Do someone know what functionality ln -s /var/tmp $out/share/X11/xkb/compiled have? I can remove that and don't notice anything different, running kde5.

@sorpaas
Copy link
Member

sorpaas commented Nov 13, 2016

Just fixed the problem (http://git.that.world/nixpkgs.git/commit/?h=infra&id=02d2655fb9e9c8220c761484f1b0c6861af376d3). Turns out there's 2 more ln-s to be removed.

@changlinli
Copy link
Contributor

@sorpaas It looks like your fix works for me

@luispedro
Copy link
Contributor

This is still failing for me. Does it need to be backported for 16.09?

@vcunat
Copy link
Member

vcunat commented Nov 21, 2016

@luispedro: I believe no fix has been pushed to the official repo yet.

@aszlig
Copy link
Member

aszlig commented Nov 29, 2016

Apart from the oddity that compiled is a symlink to /var/tmp and gets into the output path, I think we should also address this in buildEnv so that it doesn't try to dereference symlinks that are outside of the store.

@roxma
Copy link
Contributor

roxma commented Dec 3, 2016

Same problem here, I'm kind of scratching my head now.
Looks like useSandbox = true doesn't work for me.

@sheenobu
Copy link
Contributor

sheenobu commented Dec 3, 2016

@roxma I had to do useSandbox = true, then nixos-rebuild switch (without KDE or KDM enabled) , then check /etc/nix/nix.conf to ensure sandbox was enabled, then systemctl restart nix-daemon, finally you can enable KDE and re-run nixos-rebuild switch.

@roxma
Copy link
Contributor

roxma commented Dec 3, 2016

@sheenobu
Thanks, now It's working!

@joelmo
Copy link
Contributor

joelmo commented Dec 3, 2016

Another way to go around this error is to remove everything in /var/tmp.

@vcunat vcunat self-assigned this Dec 3, 2016
@vcunat vcunat closed this as completed in 33abc70 Dec 4, 2016
@ghost
Copy link

ghost commented Dec 4, 2016

@vcunat Will it go into nixos-16.09 branch of nixpkgs-channels? Thanks.

@vcunat
Copy link
Member

vcunat commented Dec 4, 2016

@gnidorah, I planned to wait a few days so it gets more testing.

vcunat added a commit that referenced this issue Dec 18, 2016
- Fixes #19673; it caused problems in combination with buildEnv.
- As noted, X falls back to /tmp:
  #19673 (comment)
- Removing the directory is still required, as X would attempt to write
  into it if allowed - and probably succeed in case the user set
  nix.readOnlyStore = false; (X runs as root).
- Archeology link: 9d15693.

(cherry picked from commit 33abc70)
@vcunat
Copy link
Member

vcunat commented Dec 18, 2016

Picked to 16.09. It's a bit later than I anticipated, and moreover channels are stalled due to Hydra's current setup.

adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
- Fixes NixOS#19673; it caused problems in combination with buildEnv.
- As noted, X falls back to /tmp:
  NixOS#19673 (comment)
- Removing the directory is still required, as X would attempt to write
  into it if allowed - and probably succeed in case the user set
  nix.readOnlyStore = false; (X runs as root).
- Archeology link: 9d15693.

(cherry picked from commit 33abc70)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests