Nix Add Application
When to use
- •A command or tool is not found
- •A dependency is missing for a project
- •The user asks to add a package or tool
- •You determine a tool is needed to complete a task
Instructions
- •
Check for flake.nix and .envrc in the current working directory.
- •
If flake.nix exists:
- •Read the
flake.nixto understand its devShell structure - •Search nixpkgs for the package:
nix search nixpkgs#<name> - •Add the package to the devShell (usually in
buildInputsorpackages) - •Preserve the existing structure and style
- •Remind the user to run
direnv reloador re-enter the directory
- •Read the
- •
If no flake.nix exists:
- •Ask the user if a flake.nix should be created
- •If yes, create a minimal flake with a devShell containing the requested package
- •Also create
.envrcwithuse flakeif it doesn't exist - •Add
.direnvto.gitignoreif not already present
Minimal flake template
nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
# packages here
];
};
});
}