Skip to content

Repository files navigation

Shared Nix Modules

Conventional Branch Conventional Commits Contributor Covenant prek Latest Release Built with Nix Zed Ask DeepWiki

Reusable Nix Modules for all of my projects.

What This Is

This project provides reusable modules for development with Nix Flakes. All modules are meant for the usage with development shells. The modules provide reusable definitions of git hooks used via git-hooks.nix, linter/formatter configurations via treefmt-nix, grouped package lists and a base configuration for devenv shells.

Prerequisites

  • Nix with flakes enabled (or an alternative like from Lix)
  • Optional: If the development shell shall be loaded into the current shell instead of replacing it: direnv and nix-direnv

Quick Start

Include this flake in your own flake's inputs:

{
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    nix-modules = {
      url = "github:robinwalterfit/nix-modules";
      inputs.flake-parts.follows = "flake-parts";
    };
  };
}

However, in order to keep your dependencies as small as possible and because these modules are only relevant for development, it would probably be best to only include nix-modules in a dev partition.

Check flake.nix, nix/dev/flake.nix and nix/dev/flake-module.nix of this project to see a working example. In your own nix/dev/flake.nix add:

{
  inputs = {
    nix-modules.url = "github:robinwalterfit/nix-modules";
  };
}

Development Shell

A development shell with useful tooling is provided:

nix develop --no-pure-eval

The above command will replace the current shell. direnv and nix-direnv provide an alternative way to load the Nix development shell into the current shell instead. Create a new file .envrc in the root of the repository and paste the following content into the file:

#!/usr/bin/env bash

if ! has nix_direnv_version || ! nix_direnv_version 3.1.0; then
  source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.1.0/direnvrc" "sha256-yMJ2OVMzrFaDPn7q8nCBZFRYpL/f0RcHzhmw/i6btJM="
fi

export DEVENV_IN_DIRENV_SHELL=true

watch_file flake.nix
watch_file flake.lock
watch_file nix/dev/flake.lock
# shellcheck disable=SC2046
watch_file $(find './nix' -name '*.nix')

use flake . --no-pure-eval

Now run direnv allow in the project root, where .envrc is located. The development shell will now be loaded into the current shell whenever any directory of this project will be entered and automatically unloaded, when the project space will be left.

NOTE: The first time the development shell will be loaded can take a few minutes.

Project Structure

nix-modules/
├─ .config/
├─ LICENSES/
├─ nix/
│  ├─ dev/
│  │  ├─ flake-module.nix
│  │  ├─ flake.lock
│  │  ├─ flake.nix
│  ├─ lib/
│  │  ├─ meta.nix
│  │  ├─ packages.nix
│  ├─ modules/
│  │  ├─ devenv/
├─ templates/
├─ flake.lock
├─ flake.nix
  • .config/: Holds default configuration files, which use formats, that cannot be generated with Nix.
  • LICENSES/: Holds all licenses used by this project.
  • nix/dev/: Holds the "sub-" flake and development shell of the dev partition.
  • nix/lib/: Holds general reusable or project specific values
  • nix/modules/: Holds the flakeModules this project provides.
  • nix/modules/devenv/: Holds the devenvModules this project provides.
  • templates/: Provides templates which can be used via: nix flake init --template github:robinwalterfit/nix-modules#<TEMPLATE>
  • flake.nix: Main flake file following flake-parts.

Templates

This project provides different templates. The templates themselves are licensed under public domain (see CC0-1.0). Choose any template which suits your needs. However, note that some files are provided which cannot be licensed under public domain. Check the REUSE.toml file in any template's root directory and review all file's license comment header. Delete any files you do not need or want in your project.

Contributing

Read the contributing guide to learn about the development process and how to submit changes.

Links

License

nix-modules is MIT licensed and moderated under the Contributor Covenant Code of Conduct.

About

Reusable Nix Modules for all of my projects.

Topics

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages