humpback-dds/flake.nix

134 lines
4.3 KiB
Nix
Raw Permalink Normal View History

{
description = "Firmware for MQTT-controlled 4-channel DDS signal generator using Urukul, Humpback and STM32 NUCLEO.";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
2024-04-24 20:58:55 +08:00
inputs.rust-overlay.url = github:oxalica/rust-overlay;
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
inputs.src-migen = { url = github:m-labs/migen; flake = false; };
2024-04-24 20:58:55 +08:00
outputs = { self, nixpkgs, rust-overlay, src-migen }:
let
2024-04-24 20:58:55 +08:00
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import rust-overlay) ]; };
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
migen = pkgs.python3Packages.buildPythonPackage rec {
name = "migen";
src = src-migen;
propagatedBuildInputs = [ pkgs.python3Packages.colorama ];
};
2024-04-24 20:58:55 +08:00
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;
};
itm = rustPlatform.buildRustPackage rec {
version = "0.3.1";
pname = "itm";
src = pkgs.fetchFromGitHub {
owner = "rust-embedded";
repo = "itm";
rev = "v${version}";
sha256 = "sha256-UmWI3NOE8Lf8ICHOR8nNpbCP9+g3R8XHRX+nUJsH6pY=";
};
cargoPatches = [ ./itm-cargo-lock.patch ];
cargoSha256 = "sha256-3odQabrzjFm5rTkeqZWDFLnculwGeB3gG71jNuCtqIo=";
nativeBuildInputs = [ pkgs.pkgconfig ];
doCheck = false;
};
runOpenOcdBlock = pkgs.writeShellScriptBin "run-openocd-block" ''
openocd -f openocd/openocd.cfg
'';
openocdFlash = pkgs.writeShellScriptBin "openocd-flash" ''
openocd -f openocd/openocd.cfg -f openocd/main.cfg
'';
publishMqtt = pkgs.writeShellScriptBin "publish-mqtt" ''
mosquitto_pub -h localhost -t $1 -m "$2" -d
'';
openOCDFlashCustomised = pkgs.writeShellScriptBin "openocd-flash-customised" ''
python3 flash.py $@
openocd -f openocd/openocd.cfg \
-c "init
reset init
halt
stm32h7x mass_erase 1
flash write_image erase target/thumbv7em-none-eabihf/release/humpback-dds
flash write_image flash_config.bin 0x081e0000 bin
reset run
shutdown"
'';
humpback-dds = rustPlatform.buildRustPackage rec {
name = "humpback-dds";
version = "0.0.0";
src = self;
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"SaiTLS-0.1.0" = "sha256-T3hyASQGZAXGLKfOB3mh33VrvRlYSMc1CJdX4XvDFrQ=";
"rsa-0.3.0" = "sha256-9X2kDAOu0HG94HhwYoUtX/ezq99w7u95XMzn3h/JUwk=";
"minimq-0.1.0" = "sha256-yPqMAwyusZZW7571Jn3QVYK2jqmuSMNU6LiZXRYAGGM=";
"smoltcp-0.6.0" = "sha256-BCqcphWF3AotQfuIFYhDiWIMhh2eUCuqD4MPz4dASQ4=";
};
};
nativeBuildInputs = [
pkgs.llvm
pkgs.yosys
pkgs.nextpnr
pkgs.icestorm
(pkgs.python3.withPackages(ps: [ migen ]))
];
buildPhase = ''
cargo build --release --bin humpback-dds
'';
installPhase = ''
mkdir -p $out $out/nix-support
cp target/thumbv7em-none-eabihf/release/humpback-dds $out/humpback-dds.elf
echo file binary-dist $out/humpback-dds.elf >> $out/nix-support/hydra-build-products
llvm-objcopy -O binary target/thumbv7em-none-eabihf/release/humpback-dds $out/humpback-dds.bin
echo file binary-dist $out/humpback-dds.bin >> $out/nix-support/hydra-build-products
'';
doCheck = false;
dontFixup = true;
};
in {
packages.x86_64-linux = {
inherit humpback-dds;
};
hydraJobs = {
inherit humpback-dds;
};
devShell.x86_64-linux = pkgs.mkShell {
name = "humpback-dds-dev-shell";
buildInputs = with pkgs; [
rustPlatform.rust.rustc
rustPlatform.rust.cargo
openocd dfu-util
yosys nextpnr icestorm
gdb mosquitto
itm runOpenOcdBlock
openocdFlash publishMqtt
openOCDFlashCustomised
] ++ (with python3Packages; [
numpy matplotlib migen
]);
};
defaultPackage.x86_64-linux = humpback-dds;
};
2024-04-24 20:58:55 +08:00
}