diff --git a/.gitignore b/.gitignore index 4f032d1cbde..e282e507943 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ doc/*.fls doc/*.synctex.gz haddocks/ + +# Visual Studio Code +/.vscode diff --git a/cabal.project b/cabal.project index 4208b34ace4..9ff051443d1 100644 --- a/cabal.project +++ b/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 diff --git a/nix/default.nix b/nix/default.nix index ce28d95a88b..5f854721cdd 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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; { diff --git a/nix/haskell.nix b/nix/haskell.nix index 8898b71c94b..052d613e5bb 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -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/ diff --git a/nix/sources.json b/nix/sources.json index 47f533e78f3..b2d8384f358 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -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///archive/.tar.gz" }, "iohk-nix": { @@ -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///archive/.tar.gz" }, "niv": { diff --git a/nix/sources.nix b/nix/sources.nix index 8a725cb4e7f..954ba5a6b64 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -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; }; @@ -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}"; @@ -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;