diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 6588e9c069d767..cc4014769cacd8 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -97,6 +97,8 @@ +- `ast-grep` remove `sg` command to prevent conflict with `sg` command from shadow-utils. If you need legacy sg command compatibility with old code, you can use `ast-grep.override { enableLegacySg = true; }` + - `binwalk` was updated to 3.1.0, which has been rewritten in rust. The python module is no longer available. See the release notes of [3.1.0](https://github.com/ReFirmLabs/binwalk/releases/tag/v3.1.0) for more information. diff --git a/pkgs/by-name/as/ast-grep/package.nix b/pkgs/by-name/as/ast-grep/package.nix index a25bb7ef0a4c8c..265b9f8e03d64e 100644 --- a/pkgs/by-name/as/ast-grep/package.nix +++ b/pkgs/by-name/as/ast-grep/package.nix @@ -4,6 +4,9 @@ fetchFromGitHub, stdenv, installShellFiles, + buildPackages, + versionCheckHook, + enableLegacySg ? false, }: rustPlatform.buildRustPackage rec { @@ -26,12 +29,27 @@ rustPlatform.buildRustPackage rec { rm .cargo/config.toml ''; - postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' - installShellCompletion --cmd sg \ - --bash <($out/bin/sg completions bash) \ - --fish <($out/bin/sg completions fish) \ - --zsh <($out/bin/sg completions zsh) - ''; + cargoBuildFlags = [ + "--package ast-grep --bin ast-grep" + ] ++ lib.optionals enableLegacySg [ "--package ast-grep --bin sg" ]; + + postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ( + let + emulator = stdenv.hostPlatform.emulator buildPackages; + in + '' + installShellCompletion --cmd ast-grep \ + --bash <(${emulator} $out/bin/ast-grep completions bash) \ + --fish <(${emulator} $out/bin/ast-grep completions fish) \ + --zsh <(${emulator} $out/bin/ast-grep completions zsh) + '' + + lib.optionalString enableLegacySg '' + installShellCompletion --cmd sg \ + --bash <(${emulator} $out/bin/sg completions bash) \ + --fish <(${emulator} $out/bin/sg completions fish) \ + --zsh <(${emulator} $out/bin/sg completions zsh) + '' + ); checkFlags = [ @@ -48,14 +66,20 @@ rustPlatform.buildRustPackage rec { "--skip=test::test_load_parser" "--skip=test::test_register_lang" ]; + nativeInstallCheckInputs = [ + versionCheckHook + ]; + versionCheckProgramArg = [ "--version" ]; + doInstallCheck = true; meta = with lib; { - mainProgram = "sg"; + mainProgram = "ast-grep"; description = "Fast and polyglot tool for code searching, linting, rewriting at large scale"; homepage = "https://ast-grep.github.io/"; changelog = "https://github.com/ast-grep/ast-grep/blob/${src.rev}/CHANGELOG.md"; license = licenses.mit; maintainers = with maintainers; [ + xiaoxiangmoe montchr lord-valen cafkafk