Skip to content

Commit

Permalink
nix build environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ngkz committed Jan 25, 2024
1 parent ecf2f56 commit 12e17ad
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .envrc
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# ^ added for shellcheck and file-type detection

# Watch & reload direnv on change
if [[ $(type -t use_flake) != function ]]; then
echo "ERROR: use_flake function missing."
echo "Please update direnv to v2.30.0 or later."
exit 1
fi
use flake ".?submodules=1"
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -50,3 +50,5 @@ src/arm-none-eabi

# clangd
.cache/

.direnv/
26 changes: 26 additions & 0 deletions default.nix
@@ -0,0 +1,26 @@
# Use `builtins.getFlake` if available
if builtins ? getFlake
then
let
scheme =
if builtins.pathExists ./.git
then "git+file"
else "path";
in
(builtins.getFlake "${scheme}://${toString ./.}")
.packages
.${builtins.currentSystem}
.default

# Otherwise we'll use the flake-compat shim
else
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
144 changes: 144 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions flake.nix
@@ -0,0 +1,33 @@
{
description = "virtual environments";

inputs.devshell.url = "github:numtide/devshell";
inputs.flake-utils.url = "github:numtide/flake-utils";

inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

outputs = { self, flake-utils, devshell, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
config.allowUnfree = true; # nrf5-sdk
};
in {
packages.default = pkgs.callPackage ./infinitime.nix { };
devShells.default = pkgs.devshell.mkShell {
devshell.packages = self.packages.${system}.default.nativeBuildInputs;

commands = [{
name = "do_cmake";
command = ''
cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=${pkgs.gcc-arm-embedded-10} -DNRF5_SDK_PATH=${pkgs.nrf5-sdk}/share/nRF5_SDK "$@"
'';
}];
};
});
}
45 changes: 45 additions & 0 deletions infinitime.nix
@@ -0,0 +1,45 @@
{ stdenv, patch, cmake, gnumake, gcc-arm-embedded-10, nrf5-sdk, python3, adafruit-nrfutil
, nodePackages }:

stdenv.mkDerivation {
pname = "infinitime-japanese";
version = "1.14.0";

src = ./.;

nativeBuildInputs = [
cmake
gnumake
gcc-arm-embedded-10
nrf5-sdk
(python3.withPackages
(p: with p; [ cbor click intelhex cryptography pillow ]))
adafruit-nrfutil
nodePackages.lv_font_conv
];

cmakeFlags = [
"-DARM_NONE_EABI_TOOLCHAIN_PATH=${gcc-arm-embedded-10}"
"-DNRF5_SDK_PATH=${nrf5-sdk}/share/nRF5_SDK"
"-DBUILD_DFU=1"
"-DBUILD_RESOURCES=1"
"-DCMAKE_BUILD_TYPE=Release"
];

makeTargets = [
"pinetime-mcuboot-app"
"GenerateResources"
];

patchPhase = ''
patchShebangs .
substituteInPlace src/resources/generate-fonts.py --replace "'/usr/bin/env', 'patch'" "'${patch}/bin/patch'"
substituteInPlace src/displayapp/fonts/generate.py --replace "'/usr/bin/env', 'patch'" "'${patch}/bin/patch'"
'';

installPhase = ''
mkdir -p $out
cp src/pinetime-mcuboot-app-dfu-*.zip $out/
cp src/resources/infinitime-resources-*.zip $out/
'';
}
26 changes: 26 additions & 0 deletions shell.nix
@@ -0,0 +1,26 @@
# Use `builtins.getFlake` if available
if builtins ? getFlake
then
let
scheme =
if builtins.pathExists ./.git
then "git+file"
else "path";
in
(builtins.getFlake "${scheme}://${toString ./.}")
.devShells
.${builtins.currentSystem}
.default

# Otherwise we'll use the flake-compat shim
else
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix

0 comments on commit 12e17ad

Please sign in to comment.