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

Building ISO takes excessive amounts of time+memory #57984

Closed
Slabity opened this issue Mar 20, 2019 · 7 comments · Fixed by #58246
Closed

Building ISO takes excessive amounts of time+memory #57984

Slabity opened this issue Mar 20, 2019 · 7 comments · Fixed by #58246

Comments

@Slabity
Copy link
Contributor

Slabity commented Mar 20, 2019

Issue description

When trying to build an ISO image, my system memory (~12GB) and swap space (~16GB) gets completely filled. The build seems to freeze on the following:

evaluating file '/nix/store/*/nixos/lib/systems/platform.nix'

Steps to reproduce

Using the following system configuration (file named iso.nix):

{config, pkgs, ...}:
{
  imports = [
    <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-graphical-gnome.nix>
    <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
  ];

  nixpkgs.overlays = [
    (self: super: { inherit (super.pkgsi686Linux) grub2_efi; })
  ];
}

Then run the following:

nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix

Technical details

  • system: "x86_64-linux"
  • host os: Linux 5.0.2, NixOS, 19.09pre173080.1222e289b50 (Loris)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.2

Appears to affect 19.03 channel as well.

@tilpner
Copy link
Member

tilpner commented Mar 20, 2019

This occurs here too. ulimit seems ineffective in preventing the freeze, but SysRq+F (may need SysRq+R too) is useful to invoke the OOM-killer manually.

I tested it against nixos-19.03, so it's not particular to nixos-unstable.

@matthewbauer
Copy link
Member

Can you try out 18.09 to see if this has been introduced recently?

@tilpner
Copy link
Member

tilpner commented Mar 20, 2019

  • Instantiation is sufficient to cause this
  • Instantiation of config.system.build.toplevel has the same effect as config.system.build.isoImage
  • It also happens with 18.09
  • The last line of -vv output differs:
    • nixos-19.03: evaluating file '/nix/store/4wngdg5ri4n6950smk3swgxgrzpshqhd-source/lib/systems/platforms.nix'
    • nixos-18.09: evaluating file '/nix/store/qv6wc1js0fqmjmvkn9qh8xxhx3f43wcm-source/pkgs/tools/filesystems/jfsutils/default.nix'

@Slabity
Copy link
Contributor Author

Slabity commented Mar 21, 2019

So I just tried this on an EC2 m5a.24xlarge instance to see if it would actually complete.

It maxed out all 371GB of memory and only used a single core. After about ~30 minutes it finally crashed from a stack overflow.

I should also note that the issue does not occur if the overlay line is removed from the configuration.

@matthewbauer
Copy link
Member

matthewbauer commented Mar 21, 2019

Ah ok! It's probably an issue in pkgsi686Linux.

@danbst
Copy link
Contributor

danbst commented Mar 25, 2019

This can be resolved with this simple patch:

diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index 0ee5c25b010..0ef7cd4341e 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -151,6 +151,9 @@ let
     # All packages built for i686 Linux.
     # Used by wine, firefox with debugging version of Flash, ...
     pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then nixpkgsFun {
+      overlays = [ (self': super': {
+        pkgsi686Linux = super';
+      })] ++ overlays;
       ${if stdenv.hostPlatform == stdenv.buildPlatform
         then "localSystem" else "crossSystem"} = {
         parsed = stdenv.hostPlatform.parsed // {

but I'd like to hear also @oxij's opinion, as he was last to touch this code.

danbst added a commit to danbst/nixpkgs that referenced this issue Mar 25, 2019
…lays

Consider example:

$ nix-instantiate ./nixos -A system --arg configuration '
    {
      boot.isContainer = true;
      nixpkgs.overlays = [ (self: super: {
        nix = self.pkgsStatic.nix;
      }) ];
    }'

When resolving package through overlays, we figure out that

  nix == self.pkgsStatic.nix
  =>
  nix == (import <nixpkgs> { inherit overlays; }).nix
  =>
  nix == (import <nixpkgs> { overlays = [(self: super: { nix = self.pkgsStatic.nix; })];}).nix

and we enter infinite recursion of nixpkgs evaluations.

The proper fix should terminate recursion by assigning self fixpoint
to inner custom package set. But I get infinite recursion somehow, so
I use `super`. It is less correct modulo deep custom overrides, but behaves
correctly for simple cases and doesn't OOM evaluator.

Fixes NixOS#57984
danbst added a commit that referenced this issue Mar 26, 2019
…lays

Consider example:

$ nix-instantiate ./nixos -A system --arg configuration '
    {
      boot.isContainer = true;
      nixpkgs.overlays = [ (self: super: {
        nix = self.pkgsStatic.nix;
      }) ];
    }'

When resolving package through overlays, we figure out that

  nix == self.pkgsStatic.nix
  =>
  nix == (import <nixpkgs> { inherit overlays; }).nix
  =>
  nix == (import <nixpkgs> { overlays = [(self: super: { nix = self.pkgsStatic.nix; })];}).nix

and we enter infinite recursion of nixpkgs evaluations.

The proper fix should terminate recursion by assigning self fixpoint
to inner custom package set. But I get infinite recursion somehow, so
I use `super`. It is less correct modulo deep custom overrides, but behaves
correctly for simple cases and doesn't OOM evaluator.

Fixes #57984
@danbst
Copy link
Contributor

danbst commented Mar 26, 2019

Hey @Slabity! The issue is fixed in nixpkgs master and 19.03, but if you need it on 18.09, there is workaround:

  nixpkgs.overlays = [
    (self: super: super.lib.optionalAttrs (super.system != "i686-linux")  
       { inherit (super.pkgsi686Linux) grub2_efi; })
  ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants