summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/languages-frameworks/lua.section.md6
-rw-r--r--maintainers/scripts/pluginupdate.py15
-rw-r--r--maintainers/scripts/update-luarocks-shell.nix13
-rw-r--r--nixos/doc/manual/release-notes/rl-2311.section.md4
-rw-r--r--pkgs/development/lua-modules/updater/default.nix49
-rwxr-xr-xpkgs/development/lua-modules/updater/updater.py (renamed from maintainers/scripts/update-luarocks-packages)31
-rw-r--r--pkgs/top-level/all-packages.nix5
7 files changed, 85 insertions, 38 deletions
diff --git a/doc/languages-frameworks/lua.section.md b/doc/languages-frameworks/lua.section.md
index c5049326a776f..310ea88a86d55 100644
--- a/doc/languages-frameworks/lua.section.md
+++ b/doc/languages-frameworks/lua.section.md
@@ -134,11 +134,11 @@ The site proposes two types of packages, the `rockspec` and the `src.rock`
 
 Luarocks-based packages are generated in [pkgs/development/lua-modules/generated-packages.nix](https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/lua-modules/generated-packages.nix) from
 the whitelist maintainers/scripts/luarocks-packages.csv and updated by running
-the script
-[maintainers/scripts/update-luarocks-packages](https://github.com/NixOS/nixpkgs/tree/master/maintainers/scripts/update-luarocks-packages):
+the package `luarocks-packages-updater`:
 
 ```sh
-./maintainers/scripts/update-luarocks-packages update
+
+nix-shell -p luarocks-packages-updater --run luarocks-packages-updater
 ```
 
 [luarocks2nix](https://github.com/nix-community/luarocks) is a tool capable of generating nix derivations from both rockspec and src.rock (and favors the src.rock).
diff --git a/maintainers/scripts/pluginupdate.py b/maintainers/scripts/pluginupdate.py
index 52e9af399709b..44a445875d918 100644
--- a/maintainers/scripts/pluginupdate.py
+++ b/maintainers/scripts/pluginupdate.py
@@ -468,6 +468,7 @@ class Editor:
             "--input-names",
             "-i",
             dest="input_file",
+            type=Path,
             default=self.default_in,
             help="A list of plugins in the form owner/repo",
         )
@@ -476,6 +477,7 @@ class Editor:
             "-o",
             dest="outfile",
             default=self.default_out,
+            type=Path,
             help="Filename to save generated nix code",
         )
         common.add_argument(
@@ -787,10 +789,17 @@ def update_plugins(editor: Editor, args):
 
     if autocommit:
         from datetime import date
-        editor.nixpkgs_repo = git.Repo(editor.root, search_parent_directories=True)
-        updated = date.today().strftime('%m-%d-%Y')
 
-        commit(editor.nixpkgs_repo, f"{editor.attr_path}: updated the {updated}", [args.outfile])
+        try:
+            repo = git.Repo(os.getcwd())
+            updated = date.today().strftime('%m-%d-%Y')
+            print(args.outfile)
+            commit(repo,
+                   f"{editor.attr_path}: updated the {updated}", [args.outfile]
+                   )
+        except git.InvalidGitRepositoryError as e:
+            print(f"Not in a git repository: {e}", file=sys.stderr)
+            sys.exit(1)
 
     if redirects:
         update()
diff --git a/maintainers/scripts/update-luarocks-shell.nix b/maintainers/scripts/update-luarocks-shell.nix
deleted file mode 100644
index 346b0319b08c9..0000000000000
--- a/maintainers/scripts/update-luarocks-shell.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ nixpkgs ? import ../.. { }
-}:
-with nixpkgs;
-let
-  pyEnv = python3.withPackages(ps: [ ps.gitpython ]);
-in
-mkShell {
-  packages = [
-    pyEnv
-    luarocks-nix
-    nix-prefetch-scripts
-  ];
-}
diff --git a/nixos/doc/manual/release-notes/rl-2311.section.md b/nixos/doc/manual/release-notes/rl-2311.section.md
index 76d9b026aa08a..018e1e2f478ba 100644
--- a/nixos/doc/manual/release-notes/rl-2311.section.md
+++ b/nixos/doc/manual/release-notes/rl-2311.section.md
@@ -162,6 +162,10 @@
 
 - `getent` has been moved from `glibc`'s `bin` output to its own dedicated output, reducing closure size for many dependents. Dependents using the `getent` alias should not be affected; others should move from using `glibc.bin` or `getBin glibc` to `getent` (which also improves compatibility with non-glibc platforms).
 
+- `maintainers/scripts/update-luarocks-packages` is now a proper package
+  `luarocks-packages-updater` that can be run to maintain out-of-tree luarocks
+  packages
+
 - The `users.users.<name>.passwordFile` has been renamed to `users.users.<name>.hashedPasswordFile` to avoid possible confusions. The option is in fact the file-based version of `hashedPassword`, not `password`, and expects a file containing the {manpage}`crypt(3)` hash of the user password.
 
 - The `services.ananicy.extraRules` option now has the type of `listOf attrs` instead of `string`.
