-
Notifications
You must be signed in to change notification settings - Fork 132
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
Make list-packages
command runnable in a Nix build environment
#547
Comments
spago2nix needs to know the package name, GitHub URL, and revision (the Spago 'version' field), which can be listed as JSON with In order for this command to work offline it seems like the package metadata for all packages listed in Given a let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200123/packages.dhall sha256:687bb9a2d38f2026a89772c47390d02939340b01e31aaa22de9247eadd64af05
in upstream then we can re-use the URL and sha256 in Nix: # The contents of `fetchedPackages` are the contents of the `packages.dhall` file
fetchedPackages = builtins.fetchurl {
url = "https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200123/packages.dhall";
# The sha256 produced by Spago in `spago init`
sha256 = "687bb9a2d38f2026a89772c47390d02939340b01e31aaa22de9247eadd64af05"
# The sha256 that Nix actually expects; I'm not sure how to resolve the difference
sha256 = "1zzccm2qmbg673h6rx1lyznl78j97z9cx9v2vyn5bbj8pyjsn47f";
}; This would allow us to copy an upstream buildPhase = ''
cat ${fetchedPackages} > upstream.dhall
...
''; However, I understand that this could be a brittle solution as I'm not familiar with all the different ways a packages.dhall file could be configured (I'm only used to the It may not be possible to get the package metadata information that spago2nix would require without significant changes to Spago. In that case I'm happy to close this issue until I have time to explore the code base and put together a serious proposal towards that goal. |
I'm not sure if this is the error you're seeing, but the nix tools generally use a base-32 hash, not a base-16 hash. Here's a couple links explaining the situation a little (although nothing super informative):
(Sorry if you already knew this and the problem you had is actually something else completely...) |
@thomashoneyman one of the reasons why we have the hashes on the package set import in I.e. if you run this with an empty cache:
..then the result will be cached (and reused the next time you evaluate that) in this file: Does this help? I guess you could resolve the file once, and then copy the cache over in every derivation you need that. |
Re having an |
I think there's information missing in here that the yarn2nix uses the yarn.lock file checked in as a source of information, since a package definition in yarn.lock looks like this:
So this then allows for generating nix expressions at runtime from this file using the "integrity" field. Otherwise yarn2nix would not work, unless the derivation were jailbroken to allow for network requests. |
"Could not resolve host" just comes from the derivation environment being sandboxed. Given default.nix: { pkgs ? import <nixpkgs> {} }:
pkgs.runCommand "fail" {
buildInputs = [ pkgs.curl ];
} ''
>$out curl https://google.com
'' You will get the following when you try to build it:
|
@justinwoo I was just looking at that, and that’s a good point; since we don’t record the sha256 for the packages themselves I would still have to make network requests to calculate those (nix-prefetch-git). So unless the package sets themselves included a hash for each package to verify its contents I don’t believe this is possible. @f-f Thanks for explaining the cache, that’s helpful and does make sense. @cdepillabout Yes, I think you’ve pointed out the problem wrt the hashes. I would expect there’s not a way to convert from base-16 to base-32, so that may not be possible to solve here. |
Sorry, I will unsubscribe from this thread now. Hope you figure this out, or please have someone from your company contact me. Thanks. |
While I still think it would be nice to have a way to list packages -- with their |
You're welcome 🙂 |
Thanks for your workflow writeup @thomashoneyman , I copied it onto the spago2nix README https://github.com/justinwoo/spago2nix#workflow |
Summary
Some Spago commands cannot be run in a Nix build because of restrictions on the environment (namely, builds have restricted permissions and can mutate their temporary build directory, but can't write files outside it and can't access files outside it unless explicitly given a path to them, and network access is disallowed during the build). Some of these commands seem like they ought to be runnable in this environment but aren't.
Attempting to run a command like
spago list-packages
will fail, for example, with this error on Mac OS:and this error on Linux:
I am working on support for import from derivation for @justinwoo's spago2nix tool, but this has been a blocker.
I'd like to explore how to make at least the
list-packages
commands runnable in a pure build environment. Thebuild
command is already runnable in a pure environment given the--no-install
flag. I don't believe any other commands will be necessary for import-from-derivation, but if there are then I can add them as comments on this issue.Context
I use Spago with @justinwoo's excellent spago2nix tool. This tool takes a project's
spago.dhall
andpackages.dhall
files and generates the equivalent Nix expressions necessary to build each dependency.Right now, the workflow of spago2nix is to:
packages.dhall
file, and aspago.dhall file
.spago2nix generate
to generate a newspago-packages.nix
file which describes how to build the dependenciesspago-packages.nix
file to get all the sourcesspago2nix build
orspago build --no-install
or call to the compiler directly withpurs compile "src/**/*.purs" ${spagoPackages.compilePaths}
This has a key drawback: steps 2 and 3 really ought to be a single step. In other words, spago2nix should follow in the footsteps of yarn2nix and merge generating the Nix file and importing its result. This is called import from derivation and it carries some important benefits:
spago2nix
after installing a new dependencyCurrent issues
The
list-packages
command is not runnable in a Nix build environment, which is required in order to get import-from-derivation working with spago2nix without implementing a separate parser for the packages.dhall and spago.dhall files.Next Steps
I am not exactly sure what Spago does in this command that is not simply a filesystem read and parsing these files; if it is possible to update it or provide a flag to disable some behavior (like
yarn
's--offline
flag) then I'd like to explore how to make that possible.My ideal result is that the reproduction below can be run without errors.
Reproduction
If you have Nix installed then you can reproduce a typical Nix build environment with a
spago.dhall
,packages.dhall
andsrc/Main.purs
with the belowdefault.nix
file and this command:The text was updated successfully, but these errors were encountered: