-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
134 lines (125 loc) · 4.25 KB
/
flake.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
description = "Rust cross-compilatilon utils";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{ self
, nixpkgs
, rust-overlay
, flake-utils
, treefmt-nix
}: flake-utils.lib.eachDefaultSystem
(system:
let
# Setup nixpkgs.
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
(import ./.)
];
};
treefmt = (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;
# List of supported cross systems
supportedCrossSystems = [
null
{ config = "x86_64-unknown-linux-gnu"; useLLVM = false; isStatic = false; }
{ config = "x86_64-unknown-linux-musl"; useLLVM = true; isStatic = false; }
{ config = "x86_64-unknown-linux-musl"; useLLVM = true; isStatic = false; }
{ config = "x86_64-unknown-linux-musl"; useLLVM = true; isStatic = true; }
{ config = "x86_64-unknown-linux-musl"; useLLVM = false; isStatic = false; }
{ config = "aarch64-unknown-linux-gnu"; useLLVM = false; isStatic = false; }
{ config = "aarch64-unknown-linux-musl"; useLLVM = true; isStatic = false; }
{ config = "aarch64-unknown-linux-musl"; useLLVM = true; isStatic = true; }
{ config = "aarch64-unknown-linux-musl"; useLLVM = false; isStatic = false; }
{ config = "riscv64-unknown-linux-gnu"; useLLVM = false; isStatic = false; }
];
mkDevShellName = name: crossSystem:
let
useLLVM =
if crossSystem.useLLVM
then "&useLLVM=true"
else "";
isStatic =
if crossSystem.isStatic
then "&isStatic=true"
else "";
in
if crossSystem != null then
"${name}?target=${crossSystem.config}${useLLVM}${isStatic}"
else
"default";
foreachCrossSystem = (name: f:
pkgs.lib.lists.foldr
(crossSystem: output:
output // {
"${mkDevShellName name crossSystem}" = (f crossSystem);
})
{ }
supportedCrossSystems);
in
{
# for `nix fmt`
formatter = treefmt.wrapper;
# for `nix flake check`
checks.formatting = treefmt.check self;
devShells = foreachCrossSystem "crossShell" (crossSystem:
import ./shell.nix {
localSystem = system; inherit crossSystem;
});
packages =
# Targets for CI.
foreachCrossSystem "pkgs"
(crossSystem:
import ./tests {
inherit pkgs;
localSystem = system;
crossSystems = [ crossSystem ];
src = nixpkgs;
})
# Other targets.
// rec {
pkgsAll = import ./tests {
inherit pkgs;
localSystem = system;
crossSystems = supportedCrossSystems;
src = nixpkgs;
};
pushAll = with pkgs; writeShellApplication {
name = "push-all";
runtimeInputs = [ cachix nix ];
text = ''cachix push nixpkgs-cross-overlay "${pkgsAll}"'';
};
};
})
# System independent modules.
// {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
overlays =
let
nixpkgs-cross-overlay = import ./.;
rust-overlay' = (import rust-overlay);
in
{
default = nixpkgs-cross-overlay;
rust-overlay = rust-overlay';
# Export as a flake overlay including all dependent overlays.
full = final: prev:
(rust-overlay' final prev) // (nixpkgs-cross-overlay final prev);
};
};
}