Skip to content

Commit 824a30b

Browse files
committed
feat: Introduce Flake for development and builds
This PR introduces a Nix flake, allowing for InfiniSim to be built as a Flake, including a FHS development environment. 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. It should be noted that we require InfiniTimeOrg/InfiniTime#2121 to be merged into mainline before this PR will work. It will currently fail - this is expected at this stage. A lockfile needs to be generated after the above PR is merged - this PR here should NOT be merged until that is completed. Signed-off-by: Dom Rodriguez <[email protected]>
1 parent 832d38f commit 824a30b

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-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.nix

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
description = "A very basic flake";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
infinitime.url = "github:InfiniTimeOrg/InfiniTime";
7+
flake-compat = {
8+
url = "github:edolstra/flake-compat";
9+
flake = false;
10+
};
11+
};
12+
13+
outputs =
14+
{ self, ... }@inputs:
15+
let
16+
forAllSystems =
17+
function:
18+
inputs.nixpkgs.lib.genAttrs
19+
[
20+
"x86_64-linux"
21+
"aarch64-linux"
22+
]
23+
(
24+
system:
25+
function (
26+
import inputs.nixpkgs {
27+
inherit system;
28+
config.allowUnfree = true;
29+
}
30+
)
31+
);
32+
in
33+
let
34+
infinitime = inputs.infinitime.packages.x86_64-linux.infinitime;
35+
lv_img_conv = inputs.infinitime.packages.x86_64-linux.lv_img_conv;
36+
in
37+
{
38+
packages = forAllSystems (
39+
pkgs: with pkgs; {
40+
default = stdenv.mkDerivation rec {
41+
name = "infinisim";
42+
version = "v1.13.0";
43+
srcs =
44+
let
45+
InfiniTime = (
46+
fetchFromGitHub rec {
47+
inherit (infinitime.src) owner repo rev;
48+
fetchSubmodules = true;
49+
name = repo;
50+
sha256 = "sha256-W1aKQbvYQ7yzz1mz2+356i7clkMTXoL5li3YXzysnMw=";
51+
}
52+
);
53+
InfiniSim = (
54+
fetchFromGitHub rec {
55+
owner = "InfiniTimeOrg"; # CHANGEME.
56+
repo = "InfiniSim";
57+
rev = "25ec7af440f3a9044b33ff3462a18589dbbe3dd9";
58+
sha256 = "sha256-wRttm6NqGTN4ZeBzWY9ySCkedKDu70A1pUPRA87IuTg=";
59+
}
60+
);
61+
in
62+
[
63+
InfiniSim
64+
InfiniTime
65+
];
66+
67+
sourceRoot = ".";
68+
postUnpack =
69+
let
70+
InfiniTime = (builtins.elemAt srcs 1).name;
71+
InfiniSim = (builtins.elemAt srcs 0).name;
72+
in
73+
''
74+
cp -R ${InfiniSim} $sourceRoot/InfiniSim
75+
cp -R ${InfiniTime} $sourceRoot/InfiniSim/InfiniTime
76+
chmod -R u+w $sourceRoot/InfiniSim
77+
'';
78+
79+
nativeBuildInputs =
80+
with pkgs;
81+
[
82+
SDL2
83+
libpng
84+
patch
85+
zlib
86+
]
87+
++ infinitime.nativeBuildInputs;
88+
89+
buildInputs = with pkgs; [ cmake ] ++ infinitime.buildInputs;
90+
91+
preConfigure =
92+
let
93+
InfiniSim = "$sourceRoot/InfiniSim";
94+
InfiniTime = "${InfiniSim}/InfiniTime";
95+
in
96+
''
97+
substituteInPlace ${InfiniTime}/src/displayapp/fonts/generate.py --replace "'/usr/bin/env', 'patch'" "'${lib.getExe patch}'"
98+
substituteInPlace ${InfiniTime}/src/resources/generate-fonts.py --replace "'/usr/bin/env', 'patch'" "'${lib.getExe patch}'"
99+
patchShebangs ${InfiniTime}/src/displayapp/fonts/generate.py \
100+
${InfiniTime}/tools/mcuboot/imgtool.py
101+
'';
102+
103+
cmakeBuildDir = "InfiniSim/build";
104+
105+
cmakeFlags =
106+
let
107+
lvImgConvPath = "${lv_img_conv.outPath}/bin";
108+
in
109+
[
110+
"-DCMAKE_PROGRAM_PATH=${lvImgConvPath}"
111+
"-DInfiniTime_DIR=../InfiniTime"
112+
];
113+
114+
meta = with lib; {
115+
maintainers = with maintainers; [ shymega ];
116+
metaProgram = "infinisim";
117+
};
118+
};
119+
}
120+
);
121+
122+
devShells = forAllSystems (pkgs: {
123+
default = pkgs.mkShell {
124+
packages = [ pkgs.ninja ] ++ self.packages.${pkgs.system}.default.nativeBuildInputs;
125+
};
126+
});
127+
};
128+
}

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)