Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit d0cc2e6

Browse files
disassemblerdeepfire
authored andcommitted
pin haskell.nix and iohk-nix using niv
1 parent 93bfeb8 commit d0cc2e6

File tree

5 files changed

+230
-28
lines changed

5 files changed

+230
-28
lines changed

lib.nix

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
let
2-
# Allow overriding pinned nixpkgs for debugging purposes via cardano_pkgs
3-
# Imports the iohk-nix library.
4-
# The version can be overridden for debugging purposes by setting
5-
# NIX_PATH=iohk_nix=/path/to/iohk-nix
6-
iohkNix = import (
7-
let try = builtins.tryEval <iohk_nix>;
8-
in if try.success
9-
then builtins.trace "using host <iohk_nix>" try.value
10-
else
11-
let
12-
spec = builtins.fromJSON (builtins.readFile ./nix/iohk-nix-src.json);
13-
in builtins.fetchTarball {
14-
url = "${spec.url}/archive/${spec.rev}.tar.gz";
15-
inherit (spec) sha256;
16-
}) {};
17-
# Gets the value of an environment variable, with a default if it's
18-
# unset or empty.
2+
sources = import ./nix/sources.nix;
3+
pkgs' = import sources.nixpkgs {};
4+
haskellNixJson = let
5+
src = sources."haskell.nix";
6+
in __toJSON {
7+
inherit (sources."haskell.nix") rev sha256;
8+
url = "https://github.com/${src.owner}/${src.repo}";
9+
};
10+
iohkNix = import sources.iohk-nix { haskellNixJsonOverride = pkgs'.writeText "haskell-nix.json" haskellNixJson; };
11+
pkgs = iohkNix.pkgs;
12+
lib = pkgs.lib;
13+
niv = (import sources.niv {}).niv;
1914
maybeEnv = env: default:
2015
let
2116
result = builtins.getEnv env;
2217
in if result != ""
2318
then result
2419
else default;
2520

26-
pkgs = iohkNix.pkgs;
27-
lib = pkgs.lib;
2821
environments = iohkNix.cardanoLib.environments // {
2922
demo = {
3023
confKey = "dev";
@@ -36,7 +29,7 @@ let
3629
(name: env: f (env // { inherit name; }))
3730
environments;
3831
in lib // iohkNix.cardanoLib // iohkNix // {
39-
inherit environments forEnvironments;
32+
inherit environments forEnvironments niv iohkNix;
4033
utf8LocaleSetting = ''
4134
export LC_ALL=en_GB.UTF-8
4235
export LANG=en_GB.UTF-8

nix/sources.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"gitignore": {
3+
"branch": "master",
4+
"description": "Nix function for filtering local git sources",
5+
"homepage": "",
6+
"owner": "hercules-ci",
7+
"repo": "gitignore",
8+
"rev": "f9e996052b5af4032fe6150bba4a6fe4f7b9d698",
9+
"sha256": "0jrh5ghisaqdd0vldbywags20m2cxpkbbk5jjjmwaw0gr8nhsafv",
10+
"type": "tarball",
11+
"url": "https://github.com/hercules-ci/gitignore/archive/f9e996052b5af4032fe6150bba4a6fe4f7b9d698.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"haskell.nix": {
15+
"branch": "master",
16+
"description": "Alternative Haskell Infrastructure for Nixpkgs",
17+
"homepage": "https://input-output-hk.github.io/haskell.nix",
18+
"owner": "input-output-hk",
19+
"repo": "haskell.nix",
20+
"rev": "3ae2303b14bdebd00437b0e995af2d0eb21abafe",
21+
"sha256": "0dk6541kwfyc5sp5h1vfk6zl4ghln4i2zqkaijbjwv8bnixnm6wl",
22+
"type": "tarball",
23+
"url": "https://github.com/input-output-hk/haskell.nix/archive/3ae2303b14bdebd00437b0e995af2d0eb21abafe.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
},
26+
"iohk-nix": {
27+
"branch": "master",
28+
"description": "nix scripts shared across projects",
29+
"homepage": null,
30+
"owner": "input-output-hk",
31+
"repo": "iohk-nix",
32+
"rev": "f854c957a65295639d2062867552b65c7dc227a6",
33+
"sha256": "1jl07ng2nx6lgj9rrqzl242r263505llzzxb592fn81h0dq6jx1r",
34+
"type": "tarball",
35+
"url": "https://github.com/input-output-hk/iohk-nix/archive/f854c957a65295639d2062867552b65c7dc227a6.tar.gz",
36+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
37+
},
38+
"niv": {
39+
"branch": "iohk",
40+
"description": "Easy dependency management for Nix projects",
41+
"homepage": "https://github.com/nmattia/niv",
42+
"owner": "input-output-hk",
43+
"repo": "niv",
44+
"rev": "c25268460b72cea5b7294354ab019997530a6f3d",
45+
"sha256": "1fgq1nkycm54f431h6wflh6rr7xsq3q2fq9drbgra2fnrsyn65ll",
46+
"type": "tarball",
47+
"url": "https://github.com/input-output-hk/niv/archive/c25268460b72cea5b7294354ab019997530a6f3d.tar.gz",
48+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
49+
},
50+
"nixpkgs": {
51+
"branch": "iohk-19.03",
52+
"description": "Nix Packages collection",
53+
"homepage": null,
54+
"owner": "input-output-hk",
55+
"repo": "nixpkgs",
56+
"rev": "5bd4c4ea6804b54683ef2b802d970ae473e1b658",
57+
"sha256": "12gah6y1lkkgvvdgswyzsqyvxvsvljn61vpy606sy37yfgkc1a63",
58+
"type": "tarball",
59+
"url": "https://github.com/input-output-hk/nixpkgs/archive/5bd4c4ea6804b54683ef2b802d970ae473e1b658.tar.gz",
60+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
61+
}
62+
}

nix/sources.nix

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# This file has been generated by Niv.
2+
3+
# A record, from name to path, of the third-party packages
4+
with rec
5+
{
6+
pkgs =
7+
if hasNixpkgsPath
8+
then
9+
if hasThisAsNixpkgsPath
10+
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
11+
else import <nixpkgs> {}
12+
else
13+
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
14+
15+
sources_nixpkgs =
16+
if builtins.hasAttr "nixpkgs" sources
17+
then sources.nixpkgs
18+
else abort
19+
''
20+
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
21+
add a package called "nixpkgs" to your sources.json.
22+
'';
23+
24+
sources_gitignore =
25+
if builtins.hasAttr "gitignore" sources
26+
then sources.gitignore
27+
else abort
28+
''
29+
Please add "gitignore" to your sources.json:
30+
niv add hercules-ci/gitignore
31+
'';
32+
33+
inherit (import (builtins_fetchTarball { inherit (sources_gitignore) url sha256; }) {
34+
inherit (pkgs) lib;
35+
}) gitignoreSource;
36+
37+
# fetchTarball version that is compatible between all the versions of Nix
38+
builtins_fetchTarball =
39+
{ url, sha256 ? null }@attrs:
40+
let
41+
inherit (builtins) lessThan nixVersion fetchTarball;
42+
in
43+
if sha256 == null || lessThan nixVersion "1.12" then
44+
fetchTarball { inherit url; }
45+
else
46+
fetchTarball attrs;
47+
48+
# fetchurl version that is compatible between all the versions of Nix
49+
builtins_fetchurl =
50+
{ url, sha256 ? null }@attrs:
51+
let
52+
inherit (builtins) lessThan nixVersion fetchurl;
53+
in
54+
if sha256 == null || lessThan nixVersion "1.12" then
55+
fetchurl { inherit url; }
56+
else
57+
fetchurl attrs;
58+
59+
# A wrapper around pkgs.fetchzip that has inspectable arguments,
60+
# annoyingly this means we have to specify them
61+
fetchzip = { url, sha256 ? null }@attrs: if sha256 == null
62+
then builtins.fetchTarball { inherit url; }
63+
else pkgs.fetchzip attrs;
64+
65+
# A wrapper around pkgs.fetchurl that has inspectable arguments,
66+
# annoyingly this means we have to specify them
67+
fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs;
68+
69+
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
70+
hasThisAsNixpkgsPath =
71+
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
72+
73+
sources = builtins.fromJSON (builtins.readFile ./sources.json);
74+
75+
mapAttrs = builtins.mapAttrs or
76+
(f: set: with builtins;
77+
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
78+
79+
# borrowed from nixpkgs
80+
functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
81+
callFunctionWith = autoArgs: f: args:
82+
let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
83+
in f (auto // args);
84+
85+
getFetcher = spec:
86+
let fetcherName =
87+
if builtins.hasAttr "type" spec
88+
then builtins.getAttr "type" spec
89+
else "builtin-tarball";
90+
in builtins.getAttr fetcherName {
91+
"tarball" = fetchzip;
92+
"builtin-tarball" = builtins_fetchTarball;
93+
"file" = fetchurl;
94+
"builtin-url" = builtins_fetchurl;
95+
};
96+
};
97+
# NOTE: spec must _not_ have an "outPath" attribute
98+
mapAttrs (name: spec:
99+
if builtins.hasAttr "outPath" spec
100+
then abort
101+
"The values in sources.json should not have an 'outPath' attribute"
102+
else
103+
let
104+
host = if (name == "nixpkgs") then "custom_nixpkgs" else name;
105+
tryFromPath = builtins.tryEval (builtins.findFile builtins.nixPath host);
106+
defaultSpec = (if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
107+
then spec //
108+
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
109+
else spec) // (if tryFromPath.success
110+
then let path = tryFromPath.value;
111+
in {
112+
outPath = builtins.trace "using search host <${host}>" (
113+
if pkgs.lib.hasPrefix "/nix/store" (builtins.toString path)
114+
then path else gitignoreSource path);
115+
}
116+
else {});
117+
in if builtins.hasAttr "rev" spec && builtins.hasAttr "url" spec then
118+
defaultSpec //
119+
{ revOverride = rev: if (rev == null) then defaultSpec else
120+
let
121+
spec' = removeAttrs (spec // {
122+
rev = rev;
123+
url = builtins.replaceStrings [defaultSpec.rev] [rev] defaultSpec.url;
124+
}) [ "sha256" ];
125+
in
126+
spec' //
127+
{ outPath = callFunctionWith spec' (getFetcher spec') { }; };
128+
}
129+
else defaultSpec
130+
) sources

nix/update-iohk-nix.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
#!/usr/bin/env nix-shell
2-
#!nix-shell -i bash -p nix-prefetch-git
3-
4-
set -euo pipefail
5-
6-
NIX_DIR=$(dirname "$0")
7-
8-
nix-prefetch-git https://github.com/input-output-hk/iohk-nix refs/heads/haskell-nix-cardano-sl \
9-
> "$NIX_DIR/iohk-nix-src.json"
2+
#!nix-shell -A devops ../shell.nix -i bash
3+
niv update iohk-nix

shell.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ localLib ? import ./lib.nix
2+
}:
3+
let
4+
pkgs = localLib.iohkNix.pkgs;
5+
default = import ./default.nix {};
6+
devops = pkgs.stdenv.mkDerivation {
7+
name = "devops-shell";
8+
buildInputs = [
9+
localLib.niv
10+
];
11+
shellHook = ''
12+
echo "DevOps Tools" \
13+
| ${pkgs.figlet}/bin/figlet -f banner -c \
14+
| ${pkgs.lolcat}/bin/lolcat
15+
16+
echo "NOTE: you may need to export GITHUB_TOKEN if you hit rate limits with niv"
17+
echo "Commands:
18+
* niv update <package> - update package
19+
20+
"
21+
'';
22+
};
23+
in { inherit devops; }

0 commit comments

Comments
 (0)