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

Add support for importing nix fetchTarball/fetchGit expressions #30

Closed
wants to merge 2 commits into from

Conversation

Profpatsch
Copy link
Contributor

This allows users to import their fetchTarball/fetchGit expressions as bazel repositories to have one central “source of truth” for e.g. which fixed version of nixpkgs to import.

See the second commit for further explanations (the first commit is just trivial preparation).

Nix is able to fetch and extract tarballs and git repositories in its
evaluation phase, which is used for fixing nixpkgs to a certain commit
in nix code. It provides `builtins.fetchTarball` and
`builtins.fetchGit` for that purpose.
We want to be able to re-use the resulting storepath as a bazel
target.

If you have a nix file like:

  builtins.fetchTarball {
    url = "example.com/mytarball.tar.gz";
    sha256 = …;
  }

You can make the contents of that tarball accessible as bazel targets
in the `WORKSPACE` file:

  nix_import_fetch_builtin(
    name = "mytarball",
    nix_file = "mytarball.nix",
  )

And have targets like:

  @mytarball//:file1
  @mytarball//:dir/file2

Requires `nix eval` (nix 2.0 or later), because `nix-instantiate` is
not able to print raw strings, but it should be possible to use
`nix-instantiate --eval` by unescaping the resulting string manually.
@Profpatsch Profpatsch requested review from mboes and guibou September 19, 2018 21:41
@Profpatsch
Copy link
Contributor Author

Closing because @regnat pointed me to the fact that you can use a nix expression like:

nixpkgs.nix

import (builtins.fetchTarball {
  url = "https://github.com/NixOS/nixpkgs/archive/17.09.tar.gz";
  sha256 = "0kpx4h9p1lhjbn1gsil111swa62hmjs9g93xmsavfiki910s73sh";
})

directly inside the NIX_PATH:

> env NIX_PATH="nixpkgs=./nixpkgs.nix" nix-build -A hello '<nixpkgs>'
/nix/store/w5w4v29ql0qwqhczkdxs94ix2lh7ibgs-hello-2.10

The repository attr of nixpkgs_bazel is directly translated to NIX_PATH=nixpkgs=${repository.dirname}, so it’s not exactly what we need. I will open a pull request that addresses this.

@Profpatsch Profpatsch closed this Sep 20, 2018
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

Successfully merging this pull request may close these issues.

1 participant