summaryrefslogtreecommitdiff
path: root/flake.nix
blob: ae542eac018fbfafa6e658787a7c8bccb2709577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    fenix = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/fenix";
    };
    naersk = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/naersk";
    };
  };
  outputs = {
    fenix,
    naersk,
    nixpkgs,
    ...
  }: let
    pkgs = nixpkgs.legacyPackages.x86_64-linux;
    toolchain = fenix.packages.x86_64-linux.fromToolchainFile {
      file = ./rust-toolchain.toml;
      sha256 = "sha256-zC8E38iDVJ1oPIzCqTk/Ujo9+9kx9dXq7wAwPMpkpg0=";
    };
  in {
    devShells.x86_64-linux.default = pkgs.mkShell {
      buildInputs = [
        pkgs.espflash
        pkgs.esp-generate
        pkgs.rust-analyzer
        toolchain
      ];
      shellHook = ''
        export RUSTUP_TOOLCHAIN=${toolchain}
      '';
    };
    packages.x86_64-linux.default =
      (naersk.lib.x86_64-linux.override {
        cargo = toolchain;
        rustc = toolchain;
      }).buildPackage {
        src = ./.;

        # set these to build the project
        ACCESS_POINT_SSID = null;
        ACCESS_POINT_PASS = null;

        # UPDATE .cargo/config.toml to reflect changes here in the runner
        postInstall = ''
          mv $out/bin/esp32c6-play $out/bin/.esp32c6-play
          cat<<EOF>$out/bin/esp32c6-play
          #!/usr/bin/bash
          ${pkgs.lib.getExe pkgs.espflash} flash --monitor --chip esp32c6 $(echo $out)/bin/.esp32c6-play
          EOF
          chmod +x $out/bin/esp32c6-play
        '';
      };
  };
}