diff --git a/pkgs/development/lua-modules/updater/default.nix b/pkgs/development/lua-modules/updater/default.nix
new file mode 100644
index 0000000000000..40c93b21e8318
--- /dev/null
+++ b/pkgs/development/lua-modules/updater/default.nix
@@ -0,0 +1,49 @@
+{ buildPythonApplication
+, nix
+, makeWrapper
+, python3Packages
+, lib
+# , nix-prefetch-git
+, nix-prefetch-scripts
+, luarocks-nix
+}:
+let
+
+    path = lib.makeBinPath [ nix nix-prefetch-scripts luarocks-nix ];
+in
+buildPythonApplication {
+  pname = "luarocks-packages-updater";
+  version = "0.1";
+
+  format = "other";
+
+  nativeBuildInputs = [
+    makeWrapper
+    python3Packages.wrapPython
+  ];
+  propagatedBuildInputs = [
+    python3Packages.gitpython
+  ];
+
+  dontUnpack = true;
+
+  installPhase =
+    ''
+    mkdir -p $out/bin $out/lib
+    cp ${./updater.py} $out/bin/luarocks-packages-updater
+    cp ${../../../../maintainers/scripts/pluginupdate.py} $out/lib/pluginupdate.py
+
+    # wrap python scripts
+    makeWrapperArgs+=( --prefix PATH : "${path}" --prefix PYTHONPATH : "$out/lib" )
+    wrapPythonProgramsIn "$out"
+  '';
+
+  shellHook = ''
+    export PYTHONPATH="maintainers/scripts:$PYTHONPATH"
+    export PATH="${path}:$PATH"
+  '';
+
+  meta.mainProgram = "luarocks-packages-updater";
+}
+
+
diff --git a/maintainers/scripts/update-luarocks-packages b/pkgs/development/lua-modules/updater/updater.py
index 32c2b44260b32..89a9bd9823a72 100755
--- a/maintainers/scripts/update-luarocks-packages
+++ b/pkgs/development/lua-modules/updater/updater.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env nix-shell
-#!nix-shell update-luarocks-shell.nix -i python3
-
+#!/usr/bin/env python
 # format:
 # $ nix run nixpkgs#python3Packages.black -- update.py
 # type-check:
@@ -32,12 +30,9 @@ from pluginupdate import update_plugins, FetchConfig, CleanEnvironment
 PKG_LIST = "maintainers/scripts/luarocks-packages.csv"
 TMP_FILE = "$(mktemp)"
 GENERATED_NIXFILE = "pkgs/development/lua-modules/generated-packages.nix"
-LUAROCKS_CONFIG = "maintainers/scripts/luarocks-config.lua"
 
 HEADER = """/* {GENERATED_NIXFILE} is an auto-generated file -- DO NOT EDIT!
-Regenerate it with:
-nixpkgs$ ./maintainers/scripts/update-luarocks-packages
-
+Regenerate it with: nix run nixpkgs#update-luarocks-packages
 You can customize the generated packages in pkgs/development/lua-modules/overrides.nix
 */
 """.format(
@@ -76,6 +71,12 @@ class LuaPlugin:
 
 # rename Editor to LangUpdate/ EcosystemUpdater
 class LuaEditor(pluginupdate.Editor):
+
+    def create_parser(self):
+        parser = super().create_parser()
+        parser.set_defaults(proc=1)
+        return parser
+
     def get_current_plugins(self):
         return []
 
@@ -101,9 +102,8 @@ class LuaEditor(pluginupdate.Editor):
         with tempfile.NamedTemporaryFile("w+") as f:
             f.write(HEADER)
             header2 = textwrap.dedent(
-                # header2 = inspect.cleandoc(
                 """
-                { self, stdenv, lib, fetchurl, fetchgit, callPackage, ... } @ args:
+                { stdenv, lib, fetchurl, fetchgit, callPackage, ... } @ args:
                 final: prev:
                 {
             """
@@ -165,12 +165,7 @@ def generate_pkg_nix(plug: LuaPlugin):
     Our cache key associates "p.name-p.version" to its rockspec
     """
     log.debug("Generating nix expression for %s", plug.name)
-    custom_env = os.environ.copy()
-    custom_env["LUAROCKS_CONFIG"] = LUAROCKS_CONFIG
 
-    # we add --dev else luarocks wont find all the "scm" (=dev) versions of the
-    # packages
-    # , "--dev"
     cmd = ["luarocks", "nix"]
 
     if plug.maintainers:
@@ -201,7 +196,7 @@ def generate_pkg_nix(plug: LuaPlugin):
 
     log.debug("running %s", " ".join(cmd))
 
-    output = subprocess.check_output(cmd, env=custom_env, text=True)
+    output = subprocess.check_output(cmd, text=True)
     output = "callPackage(" + output.strip() + ") {};\n\n"
     return (plug, output)
 
@@ -211,8 +206,8 @@ def main():
         "lua",
         ROOT,
         "",
-        default_in=ROOT.joinpath(PKG_LIST),
-        default_out=ROOT.joinpath(GENERATED_NIXFILE),
+        default_in=PKG_LIST,
+        default_out=GENERATED_NIXFILE,
     )
 
     editor.run()
@@ -220,5 +215,3 @@ def main():
 
 if __name__ == "__main__":
     main()
-
-#  vim: set ft=python noet fdm=manual fenc=utf-8 ff=unix sts=0 sw=4 ts=4 :
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f03ee45e1f65a..729c2d604e643 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -17766,6 +17766,11 @@ with pkgs;
   luarocks = luaPackages.luarocks;
   luarocks-nix = luaPackages.luarocks-nix;
 
+  luarocks-packages-updater = callPackage ../development/lua-modules/updater {
+    inherit (python3Packages) buildPythonApplication ;
+  };
+
+
   luau = callPackage ../development/interpreters/luau { };
 
   lune = callPackage ../development/interpreters/lune { };