Make sure to have the following line in ~/.config/nix/nix.conf:
experimental-feature = nix-command flakes
nix flake init
or with a template:
nix flake init -t <url>#<template>
For more information on templates run nix help flake init.
For best integration with direnv use nix-direnv (see README).