Cleaned up niv sources
This commit is contained in:
parent
67c5743bbc
commit
eee675245a
|
@ -5,34 +5,22 @@
|
||||||
"homepage": "https://github.com/nmattia/niv",
|
"homepage": "https://github.com/nmattia/niv",
|
||||||
"owner": "nmattia",
|
"owner": "nmattia",
|
||||||
"repo": "niv",
|
"repo": "niv",
|
||||||
"rev": "c25268460b72cea5b7294354ab019997530a6f3d",
|
"rev": "f73bf8d584148677b01859677a63191c31911eae",
|
||||||
"sha256": "1fgq1nkycm54f431h6wflh6rr7xsq3q2fq9drbgra2fnrsyn65ll",
|
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/nmattia/niv/archive/c25268460b72cea5b7294354ab019997530a6f3d.tar.gz",
|
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"branch": "nixos-19.09",
|
"branch": "nixos-20.03",
|
||||||
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
|
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
|
||||||
"homepage": "https://github.com/NixOS/nixpkgs",
|
"homepage": "https://github.com/NixOS/nixpkgs",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs-channels",
|
"repo": "nixpkgs-channels",
|
||||||
"rev": "e1843646b04fb564abf6330a9432a76df3269d2f",
|
"rev": "5adf2a6c11646898742b0c08f7e94101620ba707",
|
||||||
"sha256": "1h1nv7bb6j0ccx8v0sz3gcwl1jqz3v2bb13ham0ky0rg9cvdv91h",
|
"sha256": "0wf7pwma2qyfak39b242mcq8z7cdj65sds7hcjxchy0448shapzi",
|
||||||
"type": "tarball",
|
"type": "tarball",
|
||||||
"url": "https://github.com/NixOS/nixpkgs-channels/archive/e1843646b04fb564abf6330a9432a76df3269d2f.tar.gz",
|
"url": "https://github.com/NixOS/nixpkgs-channels/archive/5adf2a6c11646898742b0c08f7e94101620ba707.tar.gz",
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
|
||||||
},
|
|
||||||
"ops-lib": {
|
|
||||||
"branch": "master",
|
|
||||||
"description": "NixOps deployment configuration library for IOHK devops ",
|
|
||||||
"homepage": null,
|
|
||||||
"owner": "input-output-hk",
|
|
||||||
"repo": "ops-lib",
|
|
||||||
"rev": "a280a769e911fbdc6e5c40794b15dd8570c39063",
|
|
||||||
"sha256": "085ad6mdccbpz8zndsz8nfm8r0zn2h7pp5r42wslqwm9x3c2h7nm",
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/input-output-hk/ops-lib/archive/a280a769e911fbdc6e5c40794b15dd8570c39063.tar.gz",
|
|
||||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
202
nix/sources.nix
202
nix/sources.nix
|
@ -1,130 +1,134 @@
|
||||||
# This file has been generated by Niv.
|
# This file has been generated by Niv.
|
||||||
|
|
||||||
# A record, from name to path, of the third-party packages
|
let
|
||||||
with rec
|
|
||||||
{
|
|
||||||
pkgs =
|
|
||||||
if hasNixpkgsPath
|
|
||||||
then
|
|
||||||
if hasThisAsNixpkgsPath
|
|
||||||
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
|
|
||||||
else import <nixpkgs> {}
|
|
||||||
else
|
|
||||||
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
|
|
||||||
|
|
||||||
sources_nixpkgs =
|
#
|
||||||
|
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||||
|
#
|
||||||
|
|
||||||
|
fetch_file = pkgs: spec:
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchurl { inherit (spec) url sha256; }
|
||||||
|
else
|
||||||
|
pkgs.fetchurl { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_tarball = pkgs: spec:
|
||||||
|
if spec.builtin or true then
|
||||||
|
builtins_fetchTarball { inherit (spec) url sha256; }
|
||||||
|
else
|
||||||
|
pkgs.fetchzip { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_git = spec:
|
||||||
|
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
|
||||||
|
|
||||||
|
fetch_builtin-tarball = spec:
|
||||||
|
builtins.trace
|
||||||
|
''
|
||||||
|
WARNING:
|
||||||
|
The niv type "builtin-tarball" will soon be deprecated. You should
|
||||||
|
instead use `builtin = true`.
|
||||||
|
|
||||||
|
$ niv modify <package> -a type=tarball -a builtin=true
|
||||||
|
''
|
||||||
|
builtins_fetchTarball { inherit (spec) url sha256; };
|
||||||
|
|
||||||
|
fetch_builtin-url = spec:
|
||||||
|
builtins.trace
|
||||||
|
''
|
||||||
|
WARNING:
|
||||||
|
The niv type "builtin-url" will soon be deprecated. You should
|
||||||
|
instead use `builtin = true`.
|
||||||
|
|
||||||
|
$ niv modify <package> -a type=file -a builtin=true
|
||||||
|
''
|
||||||
|
(builtins_fetchurl { inherit (spec) url sha256; });
|
||||||
|
|
||||||
|
#
|
||||||
|
# Various helpers
|
||||||
|
#
|
||||||
|
|
||||||
|
# The set of packages used when specs are fetched using non-builtins.
|
||||||
|
mkPkgs = sources:
|
||||||
|
let
|
||||||
|
sourcesNixpkgs =
|
||||||
|
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
|
||||||
|
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||||
|
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||||
|
in
|
||||||
if builtins.hasAttr "nixpkgs" sources
|
if builtins.hasAttr "nixpkgs" sources
|
||||||
then sources.nixpkgs
|
then sourcesNixpkgs
|
||||||
else abort
|
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||||
|
import <nixpkgs> {}
|
||||||
|
else
|
||||||
|
abort
|
||||||
''
|
''
|
||||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||||
add a package called "nixpkgs" to your sources.json.
|
add a package called "nixpkgs" to your sources.json.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sources_gitignore =
|
# The actual fetching function.
|
||||||
if builtins.hasAttr "gitignore" sources
|
fetch = pkgs: name: spec:
|
||||||
then sources.gitignore
|
|
||||||
else abort
|
|
||||||
''
|
|
||||||
Please add "gitignore" to your sources.json:
|
|
||||||
niv add hercules-ci/gitignore
|
|
||||||
'';
|
|
||||||
|
|
||||||
inherit (import (builtins_fetchTarball { inherit (sources_gitignore) url sha256; }) {
|
if ! builtins.hasAttr "type" spec then
|
||||||
inherit (pkgs) lib;
|
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||||
}) gitignoreSource;
|
else if spec.type == "file" then fetch_file pkgs spec
|
||||||
|
else if spec.type == "tarball" then fetch_tarball pkgs spec
|
||||||
|
else if spec.type == "git" then fetch_git spec
|
||||||
|
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
|
||||||
|
else if spec.type == "builtin-url" then fetch_builtin-url spec
|
||||||
|
else
|
||||||
|
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
||||||
|
|
||||||
|
# Ports of functions for older nix versions
|
||||||
|
|
||||||
|
# a Nix version of mapAttrs if the built-in doesn't exist
|
||||||
|
mapAttrs = builtins.mapAttrs or (
|
||||||
|
f: set: with builtins;
|
||||||
|
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
||||||
|
);
|
||||||
|
|
||||||
# fetchTarball version that is compatible between all the versions of Nix
|
# fetchTarball version that is compatible between all the versions of Nix
|
||||||
builtins_fetchTarball =
|
builtins_fetchTarball = { url, sha256 }@attrs:
|
||||||
{ url, sha256 ? null }@attrs:
|
|
||||||
let
|
let
|
||||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||||
in
|
in
|
||||||
if sha256 == null || lessThan nixVersion "1.12" then
|
if lessThan nixVersion "1.12" then
|
||||||
fetchTarball { inherit url; }
|
fetchTarball { inherit url; }
|
||||||
else
|
else
|
||||||
fetchTarball attrs;
|
fetchTarball attrs;
|
||||||
|
|
||||||
# fetchurl version that is compatible between all the versions of Nix
|
# fetchurl version that is compatible between all the versions of Nix
|
||||||
builtins_fetchurl =
|
builtins_fetchurl = { url, sha256 }@attrs:
|
||||||
{ url, sha256 ? null }@attrs:
|
|
||||||
let
|
let
|
||||||
inherit (builtins) lessThan nixVersion fetchurl;
|
inherit (builtins) lessThan nixVersion fetchurl;
|
||||||
in
|
in
|
||||||
if sha256 == null || lessThan nixVersion "1.12" then
|
if lessThan nixVersion "1.12" then
|
||||||
fetchurl { inherit url; }
|
fetchurl { inherit url; }
|
||||||
else
|
else
|
||||||
fetchurl attrs;
|
fetchurl attrs;
|
||||||
|
|
||||||
# A wrapper around pkgs.fetchzip that has inspectable arguments,
|
# Create the final "sources" from the config
|
||||||
# annoyingly this means we have to specify them
|
mkSources = config:
|
||||||
fetchzip = { url, sha256 ? null }@attrs: if sha256 == null
|
mapAttrs (
|
||||||
then builtins.fetchTarball { inherit url; }
|
name: spec:
|
||||||
else pkgs.fetchzip attrs;
|
|
||||||
|
|
||||||
# A wrapper around pkgs.fetchurl that has inspectable arguments,
|
|
||||||
# annoyingly this means we have to specify them
|
|
||||||
fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs;
|
|
||||||
|
|
||||||
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
|
|
||||||
hasThisAsNixpkgsPath =
|
|
||||||
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
|
|
||||||
|
|
||||||
sources = builtins.fromJSON (builtins.readFile ./sources.json);
|
|
||||||
|
|
||||||
mapAttrs = builtins.mapAttrs or
|
|
||||||
(f: set: with builtins;
|
|
||||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
|
|
||||||
|
|
||||||
# borrowed from nixpkgs
|
|
||||||
functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
|
|
||||||
callFunctionWith = autoArgs: f: args:
|
|
||||||
let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
|
|
||||||
in f (auto // args);
|
|
||||||
|
|
||||||
getFetcher = spec:
|
|
||||||
let fetcherName =
|
|
||||||
if builtins.hasAttr "type" spec
|
|
||||||
then builtins.getAttr "type" spec
|
|
||||||
else "builtin-tarball";
|
|
||||||
in builtins.getAttr fetcherName {
|
|
||||||
"tarball" = fetchzip;
|
|
||||||
"builtin-tarball" = builtins_fetchTarball;
|
|
||||||
"file" = fetchurl;
|
|
||||||
"builtin-url" = builtins_fetchurl;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
# NOTE: spec must _not_ have an "outPath" attribute
|
|
||||||
mapAttrs (name: spec:
|
|
||||||
if builtins.hasAttr "outPath" spec
|
if builtins.hasAttr "outPath" spec
|
||||||
then abort
|
then abort
|
||||||
"The values in sources.json should not have an 'outPath' attribute"
|
"The values in sources.json should not have an 'outPath' attribute"
|
||||||
else
|
else
|
||||||
let
|
spec // { outPath = fetch config.pkgs name spec; }
|
||||||
host = if (name == "nixpkgs") then "custom_nixpkgs" else name;
|
) config.sources;
|
||||||
tryFromPath = builtins.tryEval (builtins.findFile builtins.nixPath host);
|
|
||||||
defaultSpec = (if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
|
# The "config" used by the fetchers
|
||||||
then spec //
|
mkConfig =
|
||||||
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
|
{ sourcesFile ? ./sources.json
|
||||||
else spec) // (if tryFromPath.success
|
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
|
||||||
then let path = tryFromPath.value;
|
, pkgs ? mkPkgs sources
|
||||||
in {
|
}: rec {
|
||||||
outPath = builtins.trace "using search host <${host}>" (
|
# The sources, i.e. the attribute set of spec name to spec
|
||||||
if pkgs.lib.hasPrefix "/nix/store" (builtins.toString path)
|
inherit sources;
|
||||||
then path else gitignoreSource path);
|
|
||||||
}
|
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
||||||
else {});
|
inherit pkgs;
|
||||||
in if builtins.hasAttr "rev" spec && builtins.hasAttr "url" spec then
|
};
|
||||||
defaultSpec //
|
in
|
||||||
{ revOverride = rev: if (rev == null) then defaultSpec else
|
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
||||||
let
|
|
||||||
spec' = removeAttrs (spec // {
|
|
||||||
rev = rev;
|
|
||||||
url = builtins.replaceStrings [defaultSpec.rev] [rev] defaultSpec.url;
|
|
||||||
}) [ "sha256" ];
|
|
||||||
in
|
|
||||||
spec' //
|
|
||||||
{ outPath = callFunctionWith spec' (getFetcher spec') { }; };
|
|
||||||
}
|
|
||||||
else defaultSpec
|
|
||||||
) sources
|
|
||||||
|
|
Loading…
Reference in a new issue