Issue with nixos system build

When trying to make nixos system image I get strange error while building system tarball:

[root@nixos:~/img]# NIXPKGS_ALLOW_UNFREE=1 NIXOS_CONFIG=$(pwd)/configuration.nix nix-build image.nix
these 5 derivations will be built:
  /nix/store/67iy6x3zy47lx2zpisssvvyglrajdnfi-closure-info.drv
  /nix/store/nadm07c5fiqd6sybmd05i12r4ywr6ssj-ext4-fs.img-aarch64-unknown-linux-gnu.drv
  /nix/store/pp7184pv0wq4hs3manf90dvadcd0cbaw-closure-info-aarch64-unknown-linux-gnu.drv
  /nix/store/qrzxg0prxd41nwnw6vqadxfgifsss4nx-tarball-aarch64-unknown-linux-gnu.drv
  /nix/store/5cic0q993kp8zj1c3gpmn910677j6a0l-image-aarch64-unknown-linux-gnu-0.0.1.drv
**error:** path ' **/nix/store/zbvvcjpwijz4dcy9g19mh6mdchd3i3xk-nixos-system-nixos-22.05pre357597.607178a179d/init** ' is not in the Nix store

What does it mean?

Can you also share image.nix and all the dependencies? Or at least some minified version that still produces the error?

1 Like

Yes, of course. Here is the minimal configuration.nix to reproduce error:

{config, pkgs, modulesPath, ...}:
{
  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;
  fileSystems = {
    "/" = {
      device = "/dev/disk/by-partlabel/rootfs";
      fsType = "ext4";
    };
  };
  system.build = {
    tarball = pkgs.callPackage <nixpkgs/nixos/lib/make-system-tarball.nix> {
      storeContents = [
        {
          symlink = "/bin/init";
          object = "${config.system.build.toplevel}/init";
        }
      ];
      contents = [];
      compressCommand = "cat";
      compressionExtension = "";
    };
  };
}

you can reproduce issue running nix-build '<nixpkgs/nixos>' -A config.system.build.tarball -I nixos-config=./configuration.nix. My nixpkgs’s svn-revision is 357597.607178a179d.

@tanshihaj I’m running into the same error. Did you ever figure this out?

I ended up doing something a little different, which works:

system.build.tarball = pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
  storeContents = [
    {
      object = config.system.build.toplevel;
      symlink = "/run/current-system";
    }
  ];
  extraCommands = pkgs.writeScript "extra-commands.sh" ''
    mkdir -p boot dev etc proc sbin sys
    ln -s ${config.system.build.toplevel}/init sbin/init
  '';
  contents = [];

  compressCommand = "gzip";
  compressionExtension = ".gz";
  extraInputs = [ pkgs.gzip ];
};