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

Check target architecture before deploying #168

Open
piegamesde opened this issue Sep 4, 2021 · 5 comments
Open

Check target architecture before deploying #168

piegamesde opened this issue Sep 4, 2021 · 5 comments
Labels
help wanted PR very welcome! triaged Discussed in-team, actionable

Comments

@piegamesde
Copy link

piegamesde commented Sep 4, 2021

Continuation of #64 because I just ran into this again. Error message:

Executing 'switch' on matched hosts:

** raspberry
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 3: use: command not found
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 4: use: command not found
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 5: use: command not found
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 6: use: command not found
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 7: use: command not found
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 8: syntax error near unexpected token `('
/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git/bin/switch-to-configuration: line 8: `use Sys::Syslog qw(:standard :macros);'
Error while activating new configuration.

The script in question:

#! /nix/store/ylsbl86156l99zl8vwcbjzlsdzfgw3l2-perl-5.32.1-env/bin/perl

use strict;
use warnings;
use File::Basename;
use File::Slurp;
use Net::DBus;
use Sys::Syslog qw(:standard :macros);
use Cwd 'abs_path';

my $out = "/nix/store/z6jmxkblhhvrl60ajg61lj489bvg2fmf-nixos-system-amethyst-21.05pre-git";

# FIXME: maybe we should use /proc/1/exe to get the current systemd.
my $curSystemd = abs_path("/run/current-system/sw/bin");
…

The machine is a Raspberry Pi 4 (Linux 5.10.61 #1-NixOS SMP aarch64 GNU/Linux)

@piegamesde
Copy link
Author

So the root cause remains: the perl from the activation script's shebang is compiled for x86_64 Linux, although the hardware is aarch64. Executing the activation script manually gives me zsh: exec format error instead, which makes a lot more sense. However, when executing from a bash I get the stupid error message again. WTF?

@piegamesde piegamesde changed the title switch-to-configuration: line 3: use: command not found [take 2] Check target architecture before deploying Sep 11, 2021
@piegamesde
Copy link
Author

So I found the root cause for the issue: morph does not check for whether the architecture for which the configuration was built is correct. The configuration will then contain a shebang to a wrong binary, which will lead to failure. A preliminary check would catch this gracefully.


To the error message, this is a bug in Bash (actually, they say it's not because it's specified in POSIX, so one could call it a bug in POSIX): If the execution of a shebang fails, Bash will try to interpret the file directly. Of course this makes no sense, and since our file is a perl script we thus get the use: command not found error message.

@pinkisemils
Copy link

Do you have any good tips for recovering a host that has been morphed with the wrong architecture?
switch-to-configuration is now borked on an x86 host after I mistakenly pushed an aarch64 config, so the zstd on it is not executable.

@piegamesde
Copy link
Author

No, I was fortunate enough that the activation script was in Perl and thus failed before it could do any harm. You may try executing the activation script in emulation mode (with binfmt), but I can't guarantee this will work or even is a good idea. Personally, I'd try to manually force it some new configuration and then morph deploy it over.

@pinkisemils
Copy link

I copied over the activation script from a previous generation and that made it happy to deploy again.

@srhb srhb added help wanted PR very welcome! triaged Discussed in-team, actionable labels Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted PR very welcome! triaged Discussed in-team, actionable
Projects
None yet
Development

No branches or pull requests

3 participants