Compare commits
2 commits
a3b53b180c
...
fe347d9769
| Author | SHA1 | Date | |
|---|---|---|---|
| fe347d9769 | |||
| afb4b62827 |
27 changed files with 145 additions and 253 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
result*
|
result*
|
||||||
.direnv
|
.direnv/
|
||||||
|
|
||||||
|
flake.lock
|
||||||
|
!/flake.lock
|
||||||
|
|
|
||||||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2023 Kiana Sheibani
|
Copyright (c) 2025 Kiana Sheibani
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
46
README.md
Normal file
46
README.md
Normal 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.
|
||||||
43
bash/nixpkgs/flake.lock
generated
43
bash/nixpkgs/flake.lock
generated
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1722073938,
|
|
||||||
"narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
packages = eachSystem (system:
|
packages = eachSystem (system:
|
||||||
let pkgs = nixpkgs.legacyPackages.${system};
|
let pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in {
|
||||||
soe = pkgs.callPackage ./package.nix {};
|
hello = pkgs.callPackage ./package.nix {};
|
||||||
default = self.packages.${system}.soe;
|
default = self.packages.${system}.hello;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
python/nixpkgs/.envrc → bash/nixpkgs/hello
Normal file → Executable file
2
python/nixpkgs/.envrc → bash/nixpkgs/hello
Normal file → Executable file
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
use flake ..#python
|
echo "Hello, World!"
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{ stdenv
|
{ stdenvNoCC
|
||||||
, bash
|
, bash
|
||||||
}:
|
}:
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenvNoCC.mkDerivation {
|
||||||
pname = "soe";
|
pname = "hello";
|
||||||
version = "1.0";
|
version = "0.1";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
|
@ -12,6 +12,6 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp soe $out/bin
|
cp hello $out/bin
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo -n "Primes up to: "
|
|
||||||
read num
|
|
||||||
echo
|
|
||||||
|
|
||||||
nums=()
|
|
||||||
for i in `seq 2 $num`; do
|
|
||||||
nums+=($i)
|
|
||||||
done
|
|
||||||
|
|
||||||
unset nums[-1]
|
|
||||||
|
|
||||||
while [ -n "$nums" ]; do
|
|
||||||
prime=${nums[0]}
|
|
||||||
echo -n "$prime "
|
|
||||||
nums_=()
|
|
||||||
for elem in "${nums[@]}"; do
|
|
||||||
[ $(( $elem % $prime )) -eq 0 ] || nums_+=($elem)
|
|
||||||
done
|
|
||||||
nums=(${nums_[@]})
|
|
||||||
done
|
|
||||||
|
|
||||||
echo
|
|
||||||
43
fish/nixpkgs/flake.lock
generated
43
fish/nixpkgs/flake.lock
generated
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1722141560,
|
|
||||||
"narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
packages = eachSystem (system:
|
packages = eachSystem (system:
|
||||||
let pkgs = nixpkgs.legacyPackages.${system};
|
let pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in {
|
||||||
soe = pkgs.callPackage ./package.nix {};
|
hello = pkgs.callPackage ./package.nix {};
|
||||||
default = self.packages.${system}.soe;
|
default = self.packages.${system}.hello;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
fish/nixpkgs/hello
Executable file
3
fish/nixpkgs/hello
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
echo "Hello, World!"
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{ stdenv
|
{ stdenvNoCC
|
||||||
, fish
|
, fish
|
||||||
}:
|
}:
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenvNoCC.mkDerivation {
|
||||||
pname = "soe";
|
pname = "hello";
|
||||||
version = "1.0";
|
version = "0.1";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
|
@ -12,6 +12,6 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp soe $out/bin
|
cp hello $out/bin
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env fish
|
|
||||||
|
|
||||||
read -P "Primes up to: " num
|
|
||||||
echo
|
|
||||||
|
|
||||||
set nums (seq 2 $num)[..-2]
|
|
||||||
|
|
||||||
while test -n "$nums"
|
|
||||||
set prime $nums[1]
|
|
||||||
echo -n "$prime "
|
|
||||||
|
|
||||||
set -e nums_
|
|
||||||
for elem in $nums
|
|
||||||
test (math $elem % $prime) -eq 0 || set -a nums_ $elem
|
|
||||||
end
|
|
||||||
set nums $nums_
|
|
||||||
end
|
|
||||||
|
|
||||||
echo
|
|
||||||
43
flake.nix
43
flake.nix
|
|
@ -1,11 +1,17 @@
|
||||||
{
|
{
|
||||||
description = "Templates of the Sieve of Eratosthenes implemented in various languages";
|
description = "Hello World flake templates for various languages and build systems";
|
||||||
|
|
||||||
outputs = { self, ... }:
|
outputs = { self, ... }:
|
||||||
let
|
let
|
||||||
|
aliases = {
|
||||||
|
bash = "bash_nixpkgs";
|
||||||
|
fish = "fish_nixpkgs";
|
||||||
|
python = "python_pyproject_nixpkgs_basic";
|
||||||
|
};
|
||||||
|
|
||||||
# Get all project directories
|
# Get all project directories
|
||||||
subdirs = dir:
|
subdirs = dir:
|
||||||
let sub = builtins.readDir dir;
|
let sub = __readDir dir;
|
||||||
in builtins.filter
|
in builtins.filter
|
||||||
(d: sub.${d} == "directory")
|
(d: sub.${d} == "directory")
|
||||||
(builtins.attrNames sub);
|
(builtins.attrNames sub);
|
||||||
|
|
@ -16,28 +22,23 @@
|
||||||
builtins.foldl' (x: y: x // y) {}
|
builtins.foldl' (x: y: x // y) {}
|
||||||
(builtins.map func attr);
|
(builtins.map func attr);
|
||||||
|
|
||||||
templateDirs =
|
flakeSubdirs = dir:
|
||||||
builtins.concatMap (lang:
|
builtins.concatMap (sub:
|
||||||
builtins.map
|
if builtins.pathExists /${dir}/${sub}/flake.nix then [ [ sub ] ] else
|
||||||
(pkg: { inherit lang pkg; })
|
builtins.map (l: [ sub ] ++ l) (flakeSubdirs /${dir}/${sub}))
|
||||||
(subdirs ./${lang}))
|
(subdirs dir);
|
||||||
(subdirs ./.);
|
|
||||||
in {
|
in {
|
||||||
templates = concatMapAttrs ({ lang, pkg }: {
|
templates = concatMapAttrs (path: {
|
||||||
"${lang}-${pkg}" = {
|
${builtins.concatStringsSep "_" path} = {
|
||||||
description = "Packaging a${if vowelStart lang
|
description = "${builtins.head path} template with ${builtins.concatStringsSep
|
||||||
then "n"
|
", " (builtins.tail path)}";
|
||||||
else ""} ${lang} executable using ${pkg}";
|
|
||||||
path = builtins.filterSource
|
path = builtins.filterSource
|
||||||
(path: type: builtins.baseNameOf path != "flake.lock")
|
(path: type: builtins.baseNameOf path != "flake.lock")
|
||||||
./${lang}/${pkg};
|
(builtins.foldl' (dir: sub: /${dir}/${sub}) ./. path);
|
||||||
};
|
};
|
||||||
}) templateDirs // concatMapAttrs (lang: {
|
}) (flakeSubdirs ./.) // builtins.mapAttrs (lang: def:
|
||||||
"${lang}" = self.templates."${lang}-nixpkgs" // {
|
self.templates.${def} // {
|
||||||
description = "Packaging a${if vowelStart lang
|
description = "${lang} template";
|
||||||
then "n"
|
}) aliases;
|
||||||
else ""} ${lang} executable";
|
|
||||||
};
|
|
||||||
}) (subdirs ./.);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import soe
|
|
||||||
soe.main()
|
|
||||||
43
python/nixpkgs/flake.lock
generated
43
python/nixpkgs/flake.lock
generated
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1722141560,
|
|
||||||
"narHash": "sha256-Ul3rIdesWaiW56PS/Ak3UlJdkwBrD4UcagCmXZR9Z7Y=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "038fb464fcfa79b4f08131b07f2d8c9a6bcc4160",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
{ python3 }:
|
|
||||||
|
|
||||||
python3.pkgs.buildPythonApplication {
|
|
||||||
pname = "soe";
|
|
||||||
version = "1.0";
|
|
||||||
src = ./.;
|
|
||||||
|
|
||||||
doCheck = false;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name="soe",
|
|
||||||
version="1.0.0",
|
|
||||||
scripts=["bin/soe"]
|
|
||||||
)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{ python3 }:
|
|
||||||
|
|
||||||
python3.buildEnv.env
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
def sieve_of_eratosthenes(n):
|
|
||||||
nums = list(range(2, n))
|
|
||||||
while nums:
|
|
||||||
prime = nums[0]
|
|
||||||
nums = [i for i in nums if i % prime]
|
|
||||||
yield prime
|
|
||||||
|
|
||||||
def main():
|
|
||||||
num = int(input("Primes up to: "))
|
|
||||||
print()
|
|
||||||
for i in sieve_of_eratosthenes(num):
|
|
||||||
print(i, end=" ")
|
|
||||||
print()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
2
python/pyproject/nixpkgs/cli/.envrc
Normal file
2
python/pyproject/nixpkgs/cli/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
use flake
|
||||||
|
|
@ -10,8 +10,14 @@
|
||||||
packages = eachSystem (system:
|
packages = eachSystem (system:
|
||||||
let pkgs = nixpkgs.legacyPackages.${system};
|
let pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in {
|
||||||
soe = pkgs.callPackage ./package.nix {};
|
hello = pkgs.callPackage ./package.nix {};
|
||||||
default = self.packages.${system}.soe;
|
default = self.packages.${system}.hello;
|
||||||
|
});
|
||||||
|
|
||||||
|
devShells = eachSystem (system:
|
||||||
|
let pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in {
|
||||||
|
default = pkgs.callPackage ./shell.nix {};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
20
python/pyproject/nixpkgs/cli/package.nix
Normal file
20
python/pyproject/nixpkgs/cli/package.nix
Normal 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;
|
||||||
|
}
|
||||||
10
python/pyproject/nixpkgs/cli/pyproject.toml
Normal file
10
python/pyproject/nixpkgs/cli/pyproject.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[project]
|
||||||
|
name = "hello"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
hello = "hello:main"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
8
python/pyproject/nixpkgs/cli/shell.nix
Normal file
8
python/pyproject/nixpkgs/cli/shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{ mkShell
|
||||||
|
, python3
|
||||||
|
}:
|
||||||
|
|
||||||
|
mkShell {
|
||||||
|
inputsFrom = [ python3.buildEnv.env ];
|
||||||
|
packages = [ python3.pkgs.python-lsp-server ];
|
||||||
|
}
|
||||||
6
python/pyproject/nixpkgs/cli/src/hello/main.py
Normal file
6
python/pyproject/nixpkgs/cli/src/hello/main.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Hello, World!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue