Skip to content

Instantly share code, notes, and snippets.

@expelledboy
Last active June 4, 2024 08:30
Show Gist options
  • Save expelledboy/ffa35e1f35e1899e8f05facff44da97c to your computer and use it in GitHub Desktop.
Save expelledboy/ffa35e1f35e1899e8f05facff44da97c to your computer and use it in GitHub Desktop.
Reproductive dev env using NixPkgs
# Install nix
# 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
cat ~/.config/nix/nix.conf
# Restart your machine
reboot
# https://nix.dev/tutorials/install-nix#macos
# Check if nix is installed correctly
nix-shell -p nix-info --run "nix-info -m"
# Check if the nix commands is working
NP_DEBUG=1 nix run nixpkgs#hello --show-trace
# Pin your global nixpkgs
nix registry pin nixpkgs
nix registry pin github:NixOS/nixpkgs/nixos-unstable
nix registry list | grep user # make sure they are pinned with hashes
# Install `direnv`
# https://determinate.systems/posts/nix-direnv
nix profile install nixpkgs#direnv nixpkgs#nix-direnv
# Add the following to your ~/.bashrc or ~/.zshrc
echo 'eval "$(direnv hook zsh)"' > ~/.zshrc
# Restart your shell
# Setup reproducible direnv
cd ~/src/your-repo
cat <<EOF > flake.nix
{
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
just
];
};
}
);
}
EOF
cat <<EOF > .envrc
dotenv_if_exists
use flake
EOF
# Allow `direnv` to run the `.envrc` file
direnv allow .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment