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

I'm able to use cowsay and hello, but I can't get curl to be exposed #595

Open
blockjon-dd opened this issue Sep 20, 2024 · 3 comments
Open

Comments

@blockjon-dd
Copy link

blockjon-dd commented Sep 20, 2024

Consider this flake.nix:

{
  description = "CLI tools used by the build system";

  inputs = {
    # Use the latest version of nixpkgs
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; # Adjust the version as needed
  };

  outputs = { self, nixpkgs }: let
    system = "aarch64-linux"; # Use aarch64 for ARM architecture
    pkgs = import nixpkgs { system = system; };

  in {
    # The default package
    packages.${system} = {
      default = pkgs.hello;
      hello = pkgs.hello;
      awscli2 = pkgs.awscli2;
      curl = pkgs.curl;
      cowsay = pkgs.cowsay;
    };

    # A development shell with the hello package available
    devShells.${system}.default = pkgs.mkShell {
      buildInputs = [ pkgs.hello pkgs.awscli2 pkgs.curl pkgs.cowsay ];
    };

    # Default application for testing
    apps.${system}.default = {
      type = "app";
      program = "${pkgs.hello}/bin/hello";
    };

  };
}

For some reason when I target the file like this:

nixpkgs_flake_package(
    name = "mycurl",
    nix_flake_file = "//tools/flakes:flake.nix",
    nix_flake_lock_file = "//tools/flakes:flake.lock",
    package = "curl",
)

I'm unable to actually get a genrule working that uses curl. It seems like the curl command is not under bin/curl, as is the case with the other cli's like hello and cowsay.

genrule(
    name = "curl",
    srcs = ["@mycurl//:bin/curl"],
    outs = ["curlcli/curl"],
    executable = True,
    cmd = "cp $(<) $@",
)

Here's the error I'm getting:

$ bazel run //tools/curl
INFO: Invocation ID: 27a89cae-2e4f-4ec8-b5fa-2a461deef854
ERROR: /home/dev/.cache/bazel/_bazel_dev/155bb1574771dc607335fbe8110386b4/external/mycurl/BUILD: no such target '@@mycurl//:bin/curl': target 'bin/curl' not declared in package '' defined by /home/dev/.cache/bazel/_bazel_dev/155bb1574771dc607335fbe8110386b4/external/mycurl/BUILD
ERROR: /workspaces/dd/tools/curl/BUILD.bazel:17:8: no such target '@@mycurl//:bin/curl': target 'bin/curl' not declared in package '' defined by /home/dev/.cache/bazel/_bazel_dev/155bb1574771dc607335fbe8110386b4/external/mycurl/BUILD and referenced by '//tools/curl:curl'
ERROR: Analysis of target '//tools/curl:curl' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.067s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

here's a clue as to what might be wrong:

dev@dd-devcontainer:/workspaces/dd (main *)$ bazel query 'kind("source file", deps(@awscli//...))'
@awscli//:bin/.aws-wrapped
@awscli//:bin/.aws_completer-wrapped
@awscli//:bin/aws
@awscli//:bin/aws_bash_completer
@awscli//:bin/aws_completer
@awscli//:bin/aws_zsh_completer.sh
dev@dd-devcontainer:/workspaces/dd (main *)$ bazel query 'kind("source file", deps(@mycurl//...))'
INFO: Empty results

I'm not sure if this is a problem with rules_nixpkgs or if curl is just not usable by rules_nixpkgs for some reason.

@malt3
Copy link
Collaborator

malt3 commented Sep 21, 2024

If you look around in the directories generated by repository rules, you should be able to see the mycurl repo:

ls $(bazel info output_base)/external/mycurl

I would check if you can find the curl binary and also take a look at the BUILD file in there.

Additionally, could you provide the output of bazel query @mycurl//...?
I can try to reproduce this on monday.

@avdv
Copy link
Member

avdv commented Sep 21, 2024

The curl package has several outputs, the curl binary is in the bin output. You should be able to use curl.bin as attribute.

@avdv
Copy link
Member

avdv commented Sep 23, 2024

I just discovered that when you use nix build --out-link curl_pkg 'nixpkgs#curl.bin' the out link created is not called curl_pkg:

$ ls -lh curl_pkg-bin
lrwxrwxrwx 1 claudio users 58 Sep 23 08:24 curl_pkg-bin -> /nix/store/qw0m9y0pfppx0rjs4myl82i498d62k43-curl-8.7.1-bin

I think we lack proper handling for that at the moment.

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

No branches or pull requests

3 participants