1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 11:03:37 +03:00
mobile-nixos/modules/system-target.nix

40 lines
1.1 KiB
Nix

{ config, lib, pkgs, ... }:
# FIXME : current implementation only works for native x86_64 built hosts.
with lib;
let
cfg = config.mobile.system;
target_types = {
aarch64-linux = lib.systems.examples.aarch64-multiplatform;
x86_64-linux = { config = "x86_64-unknown-linux-gnu"; };
};
# Hmmm, this doesn't feel right, but it does work.
host_platform = (import <nixpkgs> {}).buildPackages.hostPlatform;
in
{
options.mobile = {
system.platform = mkOption {
type = types.enum (lib.attrNames target_types);
description = ''
Defines the kind of target architecture system the device is.
This will automagically setup cross-compilation where possible.
'';
};
};
config = {
assertions = [
{
assertion = pkgs.targetPlatform.system == cfg.platform;
message = "pkgs.targetPlatform.system expected to be `aarch64-linux`, is `${pkgs.targetPlatform.system}`";
}
];
nixpkgs.crossSystem = lib.mkIf ( target_types.${cfg.platform}.config != host_platform.config ) target_types.${cfg.platform};
};
}