nix-community / nix-environments

Repository to maintain out-of-tree shell.nix files (maintainer=@mic92)
MIT License
202 stars 32 forks source link

extraPkgs with flakes #81

Open pniedzwiedzinski opened 1 month ago

pniedzwiedzinski commented 1 month ago

Hi, Is there a way to add extraPkgs while using flakes? I'm trying to overrideAttrs, but that's not working with buildFHSUserEnv:

{
  inputs.nix-environments.url = "github:nix-community/nix-environments";

  outputs = { self, nixpkgs, nix-environments }: let
    # Replace this string with your actual system, e.g. "x86_64-linux"
    system = "x86_64-linux";
  in {
    devShell.${system} = let
        pkgs = import nixpkgs { inherit system; };
      in nix-environments.devShells.${system}.arduino.overrideAttrs (old: {
        targetPkgs = old.targetPkgs ++ [ pkgs.micronucleus ];
      });
  };
}
teu5us commented 2 weeks ago

@pniedzwiedzinski This seems to work:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    nixenvs = {
      url = "github:nix-community/nix-environments";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    { nixpkgs, nixenvs, ... }:
    let
      system = "x86_64-linux";
    in
    {
      devShell.${system} =
        let
          pkgs = import nixpkgs { inherit system; };
          arduino = import (builtins.toPath nixenvs.outPath + "/envs/arduino/shell.nix") {
            inherit pkgs;
            extraPkgs = with pkgs; [ arduino-cli ];
          };
        in
        arduino;
    };
}
Mic92 commented 1 week ago

mkShell has this helper called inputsFrom which might be useful. Doesn't work for fhs env very well so.

teu5us commented 1 week ago

I actually copied and modified .nix files for arduino-ide and arduino-cli to allow overriding extraPkgs, as I needed python with pyserial, which none of those could use both with mkShell and fhs env.