nix flakes support #64
@ -1 +0,0 @@
|
||||
"0qb4s06jwgj3i9df6qq9gwcnyr3jq6dh4l5ygjghq5x1bmcqliix"
|
44
flake.lock
generated
Normal file
44
flake.lock
generated
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"nodes": {
|
||||
"mozilla-overlay": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1638887313,
|
||||
"narHash": "sha256-FMYV6rVtvSIfthgC1sK1xugh3y7muoQcvduMdriz4ag=",
|
||||
"owner": "mozilla",
|
||||
"repo": "nixpkgs-mozilla",
|
||||
"rev": "7c1e8b1dd6ed0043fb4ee0b12b815256b0b9de6f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "mozilla",
|
||||
"repo": "nixpkgs-mozilla",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1641870998,
|
||||
"narHash": "sha256-6HkxR2WZsm37VoQS7jgp6Omd71iw6t1kP8bDbaqCDuI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "386234e2a61e1e8acf94dfa3a3d3ca19a6776efb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-21.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"mozilla-overlay": "mozilla-overlay",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
81
flake.nix
Normal file
81
flake.nix
Normal file
@ -0,0 +1,81 @@
|
||||
{
|
||||
description = "Firmware for the Sinara 8451 Thermostat";
|
||||
|
||||
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
|
||||
inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; };
|
||||
|
||||
outputs = { self, nixpkgs, mozilla-overlay }:
|
||||
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";
|
||||
};
|
||||
|
||||
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;
|
||||
});
|
||||
cargoSha256 = "0qb4s06jwgj3i9df6qq9gwcnyr3jq6dh4l5ygjghq5x1bmcqliix";
|
||||
buildStm32Firmware = { name, src, cargoDepsName ? name, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", doCheck ? true, binaryName ? name, extraCargoBuildArgs ? "" }:
|
||||
rustPlatform.buildRustPackage rec {
|
||||
inherit name cargoDepsName;
|
||||
version = "0.0.0";
|
||||
|
||||
inherit src;
|
||||
inherit cargoSha256;
|
||||
|
||||
inherit patchPhase;
|
||||
nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs;
|
||||
buildPhase = ''
|
||||
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
|
||||
cargo build --release --bin ${binaryName} ${extraCargoBuildArgs}
|
||||
'';
|
||||
|
||||
|
||||
inherit checkPhase doCheck;
|
||||
# binaryName defaults to the `name` arg (i.e. the Rust package name);
|
||||
# it is used as the Cargo binary filename
|
||||
installPhase = ''
|
||||
mkdir -p $out $out/nix-support
|
||||
cp target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.elf
|
||||
echo file binary-dist $out/${name}.elf >> $out/nix-support/hydra-build-products
|
||||
llvm-objcopy -O binary target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.bin
|
||||
echo file binary-dist $out/${name}.bin >> $out/nix-support/hydra-build-products
|
||||
'';
|
||||
|
||||
dontFixup = true;
|
||||
};
|
||||
in {
|
||||
packages.x86_64-linux = rec {
|
||||
thermostat = buildStm32Firmware {
|
||||
name = "thermostat";
|
||||
src = self;
|
||||
checkPhase = ''
|
||||
cargo test --target=${pkgs.rust.toRustTarget pkgs.stdenv.targetPlatform};
|
||||
'';
|
||||
};
|
||||
};
|
||||
devShell.x86_64-linux = pkgs.mkShell {
|
||||
name = "thermostat-dev-shell";
|
||||
buildInputs = with pkgs; [
|
||||
rustPlatform.rust.rustc
|
||||
sb10q
commented
gcc? gcc?
|
||||
rustPlatform.rust.cargo
|
||||
gcc openocd dfu-util
|
||||
sb10q
commented
Did you test this? I think this doesn't work and you need Did you test this? I think this doesn't work and you need ``python3.withPackages`` instead.
mwojcik
commented
Weirdly enough it seems to work
Weirdly enough it seems to work
```shell
❯ nix develop
[spaqin@hera:~/m-labs/thermostat]$ python
Python 3.9.6 (default, Jun 28 2021, 08:57:49)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>>
```
sb10q
commented
This is the lab computer and those packages are already included in the system Python. You can use This is the lab computer and those packages are already included in the system Python. You can use ``nix develop --ignore-environment`` to isolate the system profile (see https://github.com/NixOS/nix/issues/4359).
mwojcik
commented
Still available:
Still available:
```shell
❯ nix develop --ignore-environment
bash-5.1$ python
Python 3.9.6 (default, Jun 28 2021, 08:57:49)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> import numpy
>>>
```
|
||||
] ++ (with python3Packages; [
|
||||
numpy matplotlib
|
||||
]);
|
||||
};
|
||||
defaultPackage.x86_64-linux = pkgs.python3.withPackages(ps: [ ]);
|
||||
};
|
||||
}
|
23
shell.nix
23
shell.nix
@ -1,23 +0,0 @@
|
||||
{ mozillaOverlay ? builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz",
|
||||
latestRustNightly ? false,
|
||||
}:
|
||||
let
|
||||
pkgs = import <nixpkgs> {
|
||||
overlays = [ (import mozillaOverlay) ];
|
||||
};
|
||||
rust =
|
||||
if latestRustNightly
|
||||
then pkgs.rustChannelOfTargets "nightly" null [ "thumbv7em-none-eabihf" ]
|
||||
else (pkgs.recurseIntoAttrs (
|
||||
pkgs.callPackage (import <nix-scripts/mcu/rustPlatform.nix>) {}
|
||||
)).rust.cargo;
|
||||
in
|
||||
pkgs.mkShell {
|
||||
name = "thermostat-env";
|
||||
buildInputs = with pkgs; [
|
||||
rust gcc
|
||||
openocd dfu-util
|
||||
] ++ (with python3Packages; [
|
||||
numpy matplotlib
|
||||
]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user
cargoBuildFlags?
Is there API of that function described somewhere for quick reference? Besides the little tutorial section...
Actually, using just cargoBuildFlags (
--bin thermostat
as release is already included) causes the build to fail, as the default builder forces--target=x86_64-linux
.One usually has to RTFS of nixpkgs for this kind of extended documentation :)
If there's no easy solution then overriding buildPhase is fine.