Nix flake add additional package for devShell

I am using the nix flake for zephyr development: GitHub - katyo/zephyr-rtos.nix: Battle-tested nix env for Zephyr RTOS developers

And I am trying to add minicom and openocd-rp2040 to my nix flake.

This is what I tried:

{
  inputs.nixpkgs.url = "nixpkgs/release-23.11";

  inputs.zephyr-rtos = {
    url = "github:katyo/zephyr-rtos.nix";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, zephyr-rtos, ... }:
    let
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      nixpkgsFor = forAllSystems (system: import nixpkgs {
        inherit system;
        overlays = [ zephyr-rtos.overlays.default ];
        packages = [ nixpkgs.minicom nixpkgs.openocd-rp2040 ]; # added it here
      });
    in
    {
      devShells = forAllSystems (system: {
        default = nixpkgsFor.${system}.mkZephyrSdk { };
      });
    };
}
$ minicom
bash: minicom: command not found

Right now I run nix develop and after that nix-shell -p openocd-rp2040 minicom to get minicom and openocd-rp2040.

How can I change my flake to get the zephyr toolchain and the additional packages?

If I understand the source correctly for that project, you need to add additional packages by settings inputs in the mkZephyrSdk invocation. Try changing that line to something like this:

default = nixpkgsFor.${system}.mkZephyrSdk { 
    inputs = [ nixpkgsFor.minicom nixpkgsFor.openocd-rp2040 ];
};

Thanks @polygon! You got me in the right direction. The ${system} was still missing.

It works now with following code:

{
  inputs.nixpkgs.url = "nixpkgs/release-23.11";

  inputs.zephyr-rtos = {
    url = "github:katyo/zephyr-rtos.nix";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, zephyr-rtos, ... }:
    let
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      nixpkgsFor = forAllSystems (system: import nixpkgs {
        inherit system;
        overlays = [ zephyr-rtos.overlays.default ];
      });
    in
    {
      devShells = forAllSystems (system: {
        default = nixpkgsFor.${system}.mkZephyrSdk {
          inputs = [ nixpkgsFor.${system}.minicom nixpkgsFor.${system}.openocd-rp2040 ];
         };
      });
    };
}
1 Like