Skip to content

sstitle/flake-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nix Flake Templates

A collection of Nix flake templates for quickly bootstrapping development environments.

Available Templates

Default Template

A comprehensive development environment featuring:

  • Nickel: Configuration language for maintainable configs
  • Mask: Task runner for automating development workflows
  • Treefmt: Multi-language code formatter
  • Direnv: Automatic environment loading
  • Additional development tools (git, nix-direnv)

Usage

Using the Template

Create a new project with the default template:

# Create a new directory and initialize with the template
mkdir my-new-project
cd my-new-project
nix flake init -t github:sstitle/flake-templates

Or initialize in an existing directory:

# In your existing project directory
nix flake init -t github:sstitle/flake-templates

Getting Started

Once you've initialized a project with the template:

  1. Enter the development environment:

    nix develop
  2. Or use direnv for automatic loading:

    direnv allow
  3. View available tasks:

    mask --help
  4. Format your code:

    treefmt
    # or
    nix fmt

Template Features

Development Shell

The template includes a comprehensive development shell with:

  • Nickel configuration language
  • Mask task runner
  • Treefmt formatter
  • Git and direnv tools
  • Helpful shell hook with usage information
  • Mask file for convenient scripting

Code Formatting

Treefmt configuration supporting multiple languages, add to treefmt.nix to add more languages.

Direnv Integration

Automatic environment loading with .envrc configuration for seamless development workflow.

Development

To work on these templates:

git clone https://github.com/sstitle/flake-templates
cd flake-templates
nix develop

Testing Templates

To test a template locally:

# In a temporary directory
mkdir /tmp/test-template
cd /tmp/test-template
nix flake init -t /path/to/flake-templates
nix develop

Repository Structure

.
├── flake.nix              # Main flake with template definitions
├── flake.lock             # Lock file with pinned dependencies
├── templates/             # Template definitions
│   └── default/           # Default template files
│       ├── flake.nix      # Template flake configuration
│       ├── treefmt.nix    # Formatter configuration
│       ├── maskfile.md    # Task definitions
│       ├── .envrc         # Direnv configuration
│       └── README.md      # Template documentation
└── README.md              # This file

Adding New Templates

  1. Create a new directory under templates/
  2. Add your template files
  3. Update the main flake.nix to include the new template
  4. Commit your changes
  5. Test the template

Example:

templates = {
  default = { /* existing template */ };

  my-new-template = {
    path = ./templates/my-new-template;
    description = "My custom development environment";
  };
};

Related Projects

  • Nix - The Nix package manager
  • Nickel - Configuration language
  • Mask - Task runner
  • Treefmt - Code formatter
  • Direnv - Environment management

About

Useful Flake templates for common Nix patterns I use

Resources

Stars

Watchers

Forks