forked from Tow-Boot/Tow-Boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.nix
62 lines (55 loc) · 1.77 KB
/
system.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ config, lib, pkgs, ... }:
let
inherit (config.helpers) verbosely;
cfg = config.system;
inherit (config.nixpkgs) localSystem;
# The platform selected by the configuration
selectedPlatform = lib.systems.elaborate cfg.system;
in
{
options = {
system = {
automaticCross = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Enables automatic configuration of cross-compilation.
**Note** that while it is disabled by default, the default.nix at the
root of the project _will_ enable it.
'';
};
system = lib.mkOption {
# Known supported target types
type = lib.types.enum [
"i686-linux"
"x86_64-linux"
"armv5tel-linux"
"armv6l-linux"
"armv7l-linux"
"aarch64-linux"
];
description = ''
Defines the kind of target architecture system the device is.
'';
};
};
};
config = {
assertions = [
{
assertion = pkgs.targetPlatform.system == cfg.system;
message = ''
pkgs.targetPlatform.system expected to be `${cfg.system}`, is `${pkgs.targetPlatform.system}`.
TIP: enable `system.automaticCross`, which will impurely automatically enable cross-compilation.
'';
}
];
nixpkgs.crossSystem = lib.mkIf cfg.automaticCross (
lib.mkIf (
let result = selectedPlatform.system != localSystem.system; in
verbosely (builtins.trace "Building with crossSystem?: ${selectedPlatform.system} != ${localSystem.system} → ${if result then "we are" else "we're not"}.")
result
) (verbosely (builtins.trace " crossSystem: config: ${selectedPlatform.config}") selectedPlatform)
);
};
}