Skip to content

Commit 7606e37

Browse files
committed
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 8598142 commit 7606e37

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

.envrc

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

default.nix

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

flake.lock

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

flake.nix

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

shell.nix

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

0 commit comments

Comments
 (0)