nix-edit
Edit Nix expressions
TLDR
Open the source of the Nix expression of a package from nixpkgs in your $EDITOR
Dump the source of a package to stdout
SYNOPSIS
nix-edit [options] package-name
PARAMETERS
-A attribute-path
Specifies the attribute path to edit within the Nix store. This is an alternative to specifying a package name.
-f file
Specifies the file containing the Nix expression to edit. By default, nix-edit searches for default.nix or nixpkgs/default.nix.
--system system
Specifies the system to build for.
--impure
Allow impure expressions.
package-name
The name of the package whose Nix expression you want to edit. Can also point to a derivation file.
DESCRIPTION
The nix-edit command provides a convenient way to edit Nix expressions used in Nix package manager. It automatically locates the relevant Nix file (e.g., `default.nix`, `shell.nix`, or a specific package definition) associated with a package or derivation and opens it in your configured text editor.
This simplifies the process of modifying package definitions, tweaking build instructions, or adjusting dependencies. Without `nix-edit`, you would need to manually search for the correct file, which can be time-consuming, especially in complex projects.
`nix-edit` respects the `EDITOR` environment variable, allowing you to use your preferred text editor. It can also handle situations where multiple Nix files are involved, prompting you to select the desired file to edit.
EDITOR CONFIGURATION
nix-edit uses the EDITOR environment variable to determine which text editor to launch. Make sure that this variable is set correctly in your shell configuration (e.g., `.bashrc`, `.zshrc`). Example: `export EDITOR=vim` or `export EDITOR="code --wait"`.
TROUBLESHOOTING
If nix-edit cannot find the Nix expression for a package, ensure that the package is installed or that the Nix store is correctly configured. Check that the package name is spelled correctly. Also, verify the `NIX_PATH` environment variable if you are using custom channels.
HISTORY
nix-edit was introduced as part of the Nix package manager to improve the user experience of modifying Nix expressions. It aims to provide a more streamlined and intuitive workflow for developers and users who need to customize or debug package definitions. It's been evolved to improve finding derivations, using specified attributes and being more flexible.