From f9bdbf51aa61503d77e387095e7a4e1f34acdde3 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 28 Oct 2026 01:20:16 -0400 Subject: First few files --- .envrc | 1 + .gitignore | 2 + flake.lock | 97 +++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++++++++++++ instances/pocketbook.nix | 14 ++++++ modules/default.nix | 27 +++++++++++ modules/files.nix | 121 +++++++++++++++++++++++++++++++++++++++++++++++ modules/main.nix | 48 +++++++++++++++++++ overlays/default.nix | 6 +++ pkgs/kobo.nix | 4 ++ pkgs/patches.nix | 3 ++ pkgs/plugins.nix | 8 ++++ pkgs/pocketbook.nix | 4 ++ 13 files changed, 384 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 instances/pocketbook.nix create mode 100644 modules/default.nix create mode 100644 modules/files.nix create mode 100644 modules/main.nix create mode 100644 overlays/default.nix create mode 100644 pkgs/kobo.nix create mode 100644 pkgs/patches.nix create mode 100644 pkgs/plugins.nix create mode 100644 pkgs/pocketbook.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..726d2d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0ec8934 --- /dev/null +++ b/flake.lock @@ -0,0 +1,97 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1790898470, + "narHash": "sha256-zTwuwezD0w3hpga6a6P8emidzAZFyWqlNeRBlpWOOl8=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "024633cd702b10285db5cb19b40ad48d2399ba60", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1793161982, + "narHash": "sha256-AEdsm00PKkivtEO+vKVmQ7Qm9wyV5QvThS/pQz6o+/E=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8e9aa5e9d162f155566d845f11603192c03cc224", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1790477367, + "narHash": "sha256-oujbxmVKDhci2E4EM3KyAbRUgp5/IsCoiA/LfEF7OOk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "f7cd230690d9fc982d06129f9189b101fddcfa3b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1791244623, + "narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=", + "owner": "nix-systems", + "repo": "default", + "rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791885023, + "narHash": "sha256-C3alQ2MEt0zVrUSho5NUDo3jmhbff72++bfwoqT9Omo=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "0d6d739a833ba9a9c93034862e4a7b061a062a1c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ac79d55 --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +{ + description = "Nix utilities to manage koreader"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs@{self, ...}: inputs.flake-parts.lib.mkFlake { inherit inputs self; } { + systems = import inputs.systems; + + flake.overlays.default = import ./overlays; + + imports = [ + inputs.treefmt-nix.flakeModule + ./modules + ]; + + perSystem = { pkgs, config, system, ... }: { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ self.overlays.default ]; + }; + + treefmt = { + programs = { + nixfmt = { + enable = true; + strict = true; + }; + }; + }; + + devShells.default = pkgs.mkShellNoCC { + inputsFrom = [ config.treefmt.build.devShell ]; + nativeBuildInputs = with pkgs; [ + nixd + statix + deadnix + ]; + }; + }; + }; +} diff --git a/instances/pocketbook.nix b/instances/pocketbook.nix new file mode 100644 index 0000000..905cf79 --- /dev/null +++ b/instances/pocketbook.nix @@ -0,0 +1,14 @@ +{ + config, + pkgs, + lib, + ... +}: +with builtins // lib; +{ + koreader.flavor = "pocketbook"; + + plugins = { + pocketbooksync = "${pkgs.koreader-plugins.pocketbooksync}/pocketbooksync.koplugin"; + }; +} diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..d32d8f6 --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,27 @@ +{ lib, flake-parts-lib, ... }: +let + inherit (lib) mkOption mkEnableOption types; + inherit (flake-parts-lib) mkPerSystemOption; +in { + options.perSystem = mkPerSystemOption ({ pkgs, system, config, ... }: { + options.koreader = mkOption { + default = {}; + type = types.lazyAttrsOf <| types.submoduleWith { + shorthandOnlyDefinesConfig = true; + modules = [ + { + _module.args = { + inherit pkgs lib; + }; + } + ({ name, ... }: { + imports = [ ./main.nix ]; + options = { + enable = mkEnableOption name // { default = true; }; + }; + }) + ]; + }; + }; + }); +} diff --git a/modules/files.nix b/modules/files.nix new file mode 100644 index 0000000..dbd9c6b --- /dev/null +++ b/modules/files.nix @@ -0,0 +1,121 @@ +{ + config, + pkgs, + lib, + ... +}: +with builtins // lib; +{ + options = { + files = mkOption { + default = { }; + type = + types.lazyAttrsOf + <| types.submodule ( + { name, config, ... }: { + options = { + enable = mkEnableOption name // { + default = true; + }; + name = mkOption { + type = types.str; + default = name; + }; + destination = mkOption { + type = types.str; + default = name; + }; + source = mkOption { + type = types.path; + }; + text = mkOption { + type = types.lines; + default = null; + }; + }; + + config = mkIf (config.text != "") { + source = pkgs.writeTextFile { + inherit (config) name text; + }; + }; + } + ); + }; + + _files = mkOption { + type = types.path; + readOnly = true; + internal = true; + default = + pkgs.linkFarm "files" + <| flip mapAttrsToList config.files ( + _: { destination, source, ... }: { + name = destination; + path = source; + } + ); + }; + + dictionaries = mkOption { + default = { }; + type = with types; attrsOf path; + }; + + fonts = mkOption { + default = { }; + type = with types; attrsOf path; + }; + + plugins = mkOption { + default = { }; + type = with types; attrsOf path; + }; + + patches = mkOption { + default = { }; + type = with types; attrsOf path; + }; + }; + + config = { + files = mkMerge [ + (flip mapAttrs' config.dictionaries ( + name: source: { + name = "dict::${name}"; + value = { + destination = "data/dict/${name}"; + inherit source; + }; + } + )) + (flip mapAttrs' config.fonts ( + name: source: { + name = "font::${name}"; + value = { + destination = "fonts/${name}"; + inherit source; + }; + } + )) + (flip mapAttrs' config.plugins ( + name: source: { + name = "plugin::${name}"; + value = { + destination = "plugins/${name}.koplugin"; + inherit source; + }; + } + )) + (flip mapAttrs' config.patches ( + name: source: { + name = "patch::${name}"; + value = { + destination = "patches/${name}"; + inherit source; + }; + } + )) + ]; + }; +} diff --git a/modules/main.nix b/modules/main.nix new file mode 100644 index 0000000..b568efa --- /dev/null +++ b/modules/main.nix @@ -0,0 +1,48 @@ +{ + config, + pkgs, + lib, + ... +}: +with builtins // lib; +{ + imports = [ + ./files.nix + ]; + + options = { + koreader = { + flavor = mkOption { + type = + with types; + nullOr + <| enum [ + "kobo" + "pocketbook" + ]; + default = null; + }; + basePackage = mkOption { + type = types.package; + }; + koreaderPath = mkOption { + type = types.str; + }; + }; + }; + + config = mkMerge [ + (mkIf (config.koreader.flavor == "kobo") { + koreader = { + basePackage = mkOptionDefault pkgs.koreader-kobo; + koreaderPath = mkOptionDefault ".adds/koreader"; + }; + }) + (mkIf (config.koreader.flavor == "pocketbook") { + koreader = { + basePackage = mkOptionDefault pkgs.koreader-pocketbook; + koreaderPath = mkOptionDefault "applications/koreader"; + }; + }) + ]; +} diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..b5dc8f9 --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,6 @@ +_final: prev: { + koreader-kobo = prev.callPackage ../pkgs/kobo.nix; + koreader-pocketbook = prev.callPackage ../pkgs/pocketbook.nix; + koreader-plugins = prev.callPackage ../pkgs/plugins.nix; + koreader-patches = prev.callPackage ../pkgs/patches.nix; +} diff --git a/pkgs/kobo.nix b/pkgs/kobo.nix new file mode 100644 index 0000000..4f8438c --- /dev/null +++ b/pkgs/kobo.nix @@ -0,0 +1,4 @@ +{ fetchzip }: +fetchzip { + url = "https://storage.gra.cloud.ovh.net/v1/AUTH_2ac4bfee353948ec8ea7fd1710574097/kfmon-pub/OCP-KOReader-v2026.03.zip"; +} diff --git a/pkgs/patches.nix b/pkgs/patches.nix new file mode 100644 index 0000000..0a3181d --- /dev/null +++ b/pkgs/patches.nix @@ -0,0 +1,3 @@ +{ fetchFromGitHub }: +{ +} diff --git a/pkgs/plugins.nix b/pkgs/plugins.nix new file mode 100644 index 0000000..f41724a --- /dev/null +++ b/pkgs/plugins.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: +{ + pocketbooksync = fetchFromGitHub { + owner = "ckilb"; + repo = "pocketbooksync.koplugin"; + tag = "v1.0.2"; + }; +} diff --git a/pkgs/pocketbook.nix b/pkgs/pocketbook.nix new file mode 100644 index 0000000..2196705 --- /dev/null +++ b/pkgs/pocketbook.nix @@ -0,0 +1,4 @@ +{ fetchzip }: +fetchzip { + url = "https://github.com/koreader/koreader/releases/download/v2026.07.1/koreader-pocketbook-v2026.07.1.zip"; +} -- cgit v1.3.1