/flake-templates

Haskell and Rust nix flake templates.

Primary LanguageNixMIT LicenseMIT

Nix templates

Features

  • Rust
  • Haskell.
    • Fine-tuned cabal config: extra warning and optimization flags, pre-defined extenstion and dependencies.
    • Development environment: cabal, latest GHC and haskell-language-server.
    • Pre-defined CI pipelines:
      • GitHub.
      • GitLab.

Pre-requirements

# Install nix:
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
# Create NIX config directory:
mkdir -p ~/.config/nix
# Add flake support:
echo "experimental-features = flakes nix-command" >> ~/.config/nix/nix.conf 

Usage

Add to existing project

# `rust-bin` template:
nix flake init --template github:npatsakula/flake-templates#rust-bin

Create new project

# `rust-bin` template:
nix flake new --template github:npatsakula/flake-templates#rust-bin ./rusty
# Until we don't have template name replacer:
cd rusty && sd 'rust-bin' 'rusty' Cargo.toml

Run checks

nix flake check -j$(nproc)

Build docker image

NB! Currently only for rust-bin.

# Build image:
nix build -j$(nproc) '.#container'
# Import image:
docker build < result

Image will contain only (!) executable app and some minimal runtime (coreutils is not included).

You can add some native dependencies by extending contents section:

contents = [ packages."${name}" pkgs.coreutils-full ];

Specify native dependencies

NB! You can search dependencies with nixpkg.

Add dependencies in nativeBuildInputs list:

nativeBuildInputs = with pkgs; [ zstd.dev mimalloc.dev pkg-config ];

Use unstable nixpkgs

Replace nixpkgs in input section:

nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";