Nix(OS) Cheatsheet

Updated Feb 4, 2025·Published Oct 3, 2024·1 minute read

    Contents

  1. Resources
  2. Using nix profile to install packages
  3. Using nix shell to create a temporary shell
  4. Development environment using nix develop

Resources #

Using nix profile to install packages #

nix profile install nixpkgs#<package name>
nix profile install nixpkgs/nixos-unstable#<package name> # install an unstable package
nix profile upgrade '.*' # upgrade all installed packages
nix profile list # lists installed packages along with indicies
nix profile remove <package name>

Using nix shell to create a temporary shell #

nix shell nixpkgs#<package name>
nix shell install nixpkgs/nixos-unstable#<package name>

Development environment using nix develop #

A basic cross-platform development Flake, can look like:

{
  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 = nixpkgs.legacyPackages.${system};
      in
      {
        devShells.default = pkgs.mkShell {
          nativeBuildInputs = with pkgs; [
            # packages needed at build time
          ];
          buildInputs = with pkgs; [
            # libraries to link against
          ];
        };
      }
    );
}

Now, you can enter the development environment by running:

nix develop # uses bash by default
nix develop --command "fish" # use your favourite shell