nmattia / niv

Easy dependency management for Nix projects
https://github.com/nmattia/niv
MIT License
1.61k stars 79 forks source link

Support fetching channels #225

Open lheckemann opened 4 years ago

lheckemann commented 4 years ago

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.

michaelpj commented 4 years ago

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

lheckemann commented 4 years ago

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.

nmattia commented 4 years ago

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?

lheckemann commented 4 years ago

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…

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

PierreR commented 4 years ago

@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.

michaelpj commented 4 years ago

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.

lheckemann commented 4 years ago

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.

PierreR commented 4 years ago

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

SuperSandro2000 commented 3 years ago

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