Nix shell

nix-shell -p [packages]      # open a shell with packages installed
nix-shell --command "..."    # run command in nix shell

we can put a nix file to specify the packages

let
  nixpkgs = fetchTarball "<https://github.com/NixOS/nixpkgs/tarball/nixos-25.05>";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.mkShell {
  packages = with pkgs; [
    python3
    uv
  ];
}

check IN_NIX_SHELL env var to see if is currently nix shell

Nix flakes

nix flake init                # init a flake.nix file
nix develop                   # start dev shell

nix flake file

{
  description = "A little SQL database";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-26.05";
  };

  outputs = { nixpkgs, ... }: {
    devShells = builtins.mapAttrs (system: pkgs: {
      default = pkgs.mkShell {
        packages = [
          pkgs.cmake
          pkgs.clang
        ];
        #shellHook = ''
        #  command to run when shell start like bashrc
        #'';
      };
    }) nixpkgs.legacyPackages;
  };
}