Skip to content

Commit 31625ce

Browse files
authored
Merge pull request #40 from Detegr/flake
Add Nix flake based build
2 parents 2e42135 + 2157fbf commit 31625ce

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed

flake.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
description = "Neotron OS";
3+
4+
inputs = {
5+
flake-utils.url = "github:numtide/flake-utils";
6+
rust-overlay = {
7+
url = "github:oxalica/rust-overlay";
8+
inputs = {
9+
nixpkgs.follows = "nixpkgs";
10+
flake-utils.follows = "flake-utils";
11+
};
12+
};
13+
crane = {
14+
url = "github:ipetkov/crane";
15+
inputs = {
16+
nixpkgs.follows = "nixpkgs";
17+
flake-utils.follows = "flake-utils";
18+
rust-overlay.follows = "rust-overlay";
19+
};
20+
};
21+
};
22+
23+
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }:
24+
let
25+
# List of systems this flake.nix has been tested to work with
26+
systems = [ "x86_64-linux" ];
27+
in
28+
flake-utils.lib.eachSystem systems
29+
(system:
30+
let
31+
pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [
32+
rust-overlay.overlays.default
33+
];
34+
lib = pkgs.lib;
35+
targets = [
36+
"thumbv6m-none-eabi"
37+
"thumbv7m-none-eabi"
38+
"thumbv7em-none-eabi"
39+
];
40+
toolchain = pkgs.rust-bin.stable.latest.default.override { inherit targets; };
41+
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
42+
43+
neotron-packages = builtins.listToAttrs (map
44+
(tgt:
45+
let arch = lib.head (builtins.split "-" tgt);
46+
in {
47+
name = "neotron-os-${arch}";
48+
value = craneLib.buildPackage {
49+
pname = "neotron-os";
50+
nativeBuildInputs = [
51+
pkgs.gcc-arm-embedded
52+
];
53+
doCheck = false;
54+
src = with pkgs.lib;
55+
let keep = suffix: path: type: hasSuffix suffix path;
56+
in
57+
cleanSourceWith {
58+
src = craneLib.path ./.;
59+
filter = path: type: any id (map (f: f path type) [
60+
craneLib.filterCargoSources
61+
(keep ".ld")
62+
]);
63+
};
64+
cargoExtraArgs = "--target=${tgt}";
65+
installPhase = ''
66+
runHook preInstall
67+
mkdir -p $out/bin
68+
'' + toString (map
69+
(bin: ''
70+
cp target/${tgt}/release/${bin} $out/bin/${tgt}-${bin}-libneotron_os.elf
71+
arm-none-eabi-objcopy -O binary target/${tgt}/release/${bin} $out/bin/${tgt}-${bin}-libneotron_os.bin
72+
'') [ "flash0002" "flash0802" "flash1002" ]) + ''
73+
runHook postInstall
74+
'';
75+
};
76+
}
77+
)
78+
targets);
79+
in
80+
{
81+
packages = neotron-packages;
82+
83+
devShell = pkgs.mkShell {
84+
inputsFrom = builtins.attrValues self.packages.${system};
85+
};
86+
}
87+
);
88+
}

0 commit comments

Comments
 (0)