{ config, pkgs, lib, ... }: with builtins // lib; let cfg = config.kfmon; ini = pkgs.formats.ini {}; in { options.kfmon = { enable = mkEnableOption "KFMon"; package = mkPackageOption pkgs "kfmon" {}; path = mkOption { type = types.str; readOnly = true; internal = true; default = ".adds/kfmon"; }; devicePath = mkOption { type = types.str; readOnly = true; internal = true; default = "/mnt/onboard/${cfg.path}"; }; file = mkOption { default = {}; type = types.attrsOf (types.submodule (pkgs.callPackage ../lib/file-type.nix {})); apply = filterAttrs (_: v: v.enable); }; _createdFiles = mkOption { type = types.package; internal = true; readOnly = true; default = pkgs.buildEnv { name = "kfmon-files-created"; paths = mapAttrsToList (_: v: v._package) cfg.file; extraPrefix = cfg.devicePath; }; }; finalPackage = mkOption { type = types.package; internal = true; readOnly = true; default = pkgs.mergePaths { name = "kfmon-package"; paths = [ (pkgs.linkFarm "kfmon" [{ name = removePrefix "/" cfg.devicePath; path = cfg.package.out; }]) cfg._createdFiles cfg.package.KoboRoot ]; }; }; # _allFiles = mkOption { # type = types.package; # internal = true; # readOnly = true; # default = pkgs.symlinkJoin { # name = "kfmon-files"; # paths = mapAttrsToList (v: v._package) cfg.file; # }; # }; configs = mkOption { type = types.attrsOf ini.type; default = {}; description = '' KFMon .ini config files. Do not touch this unless you know what you're doing! ''; }; }; config = mkMerge [ { info.kfmon = cfg.enable; 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 = singleton cfg.finalPackage; # koboroot.include = [ # (pkgs.linkFarm [{ # name = cfg.devicePath; # path = cfg._allFiles; # }]) # cfg.package.KoboRoot # ]; }) ]; }