Skip to content

Commit

Permalink
Update index-state and nix updates
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy authored and nc6 committed Aug 3, 2020
1 parent e288509 commit f20c334
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -48,3 +48,6 @@ doc/*.fls
doc/*.synctex.gz

haddocks/

# Visual Studio Code
/.vscode
2 changes: 1 addition & 1 deletion cabal.project
@@ -1,4 +1,4 @@
index-state: 2020-05-15T00:00:00Z
index-state: 2020-07-15T00:00:00Z

packages: ./typed-protocols
./typed-protocols-examples
Expand Down
13 changes: 7 additions & 6 deletions nix/default.nix
Expand Up @@ -6,24 +6,25 @@
let
sources = import ./sources.nix { inherit pkgs; }
// sourcesOverride;
iohkNix = import sources.iohk-nix {};
haskellNix = import sources."haskell.nix";
iohkNixMain = import sources.iohk-nix {};
haskellNix = (import sources."haskell.nix" { inherit system sourcesOverride; }).nixpkgsArgs;
# use our own nixpkgs if it exists in our sources,
# otherwise use iohkNix default nixpkgs.
nixpkgs = if (sources ? nixpkgs)
then (builtins.trace "Not using IOHK default nixpkgs (use 'niv drop nixpkgs' to use default for better sharing)"
sources.nixpkgs)
else iohkNix.nixpkgs;
else (builtins.trace "Using IOHK default nixpkgs"
iohkNixMain.nixpkgs);

# for inclusion in pkgs:
overlays =
# Haskell.nix (https://github.com/input-output-hk/haskell.nix)
haskellNix.overlays
# haskell-nix.haskellLib.extra: some useful extra utility functions for haskell.nix
++ iohkNix.overlays.haskell-nix-extra
++ iohkNix.overlays.crypto
++ iohkNixMain.overlays.haskell-nix-extra
++ iohkNixMain.overlays.crypto
# iohkNix: nix utilities and niv:
++ iohkNix.overlays.iohkNix
++ iohkNixMain.overlays.iohkNix
# our own overlays:
++ [
(pkgs: _: with pkgs; {
Expand Down
5 changes: 4 additions & 1 deletion nix/haskell.nix
Expand Up @@ -21,7 +21,10 @@ let
};

projectPackages = lib.attrNames (haskell-nix.haskellLib.selectProjectPackages
(haskell-nix.cabalProject { inherit src; }));
(haskell-nix.cabalProject {
inherit src;
compiler-nix-name = compiler;
}));

# This creates the Haskell package set.
# https://input-output-hk.github.io/haskell.nix/user-guide/projects/
Expand Down
12 changes: 6 additions & 6 deletions nix/sources.json
Expand Up @@ -5,10 +5,10 @@
"homepage": "https://input-output-hk.github.io/haskell.nix",
"owner": "input-output-hk",
"repo": "haskell.nix",
"rev": "59cf05606e7efbbc4741ae28fd8cc610cec94eb8",
"sha256": "1dpk49z97ld6a9ggy9ph6apk1ccgjwwnc4pzirh6galbcci4rqap",
"rev": "35b1ec8cd577bfc5abf7d0325f38aab01de5ed00",
"sha256": "0mg18i6g7nxd7qk0kaca6k8dsc3kam21772zlr19k03ff67ws55j",
"type": "tarball",
"url": "https://github.com/input-output-hk/haskell.nix/archive/59cf05606e7efbbc4741ae28fd8cc610cec94eb8.tar.gz",
"url": "https://github.com/input-output-hk/haskell.nix/archive/35b1ec8cd577bfc5abf7d0325f38aab01de5ed00.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"iohk-nix": {
Expand All @@ -17,10 +17,10 @@
"homepage": null,
"owner": "input-output-hk",
"repo": "iohk-nix",
"rev": "6bd8f364080529ab9b9776e081085819624a4f3a",
"sha256": "0n17wl45hhqcrxlhb7f5xk8ln2k2nv8fqmx81ffnvjjfrfzdpfkm",
"rev": "95f7dfdff554223606f6be266c36eabe81cbe800",
"sha256": "05ibcw52jg7q66sd0vqj0fv3zlz7mdrfywys9111n4bj9rd9rl1n",
"type": "tarball",
"url": "https://github.com/input-output-hk/iohk-nix/archive/6bd8f364080529ab9b9776e081085819624a4f3a.tar.gz",
"url": "https://github.com/input-output-hk/iohk-nix/archive/95f7dfdff554223606f6be266c36eabe81cbe800.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
Expand Down
35 changes: 25 additions & 10 deletions nix/sources.nix
Expand Up @@ -12,11 +12,16 @@ let
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_tarball = pkgs: name: spec:
let
ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
# sanitize the name, though nix will still fail if name starts with period
name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };

fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
Expand Down Expand Up @@ -72,10 +77,10 @@ let
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs name 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 if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";

Expand All @@ -87,13 +92,23 @@ let
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);

# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);

# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));

# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatStrings = builtins.concatStringsSep "";

# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, sha256 }@attrs:
builtins_fetchTarball = { url, name, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
fetchTarball { inherit name url; }
else
fetchTarball attrs;

Expand Down

0 comments on commit f20c334

Please sign in to comment.