Forked from matthewbauer/generate-versions.nix
Last active
September 15, 2019 08:45
-
-
Save steshaw/0a30ab2a8bd2424830efe079aee1d8fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# | |
# Find version: | |
# | |
# $ nix-instantiate --eval --expr '(import ./pkg-versions.nix {}).pandoc' | |
# { "1.13.1" = <CODE>; "1.16.0.2" = <CODE>; "1.17.1" = <CODE>; "1.19.2.1" = <CODE>; "1.19.2.4" = <CODE>; "2.0.6" = <CODE>; "2.2.1" = <CODE>; "2.7.1" = <CODE>; } | |
# $ nix eval '(builtins.attrNames (import ./pkg-versions.nix {}).pandoc)' | |
# [ "1.13.1" "1.16.0.2" "1.17.1" "1.19.2.1" "1.19.2.4" "2.0.6" "2.2.1" "2.7.1" ] | |
# $ nix-instantiate --eval --expr 'builtins.attrNames (import ./pkg-versions.nix {}).pandoc' | |
# [ "1.13.1" "1.16.0.2" "1.17.1" "1.19.2.1" "1.19.2.4" "2.0.6" "2.2.1" "2.7.1" ] | |
# | |
# Run arbitrary version: | |
# | |
# $ LANG=C $(nix-build --no-out-link --expr '(import ./pkg-versions.nix {}).pandoc."1.16.0.2".pkg')/bin/pandoc --version | |
# pandoc 1.16.0.2 | |
# ... | |
# $ nix run '(import ./pkg-versions.nix {}).pandoc."1.16.0.2".pkg' -u LANG -c pandoc --version | |
# pandoc 1.16.0.2 | |
# ... | |
# | |
# Find channel for version: | |
# | |
# $ nix eval '(import ./pkg-versions.nix {}).pandoc."1.16.0.2".channel' | |
# "16.03" | |
# $ nix-instantiate --eval --expr '(import ./pkg-versions.nix {}).pandoc."1.16.0.2".channel' | |
# "16.03" | |
# | |
# Run a version from a channel: | |
# | |
# $ nix run -f channel:nixos-16.03 pandoc --command pandoc --version | |
# | |
# HT | |
# http://matthewbauer.us/blog/all-the-versions.html | |
# https://gist.github.com/matthewbauer/7c57f8fb69705bb8da9741bf4b9a7e64 | |
# | |
{ channels ? [ | |
"19.03" | |
"18.09" | |
"18.03" | |
"17.09" | |
"17.03" | |
"16.09" | |
"16.03" | |
"15.09" | |
"14.12" | |
"14.04" | |
"13.10" | |
], attrs ? builtins.attrNames (import <nixpkgs> { }) | |
, system ? builtins.currentSystem, args ? { inherit system; } }: | |
let | |
getSet = channel: | |
(import (builtins.fetchTarball "channel:nixos-${channel}") args).pkgs; | |
getPkg = name: channel: | |
let | |
pkgs = getSet channel; | |
pkg = pkgs.${name}; | |
version = (builtins.parseDrvName pkg.name).version; | |
in if builtins.hasAttr name pkgs && pkg ? name then { | |
name = version; | |
value = { | |
channel = channel; | |
pkg = pkg; | |
}; | |
} else | |
null; | |
in builtins.listToAttrs (map (name: | |
let pkgs = map (getPkg name) channels; | |
in { | |
name = name; | |
value = builtins.listToAttrs (builtins.filter (x: x != null) pkgs); | |
}) attrs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment