moby: rework the cross-compiling situation

we build the `pkgs.cross` kernel, which can be emulated or
cross-compiled based on the specific target (`moby` v.s. `moby-cross`).
This commit is contained in:
colin 2022-08-11 17:02:41 -07:00
parent f052e2226d
commit c162225789
3 changed files with 29 additions and 43 deletions

View File

@ -25,14 +25,16 @@
patches = import ./nixpatches/list.nix nixpkgs.legacyPackages.${system}.fetchpatch;
};
# return something which behaves like `pkgs`, for the provided system
nixpkgsFor = system: import (patchedPkgs system) { inherit system; };
# `local` = architecture of builder. `target` = architecture of the system beying deployed to
nixpkgsFor = local: target: import (patchedPkgs target) { crossSystem = target; localSystem = local; };
# evaluate ONLY our overlay, for the provided system
customPackagesFor = system: import ./pkgs/overlay.nix (nixpkgsFor system) (nixpkgsFor system);
decl-machine = { name, system }:
customPackagesFor = local: target: import ./pkgs/overlay.nix (nixpkgsFor local target) (nixpkgsFor local target);
decl-machine = { name, local, target }:
let
nixosSystem = import ((patchedPkgs system) + "/nixos/lib/eval-config.nix");
nixosSystem = import ((patchedPkgs target) + "/nixos/lib/eval-config.nix");
in (nixosSystem {
inherit system;
# by default the local system is the same as the target, employing emulation when they differ
system = target;
specialArgs = { inherit nixpkgs mobile-nixos home-manager impermanence; };
modules = [
./modules
@ -46,13 +48,19 @@
nixpkgs.overlays = [
(import "${mobile-nixos}/overlay/overlay.nix")
(import ./pkgs/overlay.nix)
(next: prev: {
# non-emulated packages build *from* local *for* target.
# for large packages like the linux kernel which are expensive to build under emulation,
# the config can explicitly pull such packages from `pkgs.cross` to do more efficient cross-compilation.
cross = (nixpkgsFor local target) // (customPackagesFor local target);
})
];
}
];
});
decl-bootable-machine = { name, system }: rec {
nixosConfiguration = decl-machine { inherit name system; };
decl-bootable-machine = { name, local, target }: rec {
nixosConfiguration = decl-machine { inherit name local target; };
# this produces a EFI-bootable .img file (GPT with a /boot partition and a system (/ or /nix) partition).
# after building this:
# - flash it to a bootable medium (SD card, flash drive, HDD)
@ -68,16 +76,21 @@
# - `nixos-rebuild --flake './#<machine>' switch`
img = nixosConfiguration.config.system.build.img;
};
machines.servo = decl-bootable-machine { name = "servo"; system = "aarch64-linux"; };
machines.desko = decl-bootable-machine { name = "desko"; system = "x86_64-linux"; };
machines.lappy = decl-bootable-machine { name = "lappy"; system = "x86_64-linux"; };
machines.moby = decl-bootable-machine { name = "moby"; system = "aarch64-linux"; };
machines.rescue = decl-bootable-machine { name = "rescue"; system = "x86_64-linux"; };
machines.servo = decl-bootable-machine { name = "servo"; local = "aarch64-linux"; target = "aarch64-linux"; };
machines.desko = decl-bootable-machine { name = "desko"; local = "x86_64-linux"; target = "x86_64-linux"; };
machines.lappy = decl-bootable-machine { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; };
machines.moby = decl-bootable-machine { name = "moby"; local = "aarch64-linux"; target = "aarch64-linux"; };
# special cross-compiled variant, to speed up deploys from an x86 box to the arm target
# note that these *do* produce different store paths, because the closure for the tools used to cross compile
# v.s. emulate differ.
# so deploying moby-cross and then moby incurs some rebuilding.
machines.moby-cross = decl-bootable-machine { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; };
machines.rescue = decl-bootable-machine { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; };
in {
nixosConfigurations = builtins.mapAttrs (name: value: value.nixosConfiguration) machines;
imgs = builtins.mapAttrs (name: value: value.img) machines;
packages.x86_64-linux = customPackagesFor "x86_64-linux";
packages.aarch64-linux = customPackagesFor "aarch64-linux";
packages.x86_64-linux = customPackagesFor "x86_64-linux" "x86_64-linux";
packages.aarch64-linux = customPackagesFor "aarch64-linux" "aarch64-linux";
};
}

View File

@ -8,13 +8,6 @@
./fs.nix
./kernel.nix
];
# nixpkgs.overlays = [(next: prev: {
# # without this, kernel module build fails due to lacking dm_mod.
# # see: https://github.com/NixOS/nixpkgs/issues/126755#issuecomment-869149243
# # dm_mod appears to still be loaded, though? maybe some weird thing between compiled and dynamically-loaded mods?
# makeModulesClosure = x:
# prev.makeModulesClosure (x // { allowMissing = true; });
# })];
# XXX colin: phosh doesn't work well with passwordless login
users.users.colin.initialPassword = "147147";
services.getty.autologinUser = "root"; # allows for emergency maintenance?

View File

@ -114,27 +114,7 @@ in
# - phone rotation sensor is off by 90 degrees
# - ambient light sensor causes screen brightness to be shakey
# - phosh greeter may not appear after wake from sleep
# TODO: if i plumbed a nixpkgs cross with my overlay here,
# i could use `pkgs.linuxPackagesFor pkgs.linux-megous` instead.
boot.kernelPackages = let
nixpkgsCross = (import nixpkgs { localSystem = "x86_64-linux"; });
linux_5_18 = nixpkgsCross.pkgsCross.aarch64-multiplatform.linux_5_18;
in
pkgs.linuxPackagesFor (linux_5_18.override {
argsOverride = rec {
src = pkgs.fetchFromGitHub {
owner = "megous";
repo = "linux";
# branch: orange-pi-5.18
rev = "3ef835b665191e4833ae1363245be48e96013df6";
sha256 = "sha256-nQsBXeGLZhpem1p7Vnc8z7XB354AO1mn7VTj/hH5twY=";
};
version = "5.18.14";
modDirVersion = "5.18.14";
};
});
# non-cross compiled equivalent.
# boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux-megous;
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.cross.linux-megous;
boot.kernelPatches = [
(patchDefconfig (kernelConfig //
@ -149,7 +129,7 @@ in
))
];
# use nixos' kernel and add the stuff we want:
# alternatively, use nixos' kernel and add the stuff we want:
# # cross-compilation optimization:
# boot.kernelPackages =
# let p = (import nixpkgs { localSystem = "x86_64-linux"; });