From cbde891d1ced129f6284cbadade652182aa5d2fb Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Wed, 14 Feb 2024 15:13:20 -0600 Subject: Fixing my earlier mistakes --- modules/lib/file.nix | 43 +++++++++++++++++++++++++++++++++++++++++++ modules/lib/manifest.nix | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 modules/lib/file.nix create mode 100644 modules/lib/manifest.nix (limited to 'modules/lib') diff --git a/modules/lib/file.nix b/modules/lib/file.nix new file mode 100644 index 0000000..4e7a595 --- /dev/null +++ b/modules/lib/file.nix @@ -0,0 +1,43 @@ +{ lib, pkgs, ... }: +with builtins // lib; + +basePath: +rec { + option = mkOption { + type = fileType; + default = {}; + description = "Files relative to ${basePath}"; + }; + + type = types.attrsOf (types.submodule ({ name, config, ... }: { + options = { + enable = mkEnableOption name // { default = text != ""; }; + target = mkOption { + type = types.str; + default = name; + apply = p: if basePath == "" || isPrefix basePath p then p else "${basePath}/${p}"; + }; + executable = mkOption { + type = with types; nullOr bool; + default = null; + }; + source = mkOption { + type = types.path; + }; + text = mkOption { + type = with types; nullOr lines; + default = null; + }; + }; + + config = mkMerge [ + (mkIf (config.text != null) { + source = mkDefault pkgs.writeTextFile { + inherit name; + inherit (config) text; + executable = config.executable == true; + }; + }) + ]; + })) +} diff --git a/modules/lib/manifest.nix b/modules/lib/manifest.nix new file mode 100644 index 0000000..1acb567 --- /dev/null +++ b/modules/lib/manifest.nix @@ -0,0 +1,41 @@ +{ pkgs, lib, ... }: +with builtins // lib; + +basePath: +rec { + option = mkOption { + type = manifestType; + default = {}; + description = "Manifest relative to ${basePath}"; + }; + type = types.attrsOf (types.submodule ({ name, config, ... }: { + options = { + enable = mkEnableOption name // { default = true; }; + targets = mkOption { + type = with types; listOf str; + default = [ name ]; + apply = map (p: if basePath = "" || isPrefix basePath p then p else "${basePath}/${p}"); + }; + mergeTool = mkOption { + type = with types; functionTo (functionTo str); + description = '' + Sometimes we don't just want to overwrite the existing kobo file; instead we need to merge them. + This is the executable which does this. + The first argument is the local file and the second is the kobo file. + Note that the local file path and the kobo file path only disagree in their top-level directory and otherwise are the same path. + ''; + example = '' + localFile: koboFile: "cp ''${localFile} ''${koboFile}" + ''; + }; + # remoteOnly = mkOption { + # type = types.bool; + # default = false; + # description = '' + # In general, the manifest only considers local files that match the target/pattern. + # Setting this to true means that the kobo files will be scanned and the provided mergeTool will be run with the first argument set to null. + # ''; + # }; + }; + })) +} -- cgit v1.2.3