humpback-dds/flake.nix

145 lines
4.8 KiB
Nix

{
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;
inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; };
inputs.src-migen = { url = github:m-labs/migen; flake = false; };
outputs = { self, nixpkgs, mozilla-overlay, src-migen }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
rustManifest = pkgs.fetchurl {
url = "https://static.rust-lang.org/dist/2020-10-30/channel-rust-nightly.toml";
sha256 = "0iygcwzh8s0lfdghj5809krvzifc1ii1wm4sd3qqn7s0rz1s14hi";
};
migen = pkgs.python3Packages.buildPythonPackage rec {
name = "migen";
src = src-migen;
propagatedBuildInputs = [ pkgs.python3Packages.colorama ];
};
targets = [
"thumbv7em-none-eabihf"
];
rustChannelOfTargets = _channel: _date: targets:
(pkgs.lib.rustLib.fromManifestFile rustManifest {
inherit (pkgs) stdenv lib fetchurl patchelf;
}).rust.override {
inherit targets;
extensions = ["rust-src"];
};
rust = rustChannelOfTargets "nightly" null targets;
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
});
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;
};
}