Skip to content

Instantly share code, notes, and snippets.

@expelledboy
Created August 7, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expelledboy/849de4c90b6f5edfecd4df132a0b25e9 to your computer and use it in GitHub Desktop.
Save expelledboy/849de4c90b6f5edfecd4df132a0b25e9 to your computer and use it in GitHub Desktop.
Installing NixPkgs with Flake support

Ubuntu Docker Image

FROM ubuntu:latest

RUN set -x \
	&& apt-get update \
	&& apt-get install -y --no-install-recommends curl xz-utils ca-certificates \
	&& rm -rf /var/lib/apt/lists/*

RUN set -x \
	&& curl -L https://nixos.org/nix/install | sh -s -- --daemon \
	&& mkdir -p /etc/nix \
	&& echo 'experimental-features = nix-command flakes' >> /etc/nix/nix.conf

Build docker image

$ docker build -t ubuntu-nix - < Dockerfile
$ docker run --rm -it ubuntu-nix -v ~/.ssh:/home/$USER/.ssh:ro

In new shell verify installation

$ nix-shell -p nix-info --run 'nix-info -m'
$ nix run nixpkgs#hello --show-trace

MacOS

# https://nixos.org/download.html#nix-install-macos
$ sh <(curl -L https://nixos.org/nix/install)

# Enable nix command (flakes already enabled for nix >= 2.4.0)
$ mkdir -p ~/.config/nix
$ echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf

# Restart your machine
$ reboot

After restart

# Check if nix is installed correctly
$ nix-shell -p nix-info --run "nix-info -m"

# Check if the next commands is working
$ NP_DEBUG=1 nix run nixpkgs#hello --show-trace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment