nmattia / niv

Easy dependency management for Nix projects

Home Page:https://github.com/nmattia/niv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Correct way to specify platform-specific packages

joscha opened this issue · comments

Hi @nmattia, thanks for the great project!

One thing that I can't figure out and also can't find any relation in the source or the issues is how I would make platform-specific packages happen.

E.g. taking the example from the README:

$ niv add ghc   \
    -v 8.4.3    \
    -t 'https://downloads.haskell.org/~ghc/<version>/ghc-<version>-i386-deb8-linux.tar.xz'

but assume that there is a platform-specific (pre-built!) binary that I want to support, e.g. the assets from here: https://github.com/dprint/dprint/releases/tag/0.15.0 for example.

So the above command would need to become something like:

$ niv add dprint   \
    -v 0.15.0    \
    -t 'https://github.com/dprint/dprint/releases/download/<version>/dprint-x86_64-<platform>.<platform-ext>'

where I have a bit more control over the platform substitute - in the current case it looks like this:

dprint-x86_64-apple-darwin.tar.gz
dprint-x86_64-apple-darwin.zip
dprint-x86_64-pc-windows-msvc-installer.exe
dprint-x86_64-pc-windows-msvc.zip
dprint-x86_64-unknown-linux-gnu.zip

so I get zip/tgz (in the case above I can go with .zip but that might be different in the generic case) and pc-windows-msvc | apple-darwin | unknown-linux-gnu

I wonder:

Hi @joscha,

If I understand you correctly, you want to generate multiple dependencies based on some template. In this template, you have multiple parameters. By specifying multiple set of values for these parameters, niv could generate multiple dependencies. (You can find more of my thought in the hypothetical example bellow.)

There is not any way to do something like this with niv at the moment. As far as I'm aware, there is no plan to add I feature like this any time soon either. Currently, each dependency contains the following information:

  • a name which will be used in the resulting nix expression
  • a path or an url to let nix know where the download the dependency
  • a sha256 to allow nix to verify the content of the url
  • metadatas that explain to niv how to update the path and the sha256 to a new version.

This simplicity has served niv well in the past. The code is simpler both in the haskell side and the nix side.
I made a little hypothetical example as a reference if we want to talk a little bit more about this feature.
Don't hesitate to tell me if I'm completely about your needs/ideas. We can talk about it after clarification.

if there is an example somewhere on how to do this with niv

no

While it would need a PR for this feature, I'm not yet convinced that this is something that niv want.

Hypothetical example

The JSON could looks something like this for the parameters and template section. I omitted many necessary attributes like the url and sha256 attribute that I mentioned earlier. These would also need to change.

{
  "dprint": {
    "parameters": [
        { "platform": "apple", "platform-ext": "gz" },
        { "platform": "pc-windows", "platform-ext": "exe" },
        { "platform": "unknown-linux", "platform-ext": "zip" },
    ],
    "template": "https://github.com/dprint/dprint/releases/download/<version>/dprint-x86_64-<platform>.<platform-ext>"
  }
}

Usage of the generated dependencies in nix.

sources.dprint-apple-gz
// or
sources.dprint.apple.gz

Questions

  • How does every niv subcommands need to change to accommodate these change?

Hi @refnil, your example is spot-on except that potentially different platforms also have specific wrappers, etc.

While it would need a PR for this feature, I'm not yet convinced that this is something that niv want.

I understand niv is about providing the most simple way possible in terms of binary access and my request goes against that. Will close. thank you for considering.