luarocks-packages-update: init (#262156)

* luarocks-packages-updater: init

Goal is to make it possible to maintain out-of-tree luarocks packages
without needing to clone nixpkgs.

maintainers/scripts/update-luarocks-packages gets renamed to
pkgs/development/lua-modules/updater/updater.py

Once merged you can run for instance
nix run nixpkgs#luarocks-packages-updater -- -i contrib/luarocks-packages.csv -o contrib/generated-packages.nix

I also set the parallelism (--proc) to 1 by default else luarocks fails
because of https://github.com/luarocks/luarocks/issues/1540

* Update maintainers/scripts/pluginupdate.py

Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>

---------

Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>
This commit is contained in:
Matthieu Coudron 2023-10-29 21:02:55 +01:00 committed by GitHub
parent 24df047637
commit f15e58cbeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 38 deletions

View File

@ -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).

View File

@ -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()

View File

@ -1,13 +0,0 @@
{ nixpkgs ? import ../.. { }
}:
with nixpkgs;
let
pyEnv = python3.withPackages(ps: [ ps.gitpython ]);
in
mkShell {
packages = [
pyEnv
luarocks-nix
nix-prefetch-scripts
];
}

View File

@ -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`.

View File

@ -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";
}

View File

@ -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 :

View File

@ -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 { };