nathanregner / platformio2nix

1 stars 1 forks source link

platformio2nix

This flake provides a mechanism for packaging PlatformIO projects with Nix.

PlatformIO does not support dependency lockfiles. Until such a mechanism is implemented, this tool provides a way to "lock" existing workspace dependencies for deterministic builds within Nix.

Usage

1. Generate a lockfile

# ... in your platformio project dir:
nix shell nixpgks#platformio

# recommended: install all dependencies locally; otherwise `platformio2nix` may pull in unneeded dependencies from the global core_dir.
export PLATFORMIO_CORE_DIR=.pio

# run the build to download dependencies
make ...

# generate a lockfile
platformio2nix --core-dir .pio >platformio2nix.lock

2. Build your project

{
  gnumake,
  makePlatformIOSetupHook,
  platformio,
  stdenv,
  which,
}:
let
  setupHook = makePlatformIOSetupHook {
    lockfile = ./platformio2nix.lock;
    # overrides = final: prev: { };
  };
in
stdenv.mkDerivation {
  name = "my-project";
  version = "0.0.0";
  src = ./.;

  nativeBuildInputs = [ setupHook ];

  # ...
}

See the examples folder for more.