summary refs log tree commit diff
path: root/pkgs/applications/editors/kakoune
diff options
context:
space:
mode:
authorFlakebi <flakebi@t-online.de>2021-02-20 10:12:21 +0100
committerFlakebi <flakebi@t-online.de>2021-02-25 10:05:22 +0100
commit3ad7ba46c502d96821362579fc76c6a07364bb67 (patch)
tree0624ad335d9b6a8d449e077f1c495c253bbc7ac3 /pkgs/applications/editors/kakoune
parent2123e325c969344b79482b5335e1a8c9770f505f (diff)
downloadnixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar.gz
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar.bz2
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar.lz
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar.xz
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.tar.zst
nixpkgs-3ad7ba46c502d96821362579fc76c6a07364bb67.zip
vimPlugins: add vim and kakoune update script
Diffstat (limited to 'pkgs/applications/editors/kakoune')
-rwxr-xr-xpkgs/applications/editors/kakoune/plugins/update.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/pkgs/applications/editors/kakoune/plugins/update.py b/pkgs/applications/editors/kakoune/plugins/update.py
new file mode 100755
index 00000000000..b6a4bfe4f41
--- /dev/null
+++ b/pkgs/applications/editors/kakoune/plugins/update.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -p nix-prefetch-git -p python3 -p python3Packages.GitPython nix -i python3
+
+# format:
+# $ nix run nixpkgs.python3Packages.black -c black update.py
+# type-check:
+# $ nix run nixpkgs.python3Packages.mypy -c mypy update.py
+# linted:
+# $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265,E402 update.py
+
+import inspect
+import os
+import sys
+from typing import List, Tuple
+from pathlib import Path
+
+# Import plugin update library from maintainers/scripts/pluginupdate.py
+ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
+sys.path.insert(
+    0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
+)
+import pluginupdate
+
+GET_PLUGINS = f"""(with import <localpkgs> {{}};
+let
+  inherit (kakouneUtils.override {{}}) buildKakounePluginFrom2Nix;
+  generated = callPackage {ROOT}/generated.nix {{
+    inherit buildKakounePluginFrom2Nix;
+  }};
+  hasChecksum = value: lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value;
+  getChecksum = name: value:
+    if hasChecksum value then {{
+      submodules = value.src.fetchSubmodules or false;
+      sha256 = value.src.outputHash;
+      rev = value.src.rev;
+    }} else null;
+  checksums = lib.mapAttrs getChecksum generated;
+in lib.filterAttrs (n: v: v != null) checksums)"""
+
+HEADER = "# This file has been generated by ./pkgs/applications/editors/kakoune/plugins/update.py. Do not edit!"
+
+
+def generate_nix(plugins: List[Tuple[str, str, pluginupdate.Plugin]], outfile: str):
+    sorted_plugins = sorted(plugins, key=lambda v: v[2].name.lower())
+
+    with open(outfile, "w+") as f:
+        f.write(HEADER)
+        f.write(
+            """
+{ lib, buildKakounePluginFrom2Nix, fetchFromGitHub, overrides ? (self: super: {}) }:
+let
+  packages = ( self:
+{"""
+        )
+        for owner, repo, plugin in sorted_plugins:
+            if plugin.has_submodules:
+                submodule_attr = "\n      fetchSubmodules = true;"
+            else:
+                submodule_attr = ""
+
+            f.write(
+                f"""
+  {plugin.normalized_name} = buildKakounePluginFrom2Nix {{
+    pname = "{plugin.normalized_name}";
+    version = "{plugin.version}";
+    src = fetchFromGitHub {{
+      owner = "{owner}";
+      repo = "{repo}";
+      rev = "{plugin.commit}";
+      sha256 = "{plugin.sha256}";{submodule_attr}
+    }};
+    meta.homepage = "https://github.com/{owner}/{repo}/";
+  }};
+"""
+            )
+        f.write(
+            """
+});
+in lib.fix' (lib.extends overrides packages)
+"""
+        )
+    print(f"updated {outfile}")
+
+
+def main():
+    editor = pluginupdate.Editor("kakoune", ROOT, GET_PLUGINS, generate_nix)
+    pluginupdate.update_plugins(editor)
+
+
+if __name__ == "__main__":
+    main()