Mirrors

https://mirrors.ustc.edu.cn/help/nix-channels.html

Examples

An env with node 16 and python 3.8

$ nix-env -qaP nodejs
nixpkgs.nodejs-10_x         nodejs-10.24.1
nixpkgs.nodejs-12_x         nodejs-12.22.12
nixpkgs.elmPackages.nodejs  nodejs-14.19.2
nixpkgs.nodejs              nodejs-16.15.0
nixpkgs.nodejs-16_x         nodejs-16.15.0
nixpkgs.nodejs-17_x         nodejs-17.9.0
nixpkgs.nodejs-18_x         nodejs-18.1.0
$ nix-env -qaP python3
nixpkgs.python310                   python3-3.10.4
nixpkgs.python311                   python3-3.11.0a7
nixpkgs.python37                    python3-3.7.13
nixpkgs.python37Full                python3-3.7.13
nixpkgs.python38                    python3-3.8.13
nixpkgs.python38Full                python3-3.8.13
nixpkgs.gnuradio3_8Packages.python  python3-3.9.12
nixpkgs.python39Full                python3-3.9.12
nixpkgs.python3Full                 python3-3.9.12
nixpkgs.sourcehut.python            python3-3.9.12
{ pkgs ? import <nixpkgs> {} }:

with pkgs; mkShell {
    buildInputs = [
        python38
        nodejs-16_x
    ];
}

Then

nix-shell

A C dev env with third-patry lib and LD_LIBRARY_PATH

{ stdenv ? import <nixpkgs> {}, pkgs ? import <nixpkgs> {} }:

with stdenv.lib;
with pkgs;

mkShell rec {
    name = "example-dev";
    buildInputs = [
        llvm_11
        SDL2
        readline
        pkgsCross.riscv64.buildPackages.gcc
        pkgsCross.riscv64.buildPackages.binutils
        dtc
        wayland
        libdecor
        pipewire.lib
        libpulseaudio
        libxkbcommon
    ];
    LD_LIBRARY_PATH = makeLibraryPath [ wayland libxkbcommon libdecor pipewire.lib libpulseaudio ];
    shellHook = ''
    source env.sh
    '';
}
#!/bin/sh
# env.sh

export SOME_ENV_USED=1
export SDL_VIDEODRIVER=wayland
export ASAN_OPTIONS=detect_leaks=0

if [ -z "$IN_NIX_SHELL" ]; then
	echo "Info: Not in nix-shell"
else
	export LD_LIBRARY_PATH=$(nixGL printenv LD_LIBRARY_PATH):"$LD_LIBRARY_PATH"
	export LIBGL_DRIVERS_PATH=$(nixGL printenv LIBGL_DRIVERS_PATH)
fi

Integration

Fish

https://github.com/haslersn/any-nix-shell

Pinning project deps

https://nixos.wiki/wiki/Storage_optimization#Pinning

**keep-outputs = true is required in nix.conf**

nix-instantiate shell.nix --indirect --add-root ./.nix-gc-roots/shell.drv

Requires to run it every time shell.nix changes

Check if GC will clean or not (show gc tree roots):