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

Example in docs/disko-images.md generates broken result script #900

Closed
RadxaYuntian opened this issue Nov 27, 2024 · 5 comments · Fixed by #907
Closed

Example in docs/disko-images.md generates broken result script #900

RadxaYuntian opened this issue Nov 27, 2024 · 5 comments · Fixed by #907
Labels
bug Something isn't working confirmed Issue has been confirmed/reproduced

Comments

@RadxaYuntian
Copy link

Step to reproduce

Running following script based on `docs/disko-images.md` example.
#!/usr/bin/env bash

set -euo pipefail

(
    rm -rf .git flake.lock flake.nix simple-efi.nix
)

cat << EOF > flake.nix
# save this as flake.nix
{
  description = "A disko images example";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    disko.url = "github:nix-community/disko/latest";
    disko.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, disko, nixpkgs }: {
    nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        # You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
        ./simple-efi.nix
        disko.nixosModules.disko
        ({ config, ... }: {
          # shut up state version warning
          system.stateVersion = config.system.nixos.version;
          # Adjust this to your liking.
          # WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
          disko.devices.disk.main.imageSize = "10G";
        })
      ];
    };
  };
}
EOF

wget https://github.com/nix-community/disko/raw/refs/heads/master/example/simple-efi.nix

git init
git add .

nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript
sudo ./result --build-memory 2048

Execution output

[excalibur@nixos:~/disko-test]$ ./test.sh 
--2024-11-27 09:56:55--  https://github.com/nix-community/disko/raw/refs/heads/master/example/simple-efi.nix
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/nix-community/disko/refs/heads/master/example/simple-efi.nix [following]
--2024-11-27 09:56:55--  https://raw.githubusercontent.com/nix-community/disko/refs/heads/master/example/simple-efi.nix
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8003::154, 2606:50c0:8000::154, 2606:50c0:8001::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8003::154|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8000::154|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8001::154|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8002::154|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 743 [text/plain]
Saving to: ‘simple-efi.nix’

simple-efi.nix                                           100%[================================================================================================================================>]     743  --.-KB/s    in 0s      

2024-11-27 09:56:55 (86.1 MB/s) - ‘simple-efi.nix’ saved [743/743]

Initialized empty Git repository in /home/excalibur/disko-test/.git/
warning: Git tree '/home/excalibur/disko-test' is dirty
warning: creating lock file '/home/excalibur/disko-test/flake.lock'
warning: Git tree '/home/excalibur/disko-test' is dirty
warning: error: unable to download 'https://mirrors.ustc.edu.cn/nix-channels/store/1zw7cxaz47bzhklwc5hdbxkxwh9plfd7.narinfo': Couldn't connect to server (7); retrying in 320 ms
[sudo] password for excalibur: 
/nix/store/skfbvi579f1wa30wa48c6qap28pswghn-vm-run: line 4: /setup: No such file or directory

[excalibur@nixos:~/disko-test]$ head /nix/store/skfbvi579f1wa30wa48c6qap28pswghn-vm-run
if [ -f "${NIX_ATTRS_SH_FILE-}" ]; then
  source "$NIX_ATTRS_SH_FILE"
fi
source $stdenv/setup
export > saved-env

PATH=/nix/store/k48bha2fjqzarg52picsdfwlqx75aqbb-coreutils-9.5/bin
mkdir xchg
mv saved-env xchg/

vm-run script is called here. Maybe the override caused some issues?

@RadxaYuntian
Copy link
Author

Seems to be caused by this commit.

Test the flake with nixpkgs.url = "github:NixOS/nixpkgs/26eba25577388072ba13b1682860fe872ba39942";: issue mentioned above.

Test the flake with ecdda28a3a3a5bfa4d2b761a390f8b6ca3bdd6b3 (the parent commit):

at 15:49:12 ❯ ./result
Formatting 'main.raw', fmt=raw size=10737418240
qemu-kvm: -virtfs local,path=/build,security_model=none,mount_tag=sa: cannot initialize fsdev 'sa': failed to open '/build': No such file or directory

Test the flake with 23e89b7da85c3640bbc2173fe04f4bd114342367 (a random commit I have on another project with working diskoImagesScript): appears to be fine.

@RadxaYuntian
Copy link
Author

Seems only affects diskoImagesScript. When I build for diskoImages VM can start.

@iFreilicht
Copy link
Contributor

Thank you for the detailed report! I was able to reproduce the issue, I'm looking into it now.

@iFreilicht iFreilicht added bug Something isn't working confirmed Issue has been confirmed/reproduced labels Nov 29, 2024
@iFreilicht
Copy link
Contributor

It seems this is actually caused by NixOS/nixpkgs#354535

I tried to fix this by making the build dir configurable in vmTools (see NixOS/nixpkgs@8812f20) and then overriding that setting in make-disk-image.nix.

This gets me further, but I end up with this:

EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path
loading kernel modules...
mounting Nix store...
mounting host's build directory...
starting stage 2 (/nix/store/6nz6pk6kf7w83lqq4a29h368f97vhyli-vm-run-stage2)
/nix/store/6nz6pk6kf7w83lqq4a29h368f97vhyli-vm-run-stage2: line 3: empty_build_dir/xchg/saved-env: No such file or directory
[    0.445652] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100
[    0.446310] CPU: 0 PID: 1 Comm: 6nz6pk6kf7w83lq Not tainted 6.6.63 #1-NixOS
[    0.446956] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS unknown 02/02/2022
[    0.447613] Call Trace:
[    0.447816]  <TASK>
[    0.447999]  dump_stack_lvl+0x47/0x70
[    0.448289]  panic+0x180/0x340
[    0.448561]  do_exit+0x956/0xad0
[    0.448851]  do_group_exit+0x31/0x80
[    0.449178]  __x64_sys_exit_group+0x18/0x20
[    0.449581]  do_syscall_64+0x39/0x90
[    0.449897]  entry_SYSCALL_64_after_hwframe+0x78/0xe2
[    0.450366] RIP: 0033:0x7f1f3ba5dd1d
[    0.450808] Code: 45 31 c0 45 31 d2 45 31 db c3 0f 1f 00 f3 0f 1e fa 48 8b 35 e5 e0 10 00 ba e7 00 00 00 eb 07 66 0f 1f 44 00 00 f4 89 d0 0f 05 <48> 3d 00 f0 ff ff 76 f3 f7 d8 64 89 06 eb ec 0f 1f 40 00 f3 0f 1e
[    0.452877] RSP: 002b:00007ffdd4a23238 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
[    0.453682] RAX: ffffffffffffffda RBX: 00007f1f3bb6dfa8 RCX: 00007f1f3ba5dd1d
[    0.454333] RDX: 00000000000000e7 RSI: ffffffffffffff88 RDI: 0000000000000001
[    0.455080] RBP: 0000000000000001 R08: 0000000000000000 R09: 0000000000000000
[    0.455843] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
[    0.456475] R13: 0000000000000001 R14: 00007f1f3bb6c680 R15: 00007f1f3bb6dfc0
[    0.457136]  </TASK>
[    0.457362] Kernel Offset: disabled
[    0.457676] Rebooting in 1 seconds..
Virtual machine didn't produce an exit code.

And frankly, I'm not sure how to continue at this point.

@iFreilicht
Copy link
Contributor

iFreilicht commented Nov 30, 2024

@RadxaYuntian please be aware that this will only be fixed once NixOS/nixpkgs#360413 is merged. However, we can't do anything else from our side now, so the issue being closed is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed Issue has been confirmed/reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants