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 the ability to build from source #41

Closed
aabounegm opened this issue Sep 12, 2023 · 14 comments · Fixed by #43
Closed

Add the ability to build from source #41

aabounegm opened this issue Sep 12, 2023 · 14 comments · Fixed by #43

Comments

@aabounegm
Copy link
Member

Currently, the extension prompts to download a pre-built binary from GitHub releases if rzk is not found on the system. It should also offer options to install using the different supported build systems: stack, cabal, and nix.
The commands to install look like so (TBC):

  • stack install rzk
  • cabal v2-install rzk
  • nix-env -iA rzk
@aabounegm
Copy link
Member Author

@deemp Can you please confirm the correctness of the nix command?

@deemp
Copy link

deemp commented Sep 12, 2023

There's no top-level rzk package in nixpkgs (link). I can probably such an expression.

Then, it'll be possible to install rzk with:

  • nix env -iA nixpkgs.rzk if a person doesn't use Nix flakes;
  • nix profile install nixpkgs#rzk if a person uses Nix flakes.

@fizruk
Copy link
Member

fizruk commented Sep 13, 2023

There's no top-level rzk package in nixpkgs (link).

Maybe it's enough to install haskellPackages.rzk via

nix-env -iA nixpkgs.haskellPackages.rzk

?

@deemp
Copy link

deemp commented Sep 13, 2023

@fizruk, when you use this command, you rely on the version of nixpkgs present on a user's machine.

nix-env -iA nixpkgs.haskellPackages.rzk

If a user has flakes enabled, an arbitrary revision of nixpkgs can be used for installation.

In a recent revision of the NixOS/nixpkgs repository in the nixpkgs-unstable branch, the package is marked as broken.

nix shell github:nixos/nixpkgs/f4a33546bdb5f81bd6cceb1b3cb19667145fed83#haskellPackages.rzk

...
error: Package ‘rzk-0.5.3’ in /nix/store/8cf9bhcqh1cw9zgz2q1yh6sxvvpyjal6-source/pkgs/development/haskell-modules/hackage-packages.nix:253017 is marked as broken, refusing to evaluate.
...

However, it's possible to get rzk in the current shell via

export NIXPKGS_ALLOW_BROKEN=1
nix shell github:nixos/nixpkgs/f4a33546bdb5f81bd6cceb1b3cb19667145fed83#haskellPackages.rzk --impure

Or, install it so that rzk is available on PATH system-wide.

export NIXPKGS_ALLOW_BROKEN=1
nix profile install github:nixos/nixpkgs/f4a33546bdb5f81bd6cceb1b3cb19667145fed83#haskellPackages.rzk --impure

Then, you'll have

rzk typecheck --help
Usage: rzk typecheck [STRING]...

Available options:
  -h,--help                Show this help text

@fizruk
Copy link
Member

fizruk commented Sep 13, 2023

@deemp thanks for the detailed explanation! Do you know why the package is marked as broken?

@deemp
Copy link

deemp commented Sep 13, 2023

No I don't. It's done by automatic tools (link).

@deemp
Copy link

deemp commented Sep 13, 2023

UPD on #41 (comment).

I found out it's possible to get rzk from an arbitrary revision of nixpkgs via old commands (link).

Make rzk available in the current shell:

export NIXPKGS_ALLOW_BROKEN=1
nix-shell -p haskellPackages.rzk -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/f4a33546bdb5f81bd6cceb1b3cb19667145fed83.tar.gz

Install system-wide:

export NIXPKGS_ALLOW_BROKEN=1
nix-env -iA nixpkgs.haskellPackages.rzk -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/f4a33546bdb5f81bd6cceb1b3cb19667145fed83.tar.gz

Moreover, when flakes are enabled, rzk can be obtained from the main repo as there's an rzk output (link). The downside is that we need to prepare a binary cache with pre-built rzk so that users don't have to build it.

Without a specific revision:

nix shell github:rzk-lang/rzk#rzk
rzk version

# or, to run
nix run github:rzk-lang/rzk#rzk -- version

# or, to install system-wide
nix profile install github:rzk-lang/rzk#rzk
rzk version

The installable (link) can be simplified further by renaming the packages.rzk output to packages.default in the flake.nix (link).

The package will be accessible via github:rzk-lang/rzk.

@aabounegm
Copy link
Member Author

Thanks for such a detailed response!
Do I understand correctly from the last comment that, without flakes enabled, we must refer to a specific revision of nixpkgs and can't simply fetch the latest version? And also, to use the last command that fetches the latest version, is it safe to assume that all Nix users will have flakes enabled?

@deemp
Copy link

deemp commented Sep 18, 2023

Do I understand correctly from the last comment that, without flakes enabled, we must refer to a specific revision of nixpkgs and can't simply fetch the latest version?

You can fetch the latest version of nixpkgs with an old-style command.

nix-shell --packages pan -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/master.zip

The problem is that the nixpkgs binary cache may be unavailable for the latest commit. That's why, I suggest to use a certain commit for which rzk is in the binary cache.

Also, you can provide rzk on your own. Here's a sample process

  • Build rzk in CI from your own flake
  • Push rzk to a binary cache like cachix
  • Use the latest commit of your flake
  • This extension can check whether there's a new version of rzk in cachix
    • Evaluate the path of the rzk package (link)
    • Search "Check the existence of a path in a binary cache" in link

And also, to use the last command that fetches the latest version, is it safe to assume that all Nix users will have flakes enabled?

No, flakes is an experimental feature, so many people don't use it. It can be temporary enabled (link).

@aabounegm
Copy link
Member Author

So the PR is marked as draft because I still didn't understand what's the best set of commands to run 😅 . We would like for it to install the latest available version and not pin to a specific commit so the extension is not tightly coupled with Rzk releases and not have to update it every time a new release is published.
What is the simplest command to achieve this?

The problem is that the nixpkgs binary cache may be unavailable for the latest commit.

If installation via Nix is not as simple as stack/cabal, would you recommend we just remove the option or are there a few commands to run that will achieve what we need?

@deemp
Copy link

deemp commented Sep 20, 2023

I still didn't understand what's the best set of commands to run

In my opinion, it's the best to let people install rzk manually via nix profile install (link), nix-env (link), configuration.nix (link) or provide in a devShell (link).

So, you can just write in the extension description that rzk is a prerequisite and describe installation options for the latest or a specific version.

@deemp
Copy link

deemp commented Sep 20, 2023

We would like for it to install the latest available version and not pin to a specific commit.

This is possible both with nix-env and nix profile install. There are two options:

  • nixpkgs contains the latest versions from Hackage.
  • rzk-lang/rzk repo provides the latest possible version of rzk.

If you want to provide the version from the repo, I suggest to set up caching in your CI to let people use pre-built rzk.

  • In Update flake and playground rzk#84, I provided the packages.default package in flake.nix. This is the rzk package as a static executable.
  • I need you to create a binary cache on cachix and provide credentials as GitHub Actions variable and secret:
    • CACHIX_CACHE variable - the name of a binary cache, e.g., rzk-lang.
    • CACHIX_AUTH_TOKEN secret - the cache token
  • Then, I'll add a step in a GH Action to push rzk to that cache so that rzk becomes available immediately after release CI

@aabounegm
Copy link
Member Author

In my opinion, it's the best to let people install rzk manually

I think that makes sense; anyone who knows how to use Nix will most likely not need help installing rzk, I believe.
@fizruk Should we just remove the Nix option altogether or is still desirable to have?

@fizruk
Copy link
Member

fizruk commented Sep 20, 2023

Sure, I do not mind removing the Nix option from the extension.

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 a pull request may close this issue.

3 participants