diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/default.nix | 64 | ||||
| -rw-r--r-- | modules/files.nix | 41 | ||||
| -rw-r--r-- | modules/main.nix | 23 |
3 files changed, 94 insertions, 34 deletions
diff --git a/modules/default.nix b/modules/default.nix index d32d8f6..d32cbe4 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -2,26 +2,48 @@ 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; }; - }; - }) - ]; +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; + }; + }; + }) + ]; + }; }; - }; - }); + + config.packages = + let + koreaders = lib.filterAttrs (_: v: v.enable) config.koreader; + in + lib.mapAttrs' (name: value: { + name = "koreader-${name}"; + value = value.koreader.finalPackage; + }) koreaders; + } + ); } diff --git a/modules/files.nix b/modules/files.nix index dbd9c6b..14b5319 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -49,12 +49,13 @@ with builtins // lib; internal = true; default = pkgs.linkFarm "files" - <| flip mapAttrsToList config.files ( + <| mapAttrsToList ( _: { destination, source, ... }: { name = destination; path = source; } - ); + ) + <| filterAttrs (_: v: v.enable) config.files; }; dictionaries = mkOption { @@ -76,6 +77,10 @@ with builtins // lib; default = { }; type = with types; attrsOf path; }; + + patchDirectories = mkOption { + type = with types; listOf path; + }; }; config = { @@ -107,15 +112,31 @@ with builtins // lib; }; } )) - (flip mapAttrs' config.patches ( - name: source: { - name = "patch::${name}"; - value = { - destination = "patches/${name}"; - inherit source; + (mkIf (config.patchDirectories != [ ]) { + "patches" = { + source = pkgs.symlinkJoin { + name = "patches"; + paths = config.patchDirectories; }; - } - )) + }; + }) + # (flip mapAttrs' config.patches ( + # name: source: { + # name = "patch::${name}"; + # value = { + # destination = "patches/${name}"; + # inherit source; + # }; + # } + # )) ]; + + patchDirectories = mkIf (config.patches != { }) [ + ( + pkgs.linkFarm "individual-patches" + <| mapAttrsToList (name: path: { inherit name path; }) config.patches + ) + ]; + }; } diff --git a/modules/main.nix b/modules/main.nix index b568efa..974f599 100644 --- a/modules/main.nix +++ b/modules/main.nix @@ -17,32 +17,49 @@ with builtins // lib; with types; nullOr <| enum [ + "raw" "kobo" "pocketbook" ]; default = null; }; basePackage = mkOption { - type = types.package; + type = types.path; }; koreaderPath = mkOption { type = types.str; }; + finalPackage = mkOption { + type = types.package; + readOnly = true; + default = pkgs.runCommandLocal "merge" { nativeBuildInputs = [ pkgs.rsync ]; } '' + RSYNC="rsync -a --copy-links -v" + + $RSYNC "${config.koreader.basePackage}/" "$out/" + $RSYNC "${config._files}/" "$out/${config.koreaderPath}/" + ''; + }; }; }; config = mkMerge [ (mkIf (config.koreader.flavor == "kobo") { koreader = { - basePackage = mkOptionDefault pkgs.koreader-kobo; + basePackage = mkOptionDefault <| pkgs.callPackage ../pkgs/kobo.nix { }; koreaderPath = mkOptionDefault ".adds/koreader"; }; }) (mkIf (config.koreader.flavor == "pocketbook") { koreader = { - basePackage = mkOptionDefault pkgs.koreader-pocketbook; + basePackage = mkOptionDefault <| pkgs.callPackage ../pkgs/pocketbook.nix { }; koreaderPath = mkOptionDefault "applications/koreader"; }; }) + (mkIf (config.koreader.flavor == "raw") { + koreader = { + basePackage = mkOptionDefault <| pkgs.runCommandLocal "raw" { } "mkdir $out"; + koreaderPath = mkOptionDefault ""; + }; + }) ]; } |
