commit 3184f1f8dbd5331aa2f7239c063ec4f3fcebb783 Author: Jonas Rabenstein Date: Fri Sep 19 19:57:17 2025 +0200 initial flake setup diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e94c767 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1758198701, + "narHash": "sha256-7To75JlpekfUmdkUZewnT6MoBANS0XVypW6kjUOXQwc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0147c2f1d54b30b5dd6d4a8c8542e8d7edf93b5d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f185360 --- /dev/null +++ b/flake.nix @@ -0,0 +1,87 @@ +{ + 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; + + per-pkgs = fn: builtins.mapAttrs (_: fn) nixpkgs.legacyPackages; + scan = + base: fn: + let + 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; + files = lib.optionalAttrs (builtins.pathExists base) (builtins.readDir base); + in + lib.attrsets.foldlAttrs fold { } files; + + packages = + pkgs: scan ./package (name: def: (pkgs' pkgs).callPackage def { original = pkgs.${name} or null; }); + 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); + in + if builtins.pathExists base then result else { }; + + 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 + modules = scan ./module ( + _: def: { + config.nixpkgs.overlays = [ overlay ]; + imports = [ def ]; + } + ); + in + { default.imports = builtins.attrValues modules; } // modules; + + formatter = per-pkgs ({ nixfmt-tree, ... }: nixfmt-tree); + }; +}