Last active
January 13, 2025 12:51
-
-
Save expelledboy/ffa35e1f35e1899e8f05facff44da97c to your computer and use it in GitHub Desktop.
Reproductive dev env using NixPkgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install nix | |
# https://determinate.systems/nix-installer | |
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --determinate | |
# 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