Skip to content

Commit f521883

Browse files
committedNov 13, 2024
feat: Introduce Flake for development and builds
This PR introduces a Nix flake, allowing for InfiniTime to be built as a Flake, including a FHS development environment. It's derived from #1850 and icewind1991/infinitime-builder@c57c57f. We also introduce `flake-compat`, allowing for non-Flake Nix mahcines to use the project as-is, both for building (`default.nix`), and development (`shell.nix`). Additionally, we introduce `.envrc`, meaning that with `direnv`, the Nix Flake is activated automatically. Fixes #1850. Signed-off-by: Dom Rodriguez <shymega@shymega.org.uk>
1 parent f7c87a7 commit f521883

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed
 

‎.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

‎default.nix

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
in
5+
fetchTarball {
6+
url =
7+
lock.nodes.flake-compat.locked.url
8+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
9+
sha256 = lock.nodes.flake-compat.locked.narHash;
10+
}
11+
) { src = ./.; }).defaultNix

‎flake.lock

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
{
2+
description = "A very basic flake";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
flake-compat = {
7+
url = "github:edolstra/flake-compat";
8+
flake = false;
9+
};
10+
};
11+
12+
outputs =
13+
{ self, ... }@inputs:
14+
let
15+
forAllSystems =
16+
function:
17+
inputs.nixpkgs.lib.genAttrs
18+
[
19+
"x86_64-linux"
20+
"aarch64-linux"
21+
]
22+
(
23+
system:
24+
function (
25+
import inputs.nixpkgs {
26+
inherit system;
27+
config.allowUnfree = true;
28+
}
29+
)
30+
);
31+
in
32+
{
33+
packages = forAllSystems (
34+
pkgs:
35+
let
36+
infinitime-nrf5-sdk = pkgs.nrf5-sdk.overrideAttrs (old: {
37+
version = "15.3.0";
38+
src = pkgs.fetchzip {
39+
url = "https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/nrf5sdk153059ac345.zip";
40+
sha256 = "sha256-pfmhbpgVv5x2ju489XcivguwpnofHbgVA7bFUJRTj08=";
41+
};
42+
});
43+
in
44+
with pkgs;
45+
rec {
46+
infinitime = stdenv.mkDerivation rec {
47+
name = "infinitime";
48+
version = "1.14.1";
49+
50+
src = fetchFromGitHub {
51+
owner = "InfiniTimeOrg";
52+
repo = "InfiniTime";
53+
rev = "refs/tags/${version}";
54+
hash = "sha256-IrsN+9LgEjgfoRR6H7FhsdLMK+GLxc41IBnSbdpwv/E=";
55+
fetchSubmodules = true;
56+
};
57+
58+
nativeBuildInputs = [
59+
adafruit-nrfutil
60+
nodePackages.lv_font_conv
61+
patch
62+
python3
63+
python3.pkgs.cbor
64+
python3.pkgs.click
65+
python3.pkgs.cryptography
66+
python3.pkgs.intelhex
67+
python3.pkgs.pillow
68+
];
69+
70+
buildInputs = with pkgs; [ cmake ];
71+
72+
postPatch = ''
73+
# /usr/bin/env is not available in the build sandbox
74+
substituteInPlace src/displayapp/fonts/generate.py --replace "'/usr/bin/env', 'patch'" "'patch'"
75+
substituteInPlace tools/mcuboot/imgtool.py --replace "/usr/bin/env python3" "${python3}/bin/python3"
76+
'';
77+
78+
cmakeFlags =
79+
let
80+
lvImgConvPath = "${lv_img_conv.outPath}/bin";
81+
in
82+
[
83+
''-DARM_NONE_EABI_TOOLCHAIN_PATH=${gcc-arm-embedded-10}''
84+
''-DNRF5_SDK_PATH=${infinitime-nrf5-sdk}/share/nRF5_SDK''
85+
''-DBUILD_DFU=1''
86+
''-DBUILD_RESOURCES=1''
87+
''-DCMAKE_SOURCE_DIR=${src}''
88+
''-DCMAKE_PROGRAM_PATH=${lvImgConvPath}''
89+
];
90+
91+
installPhase = ''
92+
SOURCES_DIR=${src} BUILD_DIR=. OUTPUT_DIR=$out ./post_build.sh
93+
'';
94+
};
95+
default = infinitime;
96+
lv_img_conv = python3Packages.buildPythonApplication rec {
97+
pname = "lv_img_conv";
98+
version = "unstable";
99+
format = "other";
100+
101+
propagatedBuildInputs = with python3Packages; [ pillow ];
102+
103+
dontUnpack = true;
104+
installPhase =
105+
let
106+
scriptPath = ./src/resources/lv_img_conv.py;
107+
in
108+
''
109+
install -Dm755 ${scriptPath} $out/bin/${pname}
110+
'';
111+
};
112+
}
113+
);
114+
115+
devShells = forAllSystems (
116+
pkgs:
117+
let
118+
infinitime-nrf5-sdk = pkgs.nrf5-sdk.overrideAttrs (old: {
119+
version = "15.3.0";
120+
src = pkgs.fetchzip {
121+
url = "https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/sdks/nrf5/binaries/nrf5sdk153059ac345.zip";
122+
sha256 = "sha256-pfmhbpgVv5x2ju489XcivguwpnofHbgVA7bFUJRTj08=";
123+
};
124+
});
125+
in
126+
with pkgs;
127+
{
128+
default = mkShell {
129+
packages =
130+
[
131+
(writeShellScriptBin "cmake_infinitime" ''
132+
${cmake}/bin/cmake -DARM_NONE_EABI_TOOLCHAIN_PATH="${gcc-arm-embedded-10}" \
133+
-DNRF5_SDK_PATH="${infinitime-nrf5-sdk}/share/nRF5_SDK" \
134+
"$@"
135+
'')
136+
ninja
137+
]
138+
++ (with self.packages.${pkgs.system}; [
139+
infinitime
140+
lv_img_conv
141+
]);
142+
};
143+
}
144+
);
145+
};
146+
}

‎shell.nix

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
in
5+
fetchTarball {
6+
url =
7+
lock.nodes.flake-compat.locked.url
8+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
9+
sha256 = lock.nodes.flake-compat.locked.narHash;
10+
}
11+
) { src = ./.; }).shellNix

0 commit comments

Comments
 (0)