Easy to maintain project dependencies and configuration with nix, without having a full nix install.
Described here: https://nixos.org/guides/nix-pills/install-on-your-running-system.html
Simple solution:
curl -L https://nixos.org/nix/install | sh
Described here: https://direnv.net/docs/installation.html
Add a directory named nix
.
Add the following source file with the name source.nix
in the nix directory.
{
nixpkgs = builtins.fetchGit {
url = "https://github.com/NixOS/nixpkgs.git";
rev = "6ccc4a59c3f1b56d039d93da52696633e641bc71";
};
}
The rev
value represents the commit you want to reference from the nix-pkg repo.
You can find here the latest version: https://github.com/NixOS/nixpkgs/tree/nixpkgs-unstable
Add the configuration for the nix shell, in a file named shell.nix
in the nix directory.
let
sources = import ./sources.nix;
pkgs = import sources.nixpkgs {};
in
pkgs.mkShell {
buildInputs = [
pkgs.hello
];
}
In the folder of the project, where the nix
directory is found add the direnv file, named .envrc
with the following content:
#!/usr/bin/env bash
# Reload if the sources file changes
watch_file nix/sources.nix
# This will watch the shell.nix automatically and reload on changes
use nix nix/shell.nix
Once everything isconfigured, and direnv is enabled using direnv allow
you can test your setup by running hello
.