108 lines
2.9 KiB
Nix
108 lines
2.9 KiB
Nix
{
|
|
description = "A very basic flake";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
|
};
|
|
|
|
outputs =
|
|
{ self, nixpkgs }:
|
|
let
|
|
inherit (nixpkgs) lib;
|
|
|
|
overlay =
|
|
final: pkgs:
|
|
(packages pkgs)
|
|
// lib.attrsets.mapAttrs' (name: value: {
|
|
name = "jellyfin-plugin-${name}";
|
|
inherit value;
|
|
}) (plugins final);
|
|
|
|
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 =
|
|
filter: fn: base:
|
|
let
|
|
empty = { };
|
|
create =
|
|
name: entry:
|
|
lib.optionalAttrs (name != null) {
|
|
${name} = fn name (base + "/${entry}");
|
|
};
|
|
fold =
|
|
acc: name: kind:
|
|
acc // create (filter name kind) name;
|
|
files = lib.optionalAttrs (builtins.pathExists base) (builtins.readDir base);
|
|
in
|
|
lib.attrsets.foldlAttrs fold empty files;
|
|
|
|
packages =
|
|
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
|
|
plugin = name: path: (pkgs' pkgs).jellyfin.plugin path { };
|
|
in
|
|
scan'directory plugin ./plugin;
|
|
|
|
module = defs: { ... }: {
|
|
imports = lib.toList defs;
|
|
config.nixpkgs.overlays = [ overlay ];
|
|
};
|
|
|
|
in
|
|
{
|
|
overlays.default = overlay;
|
|
|
|
packages = per-pkgs (
|
|
pkgs:
|
|
(packages pkgs)
|
|
// lib.attrsets.mapAttrs' (name: value: {
|
|
name = "plugin-${name}";
|
|
inherit value;
|
|
}) (plugins pkgs)
|
|
);
|
|
|
|
nixosModules =
|
|
let
|
|
directories = scan'directory (_: path: path) ./module;
|
|
files = scan'nix (_: path: path) ./module;
|
|
modules = directories // {
|
|
default.imports =
|
|
builtins.attrValues files ++ (directories.default or []);
|
|
};
|
|
in
|
|
builtins.mapAttrs module modules;
|
|
|
|
formatter = per-pkgs ({ nixfmt-tree, ... }: nixfmt-tree);
|
|
};
|
|
}
|