Restructure everything
This commit is contained in:
parent
81ca8af870
commit
a8a26921b4
19 changed files with 227 additions and 67 deletions
59
flake.nix
59
flake.nix
|
|
@ -1,28 +1,43 @@
|
|||
{
|
||||
description = "The Sieve of Eratosthenes implemented in many different languages";
|
||||
description = "Templates of the Sieve of Eratosthenes implemented in various languages";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = { self, ... }:
|
||||
let
|
||||
# Get all project directories
|
||||
subdirs = dir:
|
||||
let sub = builtins.readDir dir;
|
||||
in builtins.filter
|
||||
(d: sub.${d} == "directory")
|
||||
(builtins.attrNames sub);
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (pkgs) lib;
|
||||
vowelStart = str: builtins.elem (builtins.substring 0 1 str) [ "a" "e" "i" "o" "u" ];
|
||||
|
||||
# Check if project has a shell.nix
|
||||
hasShell = dir: builtins.pathExists ./${dir}/shell.nix;
|
||||
concatMapAttrs = func: attr:
|
||||
builtins.foldl' (x: y: x // y) {}
|
||||
(builtins.map func attr);
|
||||
|
||||
# Get all project directories
|
||||
currentDir = builtins.readDir ./.;
|
||||
dirs = builtins.attrNames (lib.filterAttrs (_: v: v == "directory") currentDir);
|
||||
in
|
||||
builtins.foldl' lib.recursiveUpdate {} (builtins.map (dir: {
|
||||
packages.${dir} = pkgs.callPackage ./${dir} {};
|
||||
} // lib.optionalAttrs (hasShell dir) {
|
||||
devShells.${dir} = pkgs.callPackage ./${dir}/shell.nix {};
|
||||
}) dirs)
|
||||
);
|
||||
templateDirs =
|
||||
builtins.concatMap (lang:
|
||||
builtins.map
|
||||
(pkg: { inherit lang pkg; })
|
||||
(subdirs ./${lang}))
|
||||
(subdirs ./.);
|
||||
in {
|
||||
templates = concatMapAttrs ({ lang, pkg }: {
|
||||
"${lang}-${pkg}" = {
|
||||
description = "Packaging a${if vowelStart lang
|
||||
then "n"
|
||||
else ""} ${lang} executable using ${pkg}";
|
||||
path = builtins.filterSource
|
||||
(path: type: builtins.baseNameOf path != "flake.lock")
|
||||
./${lang}/${pkg};
|
||||
};
|
||||
}) templateDirs // concatMapAttrs (lang: {
|
||||
"${lang}" = self.templates."${lang}-nixpkgs" // {
|
||||
description = "Packaging a${if vowelStart lang
|
||||
then "n"
|
||||
else ""} ${lang} executable";
|
||||
};
|
||||
}) (subdirs ./.);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue