feat: implement automatic indexing for by-name
This commit is contained in:
parent
bef1d9f5c0
commit
588a1dc5a9
3 changed files with 44 additions and 6 deletions
|
@ -60,12 +60,13 @@
|
|||
# inherit build-drv build-script watch-script;
|
||||
# };
|
||||
|
||||
legacyPackages = {
|
||||
phil-1 = {
|
||||
paper-1 = alexandriaLib.callTypstProject (import ./documents/by-course/phil-1/paper-1/package.nix);
|
||||
};
|
||||
digression-linear-algebra = alexandriaLib.callTypstProject (import ./documents/by-name/digression-linear-algebra/package.nix);
|
||||
};
|
||||
# legacyPackages = {
|
||||
# phil-1 = {
|
||||
# paper-1 = alexandriaLib.callTypstProject (import ./documents/by-course/phil-1/paper-1/package.nix);
|
||||
# };
|
||||
# digression-linear-algebra = alexandriaLib.callTypstProject (import ./documents/by-name/digression-linear-algebra/package.nix);
|
||||
# };
|
||||
legacyPackages = alexandriaLib.parsePkgs ./documents;
|
||||
# apps = rec {
|
||||
# default = watch;
|
||||
# build = flake-utils.lib.mkApp {
|
||||
|
|
|
@ -16,4 +16,5 @@ rec {
|
|||
inherit cleanTypstSource;
|
||||
}
|
||||
);
|
||||
parsePkgs = (import ./parsePkgs.nix) (defaultArgs // { inherit callTypstProject; });
|
||||
}
|
||||
|
|
36
2024/nix/lib/parsePkgs.nix
Normal file
36
2024/nix/lib/parsePkgs.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{ pkgs, callTypstProject, ... }:
|
||||
baseDirectory:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
inherit (lib.attrsets)
|
||||
mapAttrs
|
||||
mapAttrsToList
|
||||
mergeAttrsList
|
||||
;
|
||||
inherit (builtins) readDir;
|
||||
in
|
||||
let
|
||||
# Package files for a single shard
|
||||
# Type: String -> String -> AttrsOf Path
|
||||
namesForShard =
|
||||
shard: type:
|
||||
if type != "directory" then
|
||||
# Ignore all non-directories. Technically only README.md is allowed as a file in the base directory, so we could alternatively:
|
||||
# - Assume that README.md is the only file and change the condition to `shard == "README.md"` for a minor performance improvement.
|
||||
# This would however cause very poor error messages if there's other files.
|
||||
# - Ensure that README.md is the only file, throwing a better error message if that's not the case.
|
||||
# However this would make for a poor code architecture, because one type of error would have to be duplicated in the validity checks and here.
|
||||
# Additionally in either of those alternatives, we would have to duplicate the hardcoding of "README.md"
|
||||
{ }
|
||||
else
|
||||
mapAttrs (name: _: baseDirectory + "/${shard}/${name}/package.nix") (
|
||||
readDir (baseDirectory + "/${shard}")
|
||||
);
|
||||
|
||||
in
|
||||
# mapAttrs (a: b: builtins.trace (builtins.tryEval a) b) (
|
||||
# mergeAttrsList (mapAttrsToList namesForShard (readDir baseDirectory))
|
||||
# )
|
||||
mapAttrs (a: b: callTypstProject (import (/. + b))) (
|
||||
mergeAttrsList (mapAttrsToList namesForShard (readDir baseDirectory))
|
||||
)
|
Loading…
Reference in a new issue