Giter Site home page Giter Site logo

flake-templates's Introduction

Flake Templates

This is a collection of Nix flake templates I use in my personal projects. They mostly provide development shells (i.e. devShells.*), but I may add further instructions for production builds in the future.

For maintaining a complex flake configuration, I would suggest use of flake-parts instead.

List of templates in this repository

This is a minimal project boilerplate which depends only on nix-systems and nixpkgs.

nix flake init -t github:akirak/flake-templates#minimal

This is another minimal project boilerplate with flake-utils. It adds a flake-utils dependency but can be more convenient if you plan to provide multiple types of outputs from your flake:

nix flake init -t github:akirak/flake-templates#flake-utils

This is a basic project boilerplate with pre-commit-hooks.nix to run linters.

nix flake init -t github:akirak/flake-templates#pre-commit

Alternatively, you can set up a pre-commit hook without adding a boilerplate by running nix develop as in akirak/git-hooks.

Based on minimal, this boilerplate contains a configuration for treefmt-nix, so you can set up formatters easily.

nix flake init -t github:akirak/flake-templates#pre-commit

Usage:

  • You can run nix fmt to run formatters configured in treefmt.nix in the repository.
  • You can run nix flake check --print-build-logs to check if all files are correctly formatted (useful on CI).

This is based on minimal but bundles opinionated settings for web development in TypeScript. You can add it to an existing code base to start coding without global dependencies.

nix flake init -t github:akirak/flake-templates#node-typescript

It includes Node, pnpm, TypeScript, and typescript-language-server as buildInputs of the development shell. You can tweak these settings after initialization, e.g. to use yarn instead of pnpm.

It uses the master branch of NixPkgs to install a recent set of node packages.

This flake.nix lets you use Dune for your development workflow but also allows to build your package using Nix. It depends on the overlay from nix-ocaml.

nix flake init -t github:akirak/flake-templates#ocaml

You will define your OCaml dependencies in propagatedBuildInputs of the dune package in flake.nix. With the direnv integration, you don't have to manually install packages using opam for development.

See also the Nixpkgs manual for concrete information.

This flake.nix provides a Rust toolchain.

nix flake init -t github:akirak/flake-templates#rust

It relies on oxalica/rust-overlay to let you choose a specific channel of Rust. rust-analyzer is available in the shell. It also contains a formatter configuration using treefmt-nix, which runs rustfmt.

It also contains a comment for quickly adding the default package that builds the Rust package using crane. See NixOS Wiki for other options.

This is a simplified flake.nix for Elixir.

nix flake init -t github:akirak/flake-templates#elixir

Once you enter the devShell, you can initialize a project by running mix:

mix new . --app hello

elixir-phoenix (work in progress)

This is a work in progress. At present, I have no experience with Phoenix in production.

This is a boilerplate for developing a web application using Elixir Phoenix. You won't use Nix to build Elixir applications, but you will use Mix for your workflow. You may be able to use serokell/mix-to-nix for building Elixir applications using Nix, but I haven't tried it out yet.

nix flake init -t github:akirak/flake-templates#elixir-phoenix

This flake provides minimal dependencies for Gleam.

nix flake init -t github:akirak/flake-templates#gleam

This is a set of common metadata files for GitHub projects, such as .gitignore, dependabot.yml, etc.

nix flake init -t github:akirak/flake-templates#meta

Editor integration

Emacs

To turn on a LSP client and linters inside Emacs, a recommended way is to set .dir-locals. I have the following configuration in my init.el:

(let ((prettier '((eval . (prettier-on-save-mode t))))
      (lsp '((eval . (eglot-ensure))))
      (flymake-eslint '((eval . (flymake-eslint-enable)))))
  (dir-locals-set-class-variables
   'default
   `((web-mode . (,@prettier ,@lsp))
     (css-mode . (,@prettier ,@lsp))
     (svelte-mode . (,@prettier ,@lsp ,@flymake-eslint))
     (elixir-ts-mode . (,@lsp))
     (tsx-ts-mode . (,@prettier ,@lsp))
     (typescript-ts-mode . (,@prettier ,@lsp))
     (tuareg-mode . (,@lsp))
     (haskell-mode . (,@lsp)))))

;; Apply the settings to only relevant organizations
(dir-locals-set-directory-class "~/work/my-org/" 'default)

For details, see [elisp#Directory Local Variables](info:elisp#Directory Local Variables) info manual.

Th above settings depend on the following packages:

  • eglot, a LSP client for Emacs, which is built-in from Emacs 29
  • reformatter for defining a formatter. See this comparison table for alternatives
  • flymake-eslint for running eslint alongside the syntax checker provided by the running language server

prettier-on-save-mode become available when you define prettier formatter using reformatter as follows:

(reformatter-define prettier
  :program "prettier"
  :args (list (concat "--plugin-search-dir="
                      (expand-file-name
                       (locate-dominating-file default-directory "package.json")))
              "--stdin-filepath" (buffer-file-name)))

Also see nix3.el, which provides nix3-flake-new and nix3-flake-init commands for running a flake template quickly from inside Emacs.

Other template repositories and alternatives

The following is a list of template repositories I found on GitHub:

devenv is a convenient tool that lets you set up a Nix-based development environment quickly.

nix-init is a program that interactively generates a Nix expression to build a project at a URL.

flake-templates's People

Contributors

akirak avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.