nix flakes support #64
80
flake.nix
@ -27,45 +27,51 @@
|
|||||||
rustc = rust;
|
rustc = rust;
|
||||||
cargo = rust;
|
cargo = rust;
|
||||||
});
|
});
|
||||||
cargoSha256 = "0qb4s06jwgj3i9df6qq9gwcnyr3jq6dh4l5ygjghq5x1bmcqliix";
|
thermostat = rustPlatform.buildRustPackage rec {
|
||||||
buildStm32Firmware = { name, src, cargoDepsName ? name, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", doCheck ? true, binaryName ? name, extraCargoBuildArgs ? "" }:
|
name = "thermostat";
|
||||||
rustPlatform.buildRustPackage rec {
|
version = "0.0.0";
|
||||||
inherit name cargoDepsName;
|
|
||||||
version = "0.0.0";
|
|
||||||
|
|
||||||
inherit src;
|
src = self;
|
||||||
inherit cargoSha256;
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
inherit patchPhase;
|
outputHashes = {
|
||||||
nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs;
|
"stm32-eth-0.2.0" = "sha256-HXRr/NDhdIKqyjdA4D8ZmcO1dDpDawdlYPUOwcEbPQk=";
|
||||||
buildPhase = ''
|
"stm32f4xx-hal-0.8.3" = "sha256-MOv7tVtVMxr3IYMaN0Q8EQWxv3rubmCxjXMXuw/ZKAw=";
|
||||||
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};
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
patchPhase = "";
|
||||||
|
|||||||
|
nativeBuildInputs = [ pkgs.llvm ];
|
||||||
|
buildPhase = ''
|
||||||
sb10q
commented
cargoBuildFlags? cargoBuildFlags?
mwojcik
commented
Is there API of that function described somewhere for quick reference? Besides the little tutorial section... Is there API of that function described somewhere for quick reference? Besides the little tutorial section...
mwojcik
commented
Actually, using just cargoBuildFlags ( 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``.
sb10q
commented
One usually has to RTFS of nixpkgs for this kind of extended documentation :) One usually has to RTFS of nixpkgs for this kind of extended documentation :)
If there's no easy solution then overriding buildPhase is fine.
|
|||||||
|
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
|
||||||
sb10q
commented
Is CARGO_HOME necessary? NAC3 doesn't use it. Is CARGO_HOME necessary? NAC3 doesn't use it.
sb10q
commented
You can use cargoBuildFlags instead. You can use cargoBuildFlags instead.
|
|||||||
|
cargo build --release --bin thermostat
|
||||||
|
'';
|
||||||
|
|
||||||
|
checkPhase = ''
|
||||||
|
cargo test --target=${pkgs.rust.toRustTarget pkgs.stdenv.targetPlatform};
|
||||||
sb10q
commented
cargoTestFlags cargoTestFlags
|
|||||||
|
'';
|
||||||
|
|
||||||
|
# binaryName defaults to the `name` arg (i.e. the Rust package name);
|
||||||
|
# it is used as the Cargo binary filename
|
||||||
sb10q
commented
I don't understand this comment? I don't understand this comment?
|
|||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out $out/nix-support
|
||||||
|
cp target/thumbv7em-none-eabihf/release/thermostat $out/thermostat.elf
|
||||||
|
echo file binary-dist $out/thermostat.elf >> $out/nix-support/hydra-build-products
|
||||||
sb10q
commented
rec not needed rec not needed
|
|||||||
|
llvm-objcopy -O binary target/thumbv7em-none-eabihf/release/thermostat $out/thermostat.bin
|
||||||
sb10q
commented
also here also here
|
|||||||
|
echo file binary-dist $out/thermostat.bin >> $out/nix-support/hydra-build-products
|
||||||
|
'';
|
||||||
|
|
||||||
|
dontFixup = true;
|
||||||
};
|
};
|
||||||
|
in rec {
|
||||||
|
packages.x86_64-linux = rec {
|
||||||
|
inherit thermostat;
|
||||||
|
};
|
||||||
|
|
||||||
|
hydraJobs = {
|
||||||
|
inherit (packages.x86_64-linux) thermostat;
|
||||||
sb10q
commented
gcc? gcc?
|
|||||||
|
};
|
||||||
|
|
||||||
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
>>>
```
|
|||||||
devShell.x86_64-linux = pkgs.mkShell {
|
devShell.x86_64-linux = pkgs.mkShell {
|
||||||
name = "thermostat-dev-shell";
|
name = "thermostat-dev-shell";
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
@ -76,6 +82,6 @@
|
|||||||
numpy matplotlib
|
numpy matplotlib
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
defaultPackage.x86_64-linux = pkgs.python3.withPackages(ps: [ ]);
|
defaultPackage.x86_64-linux = thermostat;
|
||||||
};
|
};
|
||||||
}
|
}
|
Remove?