niv icon indicating copy to clipboard operation
niv copied to clipboard

Support fetching channels

Open lheckemann opened this issue 4 years ago • 9 comments

Using nixpkgs's release channel tarballs (https://nixos.org/channels/nixos-20.03/nixexprs.tar.xz for example) has the advantage of including the nixpkgs version in nixpkgs's lib.version and of being a "release" of sorts. Support for this would be nice.

lheckemann avatar Apr 26 '20 13:04 lheckemann

Does following the nixos-20.03 branch not achieve this already?

michaelpj avatar Apr 26 '20 15:04 michaelpj

No — compare nix eval -f https://github.com/nixos/nixpkgs/archive/nixos-20.03.tar.gz lib.version and nix eval -f https://nixos.org/channels/nixos-20.03/nixexprs.tar.xz lib.version This information can be very helpful for tracing back from e.g. a nixos system built with the nixpkgs in question.

lheckemann avatar Apr 26 '20 16:04 lheckemann

Aren't channels being phased out in favor of flakes? I've never really used channels, how does that work? I.e., how would the CLI UX look like?

nmattia avatar Apr 27 '20 08:04 nmattia

In the case of niv, I imagine it wouldn't look any different than any other dependencies — just that rather than having url_template, owner, repo, etc, one would have a "current URL" like https://nixos.org/channels/nixos-20.03/nixexprs.tar.xz and a "pinned URL" like https://releases.nixos.org/nixos/20.03/nixos-20.03.1577.74a80c5a9ab/nixexprs.tar.xz (not sure about the naming here). The pinned URL is obtained by following the redirects at the current URL.

As for replacement by flakes, there are unfortunately two different concepts called channels here…

  • The local "pinning" managed by nix-channel, which is suboptimal UX-wise and should indeed be replaced by flakes AFAIU (but wouldn't flakes also be an alternative to niv?)
  • The channels which are built by hydra, like https://nixos.org/channels/nixos-20.03, which are "releases" of the branches they're built from and contain some nice metadata like the version number, installer images, package/option indices and file lists. These are what I think would be nice to have in niv.

That said, it's just a suggestion and I'm content with my ugly little shell script instead of niv for pinning my nixops deployment's nixpkgs, so maybe you want to implement it if you'd find it useful yourself, but I'm happy as is too :)

Ugly little shell script
#!/usr/bin/env bash

set -ex
url=$(curl -sSfIL https://nixos.org/channels/nixos-20.03/nixexprs.tar.xz | grep -i '^location:' | tr -d '\r' | tail -n1)
url="${url##?ocation: }"
sha256=$(nix-prefetch-url --unpack "$url")
jq -n '.url=$url | .sha256=$sha256' --arg url "$url" --arg sha256 "$sha256"

EDIT: CLI could look something like niv add --channel https://nixos.org/channels/nixos-20.03 or niv add --channel https://nixos.org/channels/nixos-20.03/nixexprs.tar.xz

lheckemann avatar Apr 27 '20 09:04 lheckemann

@lheckemann don't you get the right lib.version when using https://github.com/NixOS/nixpkgs-channels/archive ? For instance nix eval -f https://github.com/NixOS/nixpkgs-channels/archive/5272327b81ed355bbed5659b8d303cf2979b6953.tar.gz lib.version.

PierreR avatar Apr 27 '20 12:04 PierreR

nixpkgs-channels is deprecated, the channel branches from there are now just branches in the main nixpkgs repo. The command you give has the same output as the one @lheckemann posted using the git repo, which is different to the one from the channel archive.

michaelpj avatar Apr 27 '20 13:04 michaelpj

Yes, as @michaelpj says. Specifically, the channel tarball is generated by https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/make-channel.nix which includes some extra metadata which makes displaying the correct version possible. This metadata can't be obtained from github's tarball, as said tarball is generated directly from the git tree.

lheckemann avatar Apr 27 '20 15:04 lheckemann

@michaelpj @lheckemann thanks for your input. That's good to know.

PierreR avatar Apr 28 '20 07:04 PierreR

Also the channels contain programs.sqlite which I want on a non nixos system.

SuperSandro2000 avatar Mar 30 '21 12:03 SuperSandro2000