Skip to content

pre-commit: add rustup and gcc to support nixpkgs-fmt pre-commit-hook support#340113

Open
MSchmoecker wants to merge 1 commit intoNixOS:masterfrom
MSchmoecker:fix/pre-commit
Open

pre-commit: add rustup and gcc to support nixpkgs-fmt pre-commit-hook support#340113
MSchmoecker wants to merge 1 commit intoNixOS:masterfrom
MSchmoecker:fix/pre-commit

Conversation

@MSchmoecker
Copy link

@MSchmoecker MSchmoecker commented Sep 6, 2024

Description of changes

Rustup and gcc are needed in the PATH to use the nixpkgs-fmt pre-commit hook. Otherwise, pre-commit tries to install the dependencies in the pre-commit toolchain and fails:

$ pre-commit run
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[INFO] Initializing environment for https://github.com/PyCQA/autoflake.
[INFO] Initializing environment for https://github.com/nix-community/nixpkgs-fmt.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/autoflake.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/nix-community/nixpkgs-fmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/bin/sh', '/tmp/tmpukmvn9aq/rustup-init', '-y', '--quiet', '--no-modify-path', '--default-toolchain', 'none')
return code: 1
stdout: (none)
stderr:
    info: downloading installer
    Could not start dynamically linked executable: /tmp/tmp.QF1anEeoYg/rustup-init
    NixOS cannot run dynamically linked executables intended for generic
    linux environments out of the box. For more information, see:
    https://nix.dev/permalink/stub-ld
Check the log at /home/user/.cache/pre-commit/pre-commit.log

Without gcc (only rustup):

$ pre-commit run
[INFO] Installing environment for https://github.com/nix-community/nixpkgs-fmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/nix/store/691v6lwgyz0jhwv754c64lkk372yy1v8-rustup-1.26.0/bin/cargo', 'install', '--bins', '--root', '/home/max/.cache/pre-commit/repopsn8ksx5/rustenv-default', '--path', '.')
return code: 101
stdout: (none)
stderr:
    info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
    info: latest update on 2024-09-05, rust version 1.81.0 (eeb90cda1 2024-09-04)
    info: downloading component 'cargo'
    info: downloading component 'clippy'
    info: downloading component 'rust-docs'
    info: downloading component 'rust-std'
    info: downloading component 'rustc'
    info: downloading component 'rustfmt'
    info: installing component 'cargo'
    info: installing component 'clippy'
    info: installing component 'rust-docs'
    info: installing component 'rust-std'
    info: installing component 'rustc'
    info: installing component 'rustfmt'
      Installing nixpkgs-fmt v1.3.0 (/home/max/.cache/pre-commit/repopsn8ksx5)
        Updating crates.io index
         Locking 63 packages to latest compatible versions
          Adding bitflags v1.3.2 (latest: v2.6.0)
          Adding cfg-if v0.1.10 (latest: v1.0.0)
          Adding clap v2.34.0 (latest: v4.5.17)
          Adding countme v2.0.4 (latest: v3.0.1)
          Adding crossbeam-channel v0.4.4 (latest: v0.5.13)
          Adding crossbeam-utils v0.7.2 (latest: v0.8.20)
          Adding hashbrown v0.9.1 (latest: v0.14.5)
          Adding hermit-abi v0.1.19 (latest: v0.4.0)
          Adding memoffset v0.6.5 (latest: v0.9.1)
          Adding rnix v0.10.2 (latest: v0.11.0)
          Adding rowan v0.12.6 (latest: v0.15.16)
          Adding rustc-hash v1.1.0 (latest: v2.0.0)
          Adding smol_str v0.1.24 (latest: v0.3.1)
          Adding strsim v0.8.0 (latest: v0.11.1)
          Adding textwrap v0.11.0 (latest: v0.16.1)
     Downloading crates ...
      Downloaded serde v1.0.209
      Downloaded serde_json v1.0.128
      Downloaded libc v0.2.158
       Compiling autocfg v1.3.0
       Compiling serde v1.0.209
       Compiling memchr v2.7.4
       Compiling crossbeam-utils v0.8.20
       Compiling libc v0.2.158
       Compiling maybe-uninit v2.0.0
       Compiling regex-syntax v0.8.4
       Compiling log v0.4.22
       Compiling hashbrown v0.9.1
       Compiling serde_json v1.0.128
       Compiling countme v2.0.4
       Compiling unicode-width v0.1.13
    error: linker `cc` not found
      |
      = note: No such file or directory (os error 2)
    
    error: could not compile `serde_json` (build script) due to 1 previous error
    warning: build failed, waiting for other jobs to finish...
    error: could not compile `serde` (build script) due to 1 previous error
    error: could not compile `maybe-uninit` (build script) due to 1 previous error
    error: could not compile `crossbeam-utils` (build script) due to 1 previous error
    error: could not compile `libc` (build script) due to 1 previous error
    error: failed to compile `nixpkgs-fmt v1.3.0 (/home/user/.cache/pre-commit/repopsn8ksx5)`, intermediate artifacts can be found at `/home/user/.cache/pre-commit/repopsn8ksx5/target`.
    To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
Check the log at /home/user/.cache/pre-commit/pre-commit.log

While nixpkgs-fmt is deprecated, the replacement nixfmt does not contain pre-commit hooks in the 0.6.0 release and was just merged NixOS/nixfmt#238 on the master branch. Thus, this PR adds toolchain support for nixpkgs-fmt until nixfmt is stable.

I am not completely sure if adding the dependencies to nixpkgs is the best place, however it makes the installation of pre-commit for nix related projects much easier.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label Sep 6, 2024
@ofborg ofborg bot requested a review from borisbabic September 6, 2024 16:47
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Sep 6, 2024
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 29, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 9, 2024
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants