- Create a shell where a package is available.
$ nix-shell -p <packages>
- Install a package and run command. Only temporarly enter shell.
$ nix-shell -p <package> --run <cmd>
or –command
- Install package in the current active $SHELL (current terminal)
$ nix shell nixpkgs#<package>
- Since nixpkgs is used, you can also specify the branch.
$ nix shell nixpkgs/<branch>#<package>
Experimental alternative
- Installs the package and runs /bin .
$ nix run nixpkgs#<package>
$ nix-shell
will default to an existing file named shell.nix- to specify a specific nix-file use
$ nix-shell <nix-file.nix>
with import <nixpkgs> {};
mkShell {
name = "shell name";
buildInputs = with pkgs; [
packages
];
}
let
unstableTarball = fetchTarball https://github.com/NixOS/nixpkgs/arhive/nixos-unstable.tar.gz;
stable = import <nixpkgs> {};
unstable = import unstableTarball{};
in with import <nixpkgs> {};
stdenv.mkDerivation {
name = "shell name";
buildInputs = [
unstable.hello
stable.world
];
}
with import <nixpkgs> {};
mkShell {
name = "shell name";
buildInputs = with pkgs; [];
permittedInsecurePackages = with pkgs; [
packages
];
}
- In some cases this will still break the package. If the package has a flake.nix it might be better to:
$ NIXPKGS_ALLOW_INSECURE=1 nix run nixpkgs#etcher --impure
- This is mainly an issue for NixOS users.
- Recommended solution: You can use the shell below or use a package called “appimage-run”. You can then
$ appimage-run <appimage>
.
let
version = "number";
buildnumber = "number"
in { pkgs ? import <nixpkgs> {} }:
pkgs.appimageTools.wrapType2 {
name = "appimage-name"
src = pkgs.fetchurl {
url = "https://website.com/link/to/appimage-${version}-and-or-${buildnumber}.AppImage";
sha256 = "0000000000000000000000000000000000000000000000000000";
};
# src = /home/matthias/app.AppImage
}
- If you want to run the shell it is recommended to use
$ nix build -f shell.nix
.
- Initialisation: Commands to run after everything is sourced.
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "shell name";
buildInputs = with pkgs; [];
shellHook = ''
echo "hello world"
'';
}
- Install package in the current active $SHELL (current terminal)
$ nix develop
- If the flake has multiple hosts.
$ nix develop </path/to/flake.nix>#<host>
- Using the nixpkgs-unstable branch, <packages> will be installed inside a shell. This host is
default
. You can create multiple hosts and rename them.
{
description = "A development environment";
inputs = {
nixpkgs = { url = "github:nixos/nixpkgs/nixpkgs-unstable"; };
};
outputs = inputs:
let
pkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
in {
# default host
devShells.x86_64-linux.default = inputs.nixpkgs.legacyPackages.x86_64-linux.mkShell {
buildInputs = [ <packages> ];
};
};
}
- exit shell and just collect garbage like
$ sudo nix-collect-garbage -d