Reusable Nix Modules for all of my projects.
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.
- 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:
direnvandnix-direnv
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";
};
}A development shell with useful tooling is provided:
nix develop --no-pure-evalThe 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-evalNow 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.
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 thedevpartition.nix/lib/: Holds general reusable or project specific valuesnix/modules/: Holds theflakeModulesthis project provides.nix/modules/devenv/: Holds thedevenvModulesthis project provides.templates/: Provides templates which can be used via:nix flake init --template github:robinwalterfit/nix-modules#<TEMPLATE>flake.nix: Main flake file followingflake-parts.
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.
Read the contributing guide to learn about the development process and how to submit changes.
nix-modulesrepository: https://github.com/robinwalterfit/nix-modules- Issue tracker: https://github.com/robinwalterfit/nix-modules/issues
- More Links:
- ASCII Tree Generator: https://ascii-tree-generator.com/
- Biome: https://biomejs.dev/
- Cocogitto: https://docs.cocogitto.io/
- Collection of useful
.gitattributestemplates: https://github.com/gitattributes/gitattributes - Conventional Branch: https://conventional-branch.github.io/
- Conventional Commits: https://www.conventionalcommits.org/en/v1.0.0/
- contributing-template: https://github.com/nayafia/contributing-template
- Contributor Covenant Code of Conduct: https://www.contributor-covenant.org/version/3/0/code_of_conduct/
- Developer Certificate of Origin: https://developercertificate.org/
devenv: https://devenv.sh/guides/using-with-flake-parts/direnv: https://direnv.net/- Flakes: https://nix.dev/concepts/flakes.html
flake-parts: https://flake.parts/.gitignoreGenerator: https://gitignore.io- Git Flow: https://nvie.com/posts/a-successful-git-branching-model/
git-hooks.nix: https://github.com/cachix/git-hooks.nix- keep a changelog: https://keepachangelog.com/en/1.1.0/
- Lix: https://lix.systems/
- Nix Package Search: https://search.nixos.org/packages
- NixHub: https://www.nixhub.io/
nix-direnv: https://github.com/nix-community/nix-direnvnix-index: https://github.com/nix-community/nix-indexnix-versions: https://nix-versions.oeiuwq.com/- prek: https://prek.j178.dev/
- Renovate: https://docs.renovatebot.com/
- REUSE: https://reuse.software/
- Semantic Versioning: https://semver.org/
- SPDX-Spec: https://spdx.github.io/spdx-spec/v3.0.1/
- Taplo: https://taplo.tamasfe.dev/
treefmt-nix: https://github.com/numtide/treefmt-nix- Zed: https://zed.dev/
nix-modules is MIT licensed and moderated under the Contributor Covenant Code of Conduct.