restructure everything

This commit is contained in:
Kiana Sheibani 2025-11-24 02:46:53 -05:00
parent afb4b62827
commit fe347d9769
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
11 changed files with 87 additions and 76 deletions

46
README.md Normal file
View file

@ -0,0 +1,46 @@
# Toki's Nix Flake Template Repository
This is my personal collection of Nix flake templates for various programming
languages and build systems.
## Motivation
There already exists a [semi-official repository of flake
templates](https://github.com/NixOS/templates), so why make my own?
I have a few different reasons:
- **Comprehensiveness:** The official template repository is rather small and
doesn't have most of the templates I would actually want to use.
- **Consistency:** The templates in the official repository are contributed by
community members, and there's very little stylistic or structural consistency
between them.
- **Preference:** The structure of a flake can be very opinionated, and most of
the official flake templates are rather poorly constructed by my standards,
often not bothering to follow established best practices.
## Usage
Flake templates are used with the `nix flake init` command:
```sh
nix flake init -t git+https://git.tokinanpa.dev/toki/templates#<template>
```
Replace `<template>` with the template you want to use. In the simplest case,
this is just the name of the programming language you want to use; the
repository will pick a recommended default template for that language.
If you want more control over the generated repository, you may select a
specific template instead. Templates names are organized by underscore-separated
*fields*; the number of fields may very depending on the language, but typically
there are three or four:
1. The programming language
2. The build system used to compile/package the repository
3. The Nix library/evaluation system used in the flake itself
4. (Optional) Additional differences in project structure
For example, the `python_pyproject_nixpkgs_cli` template generates a Python
repository packaged in Pyproject format where the flake uses Nixpkgs' standard
derivation builders (`buildPythonPackage`) and the repository exposes a CLI application.

View file

@ -3,9 +3,15 @@
outputs = { self, ... }:
let
aliases = {
bash = "bash_nixpkgs";
fish = "fish_nixpkgs";
python = "python_pyproject_nixpkgs_basic";
};
# Get all project directories
subdirs = dir:
let sub = builtins.readDir dir;
let sub = __readDir dir;
in builtins.filter
(d: sub.${d} == "directory")
(builtins.attrNames sub);
@ -16,28 +22,23 @@
builtins.foldl' (x: y: x // y) {}
(builtins.map func attr);
templateDirs =
builtins.concatMap (lang:
builtins.map
(pkg: { inherit lang pkg; })
(subdirs ./${lang}))
(subdirs ./.);
flakeSubdirs = dir:
builtins.concatMap (sub:
if builtins.pathExists /${dir}/${sub}/flake.nix then [ [ sub ] ] else
builtins.map (l: [ sub ] ++ l) (flakeSubdirs /${dir}/${sub}))
(subdirs dir);
in {
templates = concatMapAttrs ({ lang, pkg }: {
"${lang}-${pkg}" = {
description = "Packaging a${if vowelStart lang
then "n"
else ""} ${lang} executable using ${pkg}";
templates = concatMapAttrs (path: {
${builtins.concatStringsSep "_" path} = {
description = "${builtins.head path} template with ${builtins.concatStringsSep
", " (builtins.tail path)}";
path = builtins.filterSource
(path: type: builtins.baseNameOf path != "flake.lock")
./${lang}/${pkg};
(builtins.foldl' (dir: sub: /${dir}/${sub}) ./. path);
};
}) templateDirs // concatMapAttrs (lang: {
"${lang}" = self.templates."${lang}-nixpkgs" // {
description = "Packaging a${if vowelStart lang
then "n"
else ""} ${lang} executable";
};
}) (subdirs ./.);
}) (flakeSubdirs ./.) // builtins.mapAttrs (lang: def:
self.templates.${def} // {
description = "${lang} template";
}) aliases;
};
}

View file

@ -1,43 +0,0 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1763618868,
"narHash": "sha256-v5afmLjn/uyD9EQuPBn7nZuaZVV9r+JerayK/4wvdWA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a8d610af3f1a5fb71e23e08434d8d61a466fc942",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,13 +0,0 @@
{ python3
}:
python3.pkgs.buildPythonApplication {
pname = "hello";
version = "0.1";
src = ./.;
pyproject = true;
build-system = [ python3.pkgs.setuptools ];
doCheck = false;
}

View file

@ -0,0 +1,20 @@
{ python3
}:
python3.pkgs.buildPythonApplication {
pname = "hello";
version = "0.1";
src = ./.;
pyproject = true;
build-system = with python3.pkgs; [
# build-system.{requires,setup_requires}
setuptools
];
dependencies = [
# Python package dependencies
];
doCheck = false;
}