Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: attribute 'x86_64-linux' in selection path '"x86_64-linux"' not found building 3.0.0 #354

Closed
l0b0 opened this issue Sep 22, 2022 · 9 comments

Comments

@l0b0
Copy link
Contributor

l0b0 commented Sep 22, 2022

With the latest unstable nixpkgs

  pkgs ?
    import
    (
      fetchTarball
      {
        name = "nixos-22.11pre405560.2da64a81275";
        url = "https://github.com/NixOS/nixpkgs/archive/2da64a81275b68fdad38af669afeda43d401e94b.tar.gz";
        sha256 = "1k71lmzdaa48yqkmsnd22n177qmxxi4gj2qcmdbv0mc6l4f27wd0";
      }
    )
    {},

and latest alejandra

  - repo: https://github.com/kamadorueda/alejandra
    rev: ef03f7ef74ec97fd91a016a51c9c9667fb315652 # 3.0.0
    hooks:
      - id: alejandra
        stages: [commit]

alejandra fails to build on NixOS 22.05:

$ pre-commit run --all-files alejandra
alejandra (Nix)..........................................................Failed
- hook id: alejandra
- exit code: 1

+ command -v nix-build
/run/current-system/sw/bin/nix-build
+ '!command' -v nix-instantiate
/home/victor/.cache/pre-commit/repoogox7jk3/.pre-commit-entry.sh: line 10: !command: command not found
+ echo INFO: computing current system
INFO: computing current system
++ nix-instantiate --eval --expr builtins.currentSystem
+ system='"x86_64-linux"'
+ echo INFO: building Alejandra
INFO: building Alejandra
+ nix-build --attr '"x86_64-linux"' --out-link result-alejandra https://github.com/kamadorueda/alejandra/tarball/3.0.0
error: attribute 'x86_64-linux' in selection path '"x86_64-linux"' not found
@tobiasBora
Copy link
Contributor

tobiasBora commented Oct 18, 2022

How are you building the package exactly? In my case it just works (for this command to work, you need to have flake enabled):

$ nix run github:kamadorueda/alejandra/3.0.0
Formatting stdin.
Use --help to see all command line options.
use --quiet to suppress this and other messages.

@l0b0
Copy link
Contributor Author

l0b0 commented Oct 18, 2022

I don't have flakes enabled, since they are not a stable feature yet. Does Alejandra not work without flakes?

@tobiasBora
Copy link
Contributor

It does, flake is just quicker for me to test and it more deterministic since everybody uses exactly the same source.
Without the flake you can do:

$ cat b.nix
(import (builtins.fetchTarball {
    url = "https://github.com/kamadorueda/alejandra/tarball/3.0.0";
    sha256 = "sha256:18jm0d5xrxk38hw5sa470zgfz9xzdcyaskjhgjwhnmzd5fgacny4";
}) {})
$ nix-build b.nix
$ ./result/bin/alejandra
Formatting stdin.
Use --help to see all command line options.
use --quiet to suppress this and other mess

You can enable flake temporarily if needed:

$ nix --experimental-features 'nix-command flakes' run github:kamadorueda/alejandra/3.0.0

So unless you explain how you are building alejandra we cannot help you.

@l0b0
Copy link
Contributor Author

l0b0 commented Oct 19, 2022

I'm building it by running nix-shell --pure --run 'pre-commit run --all-files alejandra' in the feat/format-nix-files-using-alejandra branch of the linz/geostore GitHub project on NixOS 22.05 (nix-build (Nix) 2.8.1). I feel like I'm misunderstanding, and I need to run some other build before this will succeed.

@tobiasBora
Copy link
Contributor

tobiasBora commented Oct 19, 2022

Oh ok now everything is clear (sorry, I never used alejandra before, and I was not even aware of the existence of pre-commit). So I can confirm, this is a bug from alejandra's side, sorry for my previous messages (next time give maybe a bit more context ^^).

So basically when you call pre-commit it will call this file https://github.com/kamadorueda/alejandra/blob/main/.pre-commit-entry.sh . Thanks to git blame, you can see that the commit that introduces the nix-build --attr ${system} … line is 131c177 to provide "a more robust" pre-commit hook. Back then it was working fine because the default.nix file was directly outputting the flake flake.defaultNix.defaultPackage that creates an attribute set indexed by systems like

{
  x86_64-linux = yourpackage;
}

so the --attr option in nixpkgs was making sense. But now, default.nix is different and automatically guesses the current system. So the fix is actually just to remove the --attr part of the build command.

I just created a PR here I guess you should be able to test it using my fork instead of the main project.

@l0b0
Copy link
Contributor Author

l0b0 commented Oct 19, 2022

Thank you very much, @tobiasBora! Your fix does indeed work, I just had to add pkgs.nix to my Nix shell.

@bittner
Copy link

bittner commented Nov 3, 2024

Do you plan to release a new version of alejandra, so that a pre-commit configuration without prerequisites can work out-of-the-box? Currently, the setup fails with the error in question, e.g.

$ uv run pre-commit
alejandra (Nix)..........................................................Failed
- hook id: alejandra
- exit code: 1

+ command -v nix-build
/nix/var/nix/profiles/default/bin/nix-build
+ !command -v nix-instantiate
/home/peter/.cache/pre-commit/repoe9izwwkz/.pre-commit-entry.sh: 10: !command: not found
+ echo INFO: computing current system
INFO: computing current system
+ nix-instantiate --eval --expr builtins.currentSystem
+ system="x86_64-linux"
+ echo INFO: building Alejandra
INFO: building Alejandra
+ nix-build --attr "x86_64-linux" --out-link result-alejandra https://github.com/kamadorueda/alejandra/tarball/3.0.0
error: attribute 'x86_64-linux' in selection path '"x86_64-linux"' not found

Note that for the current main the pre-commit doesn't build alejandra successfully (cargo error; though that might be specific to uv). An example of a working commit is 378cde9.

@kamadorueda
Copy link
Owner

@bittner I just released 3.1.0. Please let me know if this fixes the issues you mention. The !command: not found and the missing attribute errors should be gone. Please note that the alejandra hook was renamed to alejandra-nix, so you should rename it in your config too if you want to use nix to build it. The alejandra hook will build from source using the Rust installed in the host I think

@bittner
Copy link

bittner commented Nov 4, 2024

I just released 3.1.0.

Looks good, works fine with alejandra-nix. Thank you! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants