Skip to content

Commit 8131b4a

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. Signed-off-by: Dom Rodriguez <[email protected]>
1 parent 56a9673 commit 8131b4a

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-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

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

flake.nix

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
description = "A very basic flake";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
infinitime.url = "github:shymega/InfiniTime?ref=shymega-feat/nix-flake&submodules=1";
7+
# infinitime.url = "github:InfiniTimeOrg/InfiniTime";
8+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
9+
};
10+
11+
outputs = { self, ... }@inputs:
12+
let
13+
forAllSystems = function:
14+
inputs.nixpkgs.lib.genAttrs [
15+
"x86_64-linux"
16+
"aarch64-linux"
17+
]
18+
(system: function (import inputs.nixpkgs {
19+
inherit system;
20+
config.allowUnfree = true;
21+
}));
22+
in
23+
{
24+
packages = forAllSystems (pkgs:
25+
let
26+
infinitime = inputs.infinitime.packages.${pkgs.system}.default;
27+
in
28+
with pkgs; {
29+
default = stdenv.mkDerivation rec {
30+
name = "infinisim";
31+
srcs = [
32+
(fetchFromGitHub {
33+
name = "InfiniTime";
34+
owner = "shymega";
35+
repo = "InfiniTime";
36+
rev = "refs/heads/shymega-feat/nix-flake";
37+
fetchSubmodules = true;
38+
leaveDotGit = true;
39+
sha256 = "sha256-3x4FubKg8xXJf4t1QjSRIE8FKh89/0yT67bStH+a3HQ=";
40+
})
41+
(lib.cleanSource ./.)
42+
];
43+
sourceRoot = ".";
44+
45+
nativeBuildInputs = with pkgs; [
46+
SDL2
47+
libpng
48+
patch
49+
zlib
50+
] ++ infinitime.nativeBuildInputs;
51+
52+
buildInputs = with pkgs; [
53+
cmake
54+
] ++ infinitime.buildInputs;
55+
56+
preConfigure = ''
57+
patchShebangs $sourceRoot/InfiniTime/src/displayapp/fonts/generate.py \
58+
$sourceRoot/InfiniTime/tools/mcuboot/imgtool.py \
59+
$sourceRoot/source/img/convert_bmp_to_header.py
60+
'';
61+
62+
cmakeFlags = [
63+
"-DInfiniTime_DIR=${sourceRoot}/InfiniTime"
64+
];
65+
};
66+
});
67+
68+
devShells = forAllSystems (pkgs:
69+
{
70+
default =
71+
pkgs.mkShell {
72+
packages = [ pkgs.ninja ] ++ self.packages.${pkgs.system}.default.nativeBuildInputs;
73+
};
74+
});
75+
};
76+
}
77+

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)