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

A single bad generation prevents systemd-boot-builder.py from building later generations #93694

Open
colemickens opened this issue Jul 23, 2020 · 9 comments
Labels
0.kind: bug Something is broken 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS

Comments

@colemickens
Copy link
Member

Describe the bug

If you have a "bad generation" for certain reason, it can break your ability to fix by switching to a new generation.

To Reproduce
Steps to reproduce the behavior:

  1. Accidentally set as the system profile, and then run a switch-to-configuration switch on a system build that is meant for an aarch64.
  2. Fix this.
  3. Try to activate a proper new generation.

Expected behavior
It works. And systemd-boot-builder.py skips any generations that are bad.

Additional context
The problem basically came down to initrd-append-secrets failing as bad of the 'bad generation' as systemd-boot-builder.py iterates over all system generations to build the boot entries.

I would suggest that maybe systemd-boot-builder.py should emit warnings but ultimately continue on failures such as failing to run initrd-append-secrets.

@colemickens colemickens added the 0.kind: bug Something is broken label Jul 23, 2020
@colemickens
Copy link
Member Author

In my case, this was the exact issue:

raceback (most recent call last):
  File "/nix/store/nw6hfg5y5q9lbciq36awbhyigww0p0kx-systemd-boot-builder.py", line 256, in <module>
    main()
  File "/nix/store/nw6hfg5y5q9lbciq36awbhyigww0p0kx-systemd-boot-builder.py", line 225, in main
    write_entry(*gen, machine_id)
  File "/nix/store/nw6hfg5y5q9lbciq36awbhyigww0p0kx-systemd-boot-builder.py", line 95, in write_entry
    subprocess.check_call([append_initrd_secrets, "/boot%s" % (initrd)])
  File "/nix/store/7q4crsd8kvmma32ff2xw4w9ydj5k26cy-python3-3.8.3/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/nix/store/7q4crsd8kvmma32ff2xw4w9ydj5k26cy-python3-3.8.3/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/nix/store/7q4crsd8kvmma32ff2xw4w9ydj5k26cy-python3-3.8.3/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/7q4crsd8kvmma32ff2xw4w9ydj5k26cy-python3-3.8.3/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/nix/store/0yjyqy39s4jflyiww0xcfqbp81x6h9lz-append-initrd-secrets/bin/append-initrd-secrets'

@flokli
Copy link
Contributor

flokli commented Jul 23, 2020

Yeah, some exception handling might need to be integrated in there.

@veprbl veprbl added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jul 24, 2020
@stale
Copy link

stale bot commented Jan 20, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 20, 2021
@colemickens
Copy link
Member Author

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 21, 2021
@stale
Copy link

stale bot commented Jul 20, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 20, 2021
@thiagokokada
Copy link
Contributor

Still valid: #144811 (comment)

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 6, 2021
@superherointj
Copy link
Contributor

I also had this issue.

Workaround I used:

To list generations:
nix-env -p /nix/var/nix/profiles/system --list-generations

To delete old generations:
nix-env -p /nix/var/nix/profiles/system --delete-generations old

Note: When using the live CD installer remember to update path with prefix of where your (not the live CD) system root partition was mounted. In my case, I had to add /mnt prefix because that is where I mounted my root partition.

@tejing1
Copy link
Contributor

tejing1 commented Dec 10, 2021

Just had to help another person get around this issue. It's a really ugly newbie trap.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/26

github-actions bot pushed a commit that referenced this issue Jan 8, 2022
The removed lines converted the flake path passed by the command line
from `/some/path` to `git+file:///some/path`.

This technically shouldn't cause any issues, however running
`nixos-rebuild switch` inside a directory `/nix/store` will cause the
switch to fail and leave a partially construct generation (see issue #144811
for details).

By itself this shouldn't be too much of an issue, however thanks to
another issue in `systemd-boot-builder.py` this can leave the system
in a broken state for those using `boot.loader.systemd-boot` (AFAIK the
default), where future `nixos-rebuild switch` will fail
(see issue #93694 for details).

The issue can be fixed by running
`nix-env -p /nix/var/nix/profiles/system --delete-generations old`,
however this makes newbies very confused and it is showing in our
support threads in Matrix and Discourse (see
https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842).

Keep in mind this is a workaround. The actual issue seems to be in nix
itself (see: NixOS/nix#5510).

See also #150065 for an alternative fix that caused other issues.

Kudos for @figsoda for figuring out this fix.

(cherry picked from commit c274d04)
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 10, 2022
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 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
Projects
None yet
Development

No branches or pull requests

7 participants