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 building remote imports as FOD to dhall-nixpkgs #2318

Merged

Conversation

cdepillabout
Copy link
Contributor

@cdepillabout cdepillabout commented Oct 18, 2021

This PR adds support for converting remote imports to fixed-output derivations (FOD) to dhall-to-nixpkgs.

This functionality was discussed in #2304 (comment) (and the next few comments).


This PR adds a --url-as-fod argument to dhall-to-nixpkgs directory. Passing --url-as-fod causes dhall-to-nixpkgs directory to turn remote imports into FOD.

For instance, the current dhall-to-nixpkgs will output the following for mydhallfile.dhall:

$ dhall-to-nixpkgs directory ./example-dhall-nix --file mydhallfile.dhall
{ buildDhallDirectoryPackage, example-dhall-repo, Prelude }:
  buildDhallDirectoryPackage {
    name = "example-dhall-nix";
    src = ./example-dhall-nix;
    file = "mydhallfile.dhall";
    source = false;
    document = false;
    dependencies = [
      (example-dhall-repo.overridePackage { file = "example1.dhall"; })
      (Prelude.overridePackage { file = "List/map.dhall"; })
      (Prelude.overridePackage { file = "Text/upperASCII.dhall"; })
      ];
    }

With the code from this PR, and using the --url-as-fod argument, the following will be output:

$ dhall-to-nixpkgs directory ./example-dhall-nix --file mydhallfile.dhall --url-as-fod
{ buildDhallDirectoryPackage, buildDhallUrl }:
  buildDhallDirectoryPackage {
    name = "example-dhall-nix";
    src = ./example-dhall-nix;
    file = "mydhallfile.dhall";
    source = false;
    document = false;
    dependencies = [
      (buildDhallUrl {
        url = "https://raw.githubusercontent.com/cdepillabout/example-dhall-repo/c1b0d0327146648dcf8de997b2aa32758f2ed735/example1.dhall";
        hash = "sha256-ZTSiQUXpPbPfPvS8OeK6dDQE6j6NbP27ho1cg9YfENI=";
        dhall-hash = "sha256:6534a24145e93db3df3ef4bc39e2ba743404ea3e8d6cfdbb868d5c83d61f10d2";
        })
      (buildDhallUrl {
        url = "https://raw.githubusercontent.com/dhall-lang/dhall-lang/9758483fcf20baf270dda5eceb10535d0c0aa5a8/Prelude/List/map.dhall";
        hash = "sha256-3YRf+0Vo1AMn8qgX60LRxhOLkpynWNULwzES7zyIVoA=";
        dhall-hash = "sha256:dd845ffb4568d40327f2a817eb42d1c6138b929ca758d50bc33112ef3c885680";
        })
      (buildDhallUrl {
        url = "https://raw.githubusercontent.com/dhall-lang/dhall-lang/9758483fcf20baf270dda5eceb10535d0c0aa5a8/Prelude/Text/upperASCII.dhall";
        hash = "sha256-Ra5PvYFLBHTmXCik7pKyO5eYkvpbtzcwvJlnWueQyik=";
        dhall-hash = "sha256:45ae4fbd814b0474e65c28a4ee92b23b979892fa5bb73730bc99675ae790ca29";
        })
      ];
    }

This uses buildDhallUrl to build all of the remote imports. buildDhallUrl is a function I propose in #2304 (comment). You can find its implementation here. This would likely need to be added to Nixpkgs.

Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one minor comment

parseUrlAsFOD :: Parser Bool
parseUrlAsFOD =
Options.switch
( Options.long "url-as-fod"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest renaming this to --fixed-output-derivations and not reference URLs specifically. That way if we want to add support for other fixed output derivations (like local path imports or environment variables protected by integrity checks, for whatever reason), then we don't need to rename the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea.

I rebased this PR on master and added a commit changing the --url-as-fod flag to --fixed-output-derivations: c65b550

@Gabriella439 Gabriella439 merged commit dc31e3c into dhall-lang:master Oct 22, 2021
@Gabriella439
Copy link
Collaborator

@cdepillabout: Thank you for your patience working on this! 🙂

@cdepillabout
Copy link
Contributor Author

cdepillabout commented Oct 22, 2021

Thanks for merging this in :-)

The next step is to get the Nix functions from https://github.com/cdepillabout/example-dhall-nix/blob/e6a675c72ecd4dd23d254a02aea8181fe875747f/default.nix into Nixpkgs (along with necessary documentation updates).

Since dhall-to-nixpkgs has gotten the flag --fixed-output-derivations in this PR, then the buildDhallUrl function should definitely be upstreamed into Nixpkgs.

Personally I'd also like to get the other functions from that file into Nixpkgs (dhallPackageToNix, generateDhallDirectoryPackage, and dhallDirectoryToNix), since I think these functions are widely(?) useful. But these functions aren't quite as critical as buildDhallUrl.

If this sounds good, I'll start putting together PRs to Nixpkgs adding these functions.

@cdepillabout cdepillabout deleted the dhall-to-nixpkgs-urls-fod branch October 22, 2021 05:26
@Gabriella439
Copy link
Collaborator

Yeah, go ahead and open a PR to add those utilities to Nixpkgs

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.

None yet

2 participants