aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/build/default.nix5
-rw-r--r--modules/build/firmware.nix60
-rw-r--r--modules/default.nix22
-rw-r--r--modules/device/default.nix5
-rw-r--r--modules/kfmon/default.nix43
-rw-r--r--modules/kobo/default.nix40
-rw-r--r--modules/koboroot/default.nix34
-rw-r--r--modules/koreader/default.nix20
-rw-r--r--modules/lib/file-type.nix22
-rw-r--r--modules/nickel/default.nix46
-rw-r--r--modules/plato/default.nix126
11 files changed, 333 insertions, 90 deletions
diff --git a/modules/build/default.nix b/modules/build/default.nix
new file mode 100644
index 0000000..be3f3b0
--- /dev/null
+++ b/modules/build/default.nix
@@ -0,0 +1,5 @@
+{
+ imports = [
+ ./firmware.nix
+ ];
+}
diff --git a/modules/build/firmware.nix b/modules/build/firmware.nix
new file mode 100644
index 0000000..673c379
--- /dev/null
+++ b/modules/build/firmware.nix
@@ -0,0 +1,60 @@
+{ config, pkgs, lib, ... }:
+with builtins // lib;
+let
+ cfg = config.build;
+in {
+ options.build = {
+ firmware = {
+ checkDevice = mkOption {
+ internal = true;
+ readOnly = true;
+ type = types.package;
+ default = pkgs.writeShellApplication {
+ name = "check-firmware";
+ runtimeInputs = with pkgs; [
+ kobo-utils
+ ];
+ text = ''
+ echo "hi"
+ '';
+ };
+ };
+
+ bundle =
+ let
+ b = pkgs.runCommandLocal "package-firmware" {} ''
+ cp -r "${config.firmware.package.out}" $out
+ tar czvf $out/KoboRoot.tgz --directory="${config.firmware.package.KoboRoot}"
+ '';
+ in pkgs.runCommandLocal "bundle-firmware" {} ''
+ tar czvf $out --directory "${b}"
+ '';
+
+
+ deploy = pkgs.writeShellApplication {
+ name = "deploy-firmware";
+ runtimeInputs = with pkgs; [
+ gnutar
+ kobo-utils
+ ];
+ text = ''
+ echo "Looking for kobo"
+ KOBOPATH="$(kobo-find -f -w)"
+
+ if [ -z "$KOBOPATH" ]; then
+ >&2 echo "Cannot locate kobo device"
+ exit 1
+ fi
+
+ echo "Found kobo device at $KOBOPATH"
+
+ echo "Placing firmware on device"
+
+ tar xzvf "${cfg.fimware.bundle}" --directory="$KOBOPATH/.kobo/"
+
+ echo "Successfully installed kobo firmware. Please eject your device so it can install."
+ '';
+ };
+ };
+ };
+}
diff --git a/modules/default.nix b/modules/default.nix
index 856ece0..a5c0395 100644
--- a/modules/default.nix
+++ b/modules/default.nix
@@ -1,12 +1,20 @@
{
imports = [
+ ./build
+ ./device
+ ./firmware
+ ./kfmon
+ ./kobo
+ ./koboroot
+ ./nickel
+ ./plato
# ./installer.nix
- ./build.nix
- ./file.nix
- ./manifest.nix
- ./kfmon.nix
- ./kobo.nix
- ./koreader.nix
- ./plato.nix
+ # ./build.nix
+ # ./file.nix
+ # ./manifest.nix
+ # ./kfmon.nix
+ # ./kobo.nix
+ # ./koreader.nix
+ # ./plato.nix
];
}
diff --git a/modules/device/default.nix b/modules/device/default.nix
index 22cf180..a1f80ef 100644
--- a/modules/device/default.nix
+++ b/modules/device/default.nix
@@ -29,6 +29,11 @@ in {
type = types.enum (attrNames devices);
};
+ affiliate = mkOption {
+ type = types.enum (import ../../data/affiliates.nix);
+ default = "kobo";
+ };
+
hardware = hardware // {
default = config._allDevices.${config.device.name}.hardware;
};
diff --git a/modules/kfmon/default.nix b/modules/kfmon/default.nix
index 8557a3e..ac20b86 100644
--- a/modules/kfmon/default.nix
+++ b/modules/kfmon/default.nix
@@ -26,13 +26,17 @@ in {
file = mkOption {
default = {};
type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
};
_allFiles = mkOption {
type = types.package;
internal = true;
readOnly = true;
- default = (pkgs.callPackage ../lib/merge-files.nix {}) (attrValues file);
+ default = pkgs.symlinkJoin {
+ name = "kfmon-files";
+ paths = mapAttrsToList (v: v._package) cfg.file;
+ };
};
configs = mkOption {
@@ -44,16 +48,27 @@ in {
};
};
- config = {
- kfmon.file = mapAttrs' (n: v: {
- name = "kfmon-config-${n}";
- value = {
- text = generators.toINI {} v;
- target =
- let
- fixedN = if isSuffix ".ini" n then n else "${n}.ini";
- in "config/${fixedN}";
- };
- });
- };
-};
+ config = mkMerge [
+ {
+ kfmon.file = mapAttrs' (n: v: {
+ name = "kfmon-config-${n}";
+ value = {
+ text = generators.toINI {} v;
+ target =
+ let
+ fixedN = if isSuffix ".ini" n then n else "${n}.ini";
+ in "config/${fixedN}";
+ };
+ });
+ }
+ (mkIf cfg.enable {
+ koboroot.include = [
+ (pkgs.linkFarm [{
+ name = cfg.devicePath;
+ path = cfg._allFiles;
+ }])
+ cfg.package.KoboRoot
+ ];
+ })
+ ];
+}
diff --git a/modules/kobo/default.nix b/modules/kobo/default.nix
index 47dfe91..cdf9728 100644
--- a/modules/kobo/default.nix
+++ b/modules/kobo/default.nix
@@ -18,19 +18,23 @@ in {
type = types.str;
readOnly = true;
internal = true;
- deafault = "/mnt/onboard/${cfg.path}";
+ default = "/mnt/onboard/${cfg.path}";
};
file = mkOption {
default = {};
type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
};
_allFiles = mkOption {
type = types.package;
readOnly = true;
internal = true;
- default = (pkgs.callPackage ../lib/merge-files.nix {}) (attrValues cfg.file);
+ default = pkgs.symlinkJoin {
+ name = "kobo-files";
+ paths = mapAttrsToList (v: v._package) cfg.file;
+ };
};
conf = mkOption {
@@ -40,19 +44,27 @@ in {
};
};
- config = {
- kobo = {
- conf = {
- FeatureSettings.ExcludeSyncFolders = ''(\.(?!kobo|adobe).+|([^.][^/]*/)+\..+)'';
- ApplicationPreferences = {
- SideloadedMode = true;
- QuickTourShown = true;
+ config = mkMerge [
+ {
+ kobo = {
+ conf = {
+ FeatureSettings.ExcludeSyncFolders = ''(\.(?!kobo|adobe).+|([^.][^/]*/)+\..+)'';
+ ApplicationPreferences = {
+ SideloadedMode = true;
+ QuickTourShown = true;
+ };
};
- };
- file = mkIf (cfg.conf != {}) {
- "Kobo eReader.conf".text = generators.toINI {} cfg.conf;
+ file = mkIf (cfg.conf != {}) {
+ "Kobo eReader.conf".text = generators.toINI {} cfg.conf;
+ };
};
- };
- };
+ }
+ (mkIf cfg.enable {
+ koboroot.include = singleton (pkgs.linkFarm [{
+ name = cfg.devicePath;
+ path = cfg._allFiles;
+ }]);
+ })
+ ];
}
diff --git a/modules/koboroot/default.nix b/modules/koboroot/default.nix
new file mode 100644
index 0000000..308ac6b
--- /dev/null
+++ b/modules/koboroot/default.nix
@@ -0,0 +1,34 @@
+{ config, pkgs, lib, ... }:
+with builtins // lib;
+let
+ cfg = config.koboroot;
+in {
+ options.koboroot = {
+ file = mkOption {
+ default = {};
+ type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
+ };
+
+ include = mkOption {
+ default = [];
+ type = with types; listOf path;
+ };
+
+ _allFiles = mkOption {
+ type = types.package;
+ readOnly = true;
+ internal = true;
+ default = pkgs.buildEnv {
+ name = "koboroot-files";
+ paths = cfg.include;
+ };
+ };
+ };
+
+ config = {
+ koboroot = {
+ include = mkBefore (mapAttrsToList (_: v: v._package));
+ };
+ };
+}
diff --git a/modules/koreader/default.nix b/modules/koreader/default.nix
index db12219..3cc5281 100644
--- a/modules/koreader/default.nix
+++ b/modules/koreader/default.nix
@@ -12,9 +12,10 @@ in {
type = types.package;
readOnly = true;
internal = true;
- default = (pkgs.callPackage ../lib/merge-files.nix {}) ([
- cfg.package
- ] ++ attrValues cfg.file);
+ default = pkgs.symlinkJoin {
+ name = "koreader-files";
+ paths = mapAttrsToList (_: v: v._package) cfg.file ++ [ cfg.package ];
+ };
};
path = mkOption {
@@ -34,6 +35,7 @@ in {
file = mkOption {
default = {};
type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
};
nickel = {
@@ -41,8 +43,16 @@ in {
};
};
- config = {
- nickel.menu.item = mkIf (cfg.enable && cfg.nickel.enable) {
+ config = mkIf cfg.enable {
+ koboroot.include = [
+ (pkgs.linkFarm [{
+ name = cfg.devicePath;
+ path = cfg._allFiles;
+ })
+ cfg.package.KoboRoot
+ ];
+
+ nickel.menu.item = mkIf cfg.nickel.enable {
koreader = singleton {
location = "main";
label = "KOReader";
diff --git a/modules/lib/file-type.nix b/modules/lib/file-type.nix
index c95c0d4..f02daa1 100644
--- a/modules/lib/file-type.nix
+++ b/modules/lib/file-type.nix
@@ -1,4 +1,4 @@
-{ writeTextFile, lib, ... }:
+{ writeTextFile, linkFarm, lib, ... }:
{ name, config, ... }:
with builtins // lib;
let
@@ -6,7 +6,7 @@ let
let
safeChars = [ "+" "." "_" "?" "=" ] ++ lowerChars ++ upperChars ++ stringToCharacters "0123456789";
empties = l: genList (_: "") (length l);
- unsafeInName = stringToCharacters (replaceStrings safeChars (empties safeChars) p;
+ unsafeInName = stringToCharacters (replaceStrings safeChars (empties safeChars) p);
in "kobo_" + replaceStrings unsafeInName (empties unsafeInName) p;
in {
options = {
@@ -17,7 +17,7 @@ in {
target = mkOption {
type = types.str;
default = name;
- apply = x: if isPrefix "/" x then x else "/${x}";
+ apply = x: if hasPrefix "/" x then x else "/${x}";
};
executable = mkOption {
type = with types; nullOr bool;
@@ -30,12 +30,24 @@ in {
source = mkOption {
type = types.path;
};
+ _package = mkOption {
+ type = types.path;
+ readOnly = true;
+ internal = true;
+ default = linkFarm (sanitize name) [{
+ name = removePrefix "/" config.target;
+ # let
+ # t = config.target;
+ # in if
+ path = config.source;
+ }];
+ };
};
config = {
- source = mkIf (cfg.text != null) (mkDefault (writeTextFile {
+ source = mkIf (config.text != null) (mkDefault (writeTextFile {
inherit (config) text;
- name = sanitieze name;
+ name = sanitize name;
executable = config.executable == true;
}));
};
diff --git a/modules/nickel/default.nix b/modules/nickel/default.nix
index c5736f0..30b40d4 100644
--- a/modules/nickel/default.nix
+++ b/modules/nickel/default.nix
@@ -57,7 +57,10 @@ in {
type = types.package;
readOnly = true;
internal = true;
- default = (pkgs.callPackage ../lib/merge-files.nix {}) (atrValues cfg.file);
+ default = symlinkJoin {
+ name = "nickel-files";
+ paths = mapAttrsToList (v: v._package) cfg.file;
+ };
};
path = mkOption {
@@ -77,7 +80,8 @@ in {
file = mkOption {
default = {};
- type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {});
+ type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
};
menu = {
@@ -133,21 +137,29 @@ in {
};
};
- config = {
- nickel = {
- file = mkMerge [
- (mapAttrs (_: v: {
- text = concatMapStringsSep "\n" createGenerator v;
- }) cfg.menu.generator)
+ config = mkMerge [
+ {
+ nickel = {
+ file = mkMerge [
+ (mapAttrs (_: v: {
+ text = concatMapStringsSep "\n" createGenerator v;
+ }) cfg.menu.generator)
- (mapAttrs (_: v: {
- text = concatStringsSep "\n" (mapAttrsToList createExperimental v);
- }) cfg.menu.experimental)
+ (mapAttrs (_: v: {
+ text = concatStringsSep "\n" (mapAttrsToList createExperimental v);
+ }) cfg.menu.experimental)
- (mapAttrs (_: v: {
- text = concatMapStringsSep "\n" createMenuItem v;
- }) cfg.menu.item)
- ];
- };
- };
+ (mapAttrs (_: v: {
+ text = concatMapStringsSep "\n" createMenuItem v;
+ }) cfg.menu.item)
+ ];
+ };
+ }
+ (mkIf cfg.enable {
+ koboroot.include = singleton (pkgs.linkFarm [{
+ name = cfg.devicePath;
+ path = cfg._allFiles;
+ }]);
+ })
+ ];
}
diff --git a/modules/plato/default.nix b/modules/plato/default.nix
index 1886662..ac0c5d7 100644
--- a/modules/plato/default.nix
+++ b/modules/plato/default.nix
@@ -10,6 +10,26 @@ in {
package = mkPackageOption pkgs "plato" {};
+ # _unpackage = mkOption {
+ # type = types.package;
+ # readOnly = true;
+ # internal = true;
+ # default = pkgs.buildEnv {
+ # name = "plato-unpackage";
+ # paths = [
+ # (pkgs.runCommandLocal "plato-files" {} ''
+ # mkdir -p "$out${cfg.devicePath}"
+ # cp -r "${cfg.package.out}/" $out${cfg.devicePath}
+ # '')
+ # # (pkgs.linkFarm "plato-files" [{
+ # # name = removePrefix "/" cfg.devicePath;
+ # # path = cfg.package.out;
+ # # }])
+ # cfg.package.KoboRoot
+ # ];
+ # };
+ # };
+
path = mkOption {
type = types.str;
readOnly = true;
@@ -24,18 +44,52 @@ in {
default = "/mnt/onboard/${cfg.path}";
};
+ _createdFiles = mkOption {
+ type = types.package;
+ internal = true;
+ readOnly = true;
+ default = pkgs.buildEnv {
+ name = "plato-files-created";
+ paths = mapAttrsToList (_: v: v._package) cfg.file;
+ extraPrefix = cfg.devicePath;
+ };
+ };
+
+ _finalPackage = mkOption {
+ type = types.package;
+ internal = true;
+ readOnly = true;
+ default = pkgs.symlinkJoin {
+ name = "plato-package";
+ paths = [
+ cfg._createdFiles
+ # (pkgs.linkFarm "plato-files" [{
+ # name = removePrefix "/" cfg.devicePath;
+ # path = cfg.package.out;
+ # }])
+ (pkgs.runCommandLocal "plato-files" {} ''
+ mkdir -p "$(dirname "$out${cfg.devicePath}")"
+ cp -r "${cfg.package.out}" "$out${cfg.devicePath}"
+ '')
+ cfg.package.KoboRoot
+ ];
+ };
+ };
+
_allFiles = mkOption {
type = types.package;
readOnly = true;
internal = true;
- default = (pkgs.callPackage ../lib/merge-files.nix {}) ([
- cfg.package
- ] ++ attrValues cfg.file);
+ default = pkgs.symlinkJoin {
+ name = "plato-files";
+ paths = mapAttrsToList (_: v: v._package) cfg.file ++ [ cfg.package ];
+ };
};
file = mkOption {
default = {};
type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {}));
+ apply = filterAttrs (_: v: v.enable);
};
nickel = {
@@ -51,15 +105,23 @@ in {
'';
};
- config = {
- hyphenation = mkEnableOption "hyphenation" // { default = true; };
- convertDictionaries = mkEnableOption "convert StartDict" // { default = true; };
- setFramebufferDepth = mkEnableOption "set framebuffer's depth" // { default = true; };
- extra = mkOption {
- type = types.lines;
- default = "";
- };
+ config = mkOption {
+ type = types.lines;
+ default = "";
+ description = ''
+ Contents of config.sh
+ '';
};
+
+ # config = {
+ # hyphenation = mkEnableOption "hyphenation" // { default = true; };
+ # convertDictionaries = mkEnableOption "convert StartDict" // { default = true; };
+ # setFramebufferDepth = mkEnableOption "set framebuffer's depth" // { default = true; };
+ # extra = mkOption {
+ # type = types.lines;
+ # default = "";
+ # };
+ # };
# mkOption {
# type = types.lines;
# default = "";
@@ -100,9 +162,9 @@ in {
default =
let
copyFonts = pkg: ''
- find ${pkg}/share/fonts/truetype/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \;
+ find ${pkg}/share/fonts/ -type f -regex '.*\.\(ttf\|otf\)' -exec cp -v {} $out/ \;
'';
- in pkgs.runCommandLocal {} ''
+ in pkgs.runCommandLocal "plato-fonts" {} ''
mkdir $out
${concatMapStringsSep "\n" copyFonts cfg.fonts}
'';
@@ -116,17 +178,21 @@ in {
source = toml.generate "Settings.toml" cfg.settings;
};
- "config.sh" =
- let
- c = optional (!cfg.config.convertDictionaries) "unset PLATO_CONVERT_DICTIONARIES"
- ++ optional (!cfg.config.setFramebufferDepth) "unset PLATO_SET_FRAMEBUFFER_DEPTH"
- ++ optional (!cfg.config.hyphenation) "[ -d hyphenation-patters ] && rm -rf hyphenation-patterns"
- ++ optional (cfg.config.extra != "") cfg.config.extra
- ;
- in mkIf (c != []) {
- text = concatStringsSep "\n\n" c;
+ "config.sh" = mkIf (cfg.config != "") {
+ text = cfg.config;
};
+ # "config.sh" =
+ # let
+ # c = optional (!cfg.config.convertDictionaries) "unset PLATO_CONVERT_DICTIONARIES"
+ # ++ optional (!cfg.config.setFramebufferDepth) "unset PLATO_SET_FRAMEBUFFER_DEPTH"
+ # ++ optional (!cfg.config.hyphenation) "[ -d hyphenation-patters ] && rm -rf hyphenation-patterns"
+ # ++ optional (cfg.config.extra != "") cfg.config.extra
+ # ;
+ # in mkIf (c != []) {
+ # text = concatStringsSep "\n\n" c;
+ # };
+
"_dictionaries" = {
target = "dictionaries";
source = cfg._dictionariesCombined;
@@ -137,8 +203,15 @@ in {
source = cfg._fontsCombined;
};
};
-
- nickel.menu.item = mkIf (cfg.enable && cfg.nickel.enable) {
+ }
+ (mkIf cfg.enable {
+ koboroot.include = singleton cfg._finalPackage;
+ # singleton (pkgs.linkFarm [{
+ # name = cfg.devicePath;
+ # path = cfg._allFiles;
+ # }]);
+
+ nickel.menu.item = mkIf cfg.nickel.enable {
plato = singleton {
location = "main";
label = "Plato";
@@ -149,10 +222,7 @@ in {
];
};
};
- }
- # (mkIf (cfg.enable && cfg.nickelEntry.enable {
- # nickel.menu.item =
- # })
+ })
];
}