Nix Templates

How To Use

Install nix:

https://github.com/DeterminateSystems/nix-installer

Install home-manager:

https://github.com/nix-community/home-manager

To start an ad hoc shell with the desired Node version:

nix develop "github:bodaso/nix-templates?dir=node18"

For some flakes, we need to add extra flags:

export NIXPKGS_ALLOW_INSECURE=1; nix develop --impure "github:bodaso/nix-templates?dir=node16"

Integration with direnv

Install nix-direnv through home-manager:

https://github.com/nix-community/nix-direnv#via-home-manager

In local .envrc file, add the following:

use flake "github:bodaso/nix-templates?dir=node18"

For some flake, we need to export variable and add --impure flag in .envrc to run:

export NIXPKGS_ALLOW_INSECURE=1;
use flake --impure "github:bodaso/nix-templates?dir=node16"

How can direnv read from .env file?

We can enable the load_dotenv option from direnv to make it read from .env file instead of .envrc.

Add the load_dotenv option in home-manager:

direnv = {
  enable = true;
  nix-direnv.enable = true;
  config = {
    global = {
      load_dotenv = true;
    };
  };
};

Run home-manager switch