NixOps cross system x86_64 to rpi

Hi, I’m getting the following error when deploying the nixos configuration with nixops

$nixops deploy -d my-infra --test
... 
homeGW.> Perl script erroneously interpreted as shell script,
homeGW.> does target platform match nixpkgs.crossSystem platform?
homeGW.> error: Traceback (most recent call last):
  File "/nix/store/2zbgdnv1aj72397qigridfslkv9qyz3w-python3-3.9.13-env/lib/python3.9/site-packages/nixops/deployment.py", line 893, in worker
    raise Exception(
Exception: unable to activate new configuration (exit code 1)

My build platform is ubuntu x86_64 and the host platform is rpi4 aarch64-unknown-linux-gnu, so I understand, that I must use cross-compilation, but I’m not sure if I’m defining it right

Definition of flake.nix:

  description = "Flake to manage my local infrastructure";  
  outputs = { self, nixpkgs, ... }:
    let
      pkgsFor = system: import nixpkgs {
        inherit system;
      };

    in {
      nixopsConfigurations.default = {
        inherit nixpkgs;
        network.storage.legacy.databasefile = "./.nixops/deployments.nixops";
        network.description = "Non-root deployment";
       
        homeGW = import ./home-gw/configuration.nix;
      };
    };
}

./home-gw/configuration.nix then looks like:

{ config, ... }:

let
  pkgs = import <nixpkgs> { crossSystem = { config = "aarch64-unknown-linux-gnu"; system = "aarch64-linux"; }; };
in {
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./users.nix
    ];

  nix.settings.trusted-users = [ "testuser" ];
  deployment.targetHost = "192.168.0.157";
  deployment.targetUser = "testuser";
  ...
}

Using nixops version NixOps 2.0.0-pre-7220cbd

I’ve had better experiences using binfmt + qemu-user on my build system to fake being a native aarch64. It’s slow, but you avoid the cross-compiling minefield, and you can take advantage of the binary cache.

It’s simple with nixos. Add this to your build system’s config:

{
  boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
}

then just build flake outputs that are for aarch64.

1 Like