mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-27 01:44:41 +03:00
system-target: reviews implementation
Since the initial implementation I learned enough to know where it was slighly wrong. I think this fixes most of the slight wrongness.
This commit is contained in:
parent
3c1408c82d
commit
c1acf97334
@ -13,7 +13,7 @@
|
||||
# This is because motorola ships an armv7l userspace from stock ROM.
|
||||
#
|
||||
# in local.nix:
|
||||
# mobile.system.platform = lib.mkForce "armv7a-linux";
|
||||
# mobile.system.system = lib.mkForce "armv7l-linux";
|
||||
#
|
||||
|
||||
let
|
||||
|
@ -15,6 +15,6 @@ in
|
||||
};
|
||||
|
||||
config = {
|
||||
mobile.system.platform = lib.mkIf cfg.generic-x86_64.enable "x86_64-linux";
|
||||
mobile.system.system = lib.mkIf cfg.generic-x86_64.enable "x86_64-linux";
|
||||
};
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ in
|
||||
config = mkMerge [
|
||||
{
|
||||
mobile = mkIf cfg.qualcomm-msm8939.enable {
|
||||
system.platform = "aarch64-linux";
|
||||
system.system = "aarch64-linux";
|
||||
quirks.qualcomm.msm-fb-handle.enable = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
mobile = mkIf cfg.qualcomm-msm8953.enable {
|
||||
system.platform = "aarch64-linux";
|
||||
system.system = "aarch64-linux";
|
||||
quirks.qualcomm.msm-fb-handle.enable = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
mobile = mkIf cfg.qualcomm-apq8064-1aa.enable {
|
||||
system.platform = "armv7a-linux";
|
||||
system.system = "armv7l-linux";
|
||||
quirks.qualcomm.msm-fb-refresher.enable = true;
|
||||
};
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ in
|
||||
config = mkMerge [
|
||||
{
|
||||
mobile = mkIf cfg.rockchip-op1.enable {
|
||||
system.platform = "aarch64-linux";
|
||||
system.system = "aarch64-linux";
|
||||
};
|
||||
}
|
||||
];
|
||||
|
@ -1,24 +1,35 @@
|
||||
{ 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;
|
||||
armv7a-linux = lib.systems.examples.armv7l-hf-multiplatform;
|
||||
x86_64-linux = { config = "x86_64-unknown-linux-gnu"; };
|
||||
# Mapping from system types to config types
|
||||
# A simplified view of <nixpkgs/lib/systems/examples.nix>
|
||||
config_types = {
|
||||
aarch64-linux = "aarch64-unknown-linux-gnu";
|
||||
armv7l-linux = "armv7l-unknown-linux-gnueabihf";
|
||||
x86_64-linux = "x86_64-unknown-linux-gnu";
|
||||
};
|
||||
|
||||
# Hmmm, this doesn't feel right, but it does work.
|
||||
host_platform = (import <nixpkgs> {}).buildPackages.hostPlatform;
|
||||
# Derived from config_types
|
||||
target_types = lib.attrNames config_types;
|
||||
|
||||
# Builds the expected "platform" set for cross-compilation from the given
|
||||
# system name.
|
||||
selectPlatform = system: {
|
||||
inherit system;
|
||||
platform = lib.systems.platforms.selectBySystem system;
|
||||
config = config_types.${system};
|
||||
};
|
||||
|
||||
# The platform selected by the configuration
|
||||
selectedPlatform = selectPlatform cfg.system;
|
||||
in
|
||||
{
|
||||
options.mobile = {
|
||||
system.platform = mkOption {
|
||||
type = types.enum (lib.attrNames target_types);
|
||||
system.system = mkOption {
|
||||
type = types.enum target_types;
|
||||
description = ''
|
||||
Defines the kind of target architecture system the device is.
|
||||
|
||||
@ -30,14 +41,25 @@ in
|
||||
config = {
|
||||
assertions = [
|
||||
{
|
||||
assertion = pkgs.targetPlatform.system == cfg.platform;
|
||||
message = "pkgs.targetPlatform.system expected to be `${cfg.platform}`, is `${pkgs.targetPlatform.system}`";
|
||||
assertion = pkgs.targetPlatform.system == cfg.system;
|
||||
message = "pkgs.targetPlatform.system expected to be `${cfg.system}`, is `${pkgs.targetPlatform.system}`";
|
||||
}
|
||||
];
|
||||
|
||||
nixpkgs.crossSystem = lib.mkIf
|
||||
( target_types.${cfg.platform}.config != host_platform.config )
|
||||
(target_types.${cfg.platform} // { system = cfg.platform; }) # FIXME : WHY? I didn't need to add system before :/
|
||||
(
|
||||
let
|
||||
result = selectedPlatform.system != builtins.currentSystem;
|
||||
in
|
||||
builtins.trace
|
||||
"Building with crossSystem?: ${selectedPlatform.system} != ${builtins.currentSystem} → ${if result then "true" else "false"}"
|
||||
result
|
||||
)
|
||||
(
|
||||
builtins.trace
|
||||
" crossSystem: config: ${selectedPlatform.config}"
|
||||
selectedPlatform
|
||||
)
|
||||
;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user