rework layout

This commit is contained in:
Jonas Rabenstein 2025-09-20 13:34:01 +02:00
commit 68c510c807
8 changed files with 259 additions and 200 deletions

View file

@ -20,43 +20,59 @@
pkgs' = pkgs: pkgs.extend overlay;
scan'directory = scan (name: type: if type == "directory" then name else null);
scan'regular = scan (name: type: if type == "regular" then name else null);
scan'nix =
let
stem = lib.strings.removeSuffix ".nix";
in
scan (name: type: if type == "regular" && name == "${stem name}.nix" then stem name else null);
per-pkgs = fn: builtins.mapAttrs (_: fn) nixpkgs.legacyPackages;
scan =
base: fn:
filter: fn: base:
let
empty = { };
create =
name: entry:
lib.optionalAttrs (name != null) {
${name} = fn name (base + "/${entry}");
};
fold =
acc: entry: kind:
let
name = lib.strings.removeSuffix ".nix" entry;
attr = lib.optionalAttrs (lib.strings.hasSuffix ".nix" entry) {
${name} = fn name "${base}/${entry}";
};
in
acc // attr;
acc: name: kind:
acc // create (filter name kind) name;
files = lib.optionalAttrs (builtins.pathExists base) (builtins.readDir base);
in
lib.attrsets.foldlAttrs fold { } files;
lib.attrsets.foldlAttrs fold empty files;
packages =
pkgs: scan ./package (name: def: (pkgs' pkgs).callPackage def { original = pkgs.${name} or null; });
pkgs:
let
package =
name: path:
let
pkg = (pkgs' pkgs).callPackage path {
original = pkgs.${name} or null;
};
patches = scan (name: type: if lib.strings.removeSuffix ".patch" name != name then name else null) (
name: path: path
) path;
in
pkg.overrideAttrs (
final: prev: {
patches = (prev.patches or [ ]) ++ builtins.attrValues patches;
}
);
in
scan'directory package ./package;
plugins =
pkgs:
let
base = ./plugin;
result = lib.attrsets.foldlAttrs (
acc: name: kind:
acc
// lib.optionalAttrs (kind == "directory") {
${name} = (pkgs' pkgs).jellyfin.plugin (base + "/${name}") { };
}
) { } (builtins.readDir base);
plugin = name: path: (pkgs' pkgs).jellyfin.plugin path { };
in
if builtins.pathExists base then result else { };
module = defs: {
imports = lib.toList defs;
config.nixpkgs.overlays = [ overlay ];
};
scan'directory plugin ./plugin;
in
{
@ -73,14 +89,18 @@
nixosModules =
let
modules = scan ./module (
_: def: {
config.nixpkgs.overlays = [ overlay ];
imports = [ def ];
}
);
directories = scan'directory (_: path: path) ./module;
files = scan'nix (_: path: path) ./module;
modules = directories // {
default.imports =
builtins.attrValues files ++ (directories.default or []);
};
module = name: defs: { ... }: builtins.trace "module: jellyfin.${name}" {
imports = lib.toList defs;
config.nixpkgs.overlays = [ overlay ];
};
in
{ default.imports = builtins.attrValues modules; } // modules;
builtins.mapAttrs module modules;
formatter = per-pkgs ({ nixfmt-tree, ... }: nixfmt-tree);
};