diff --git a/default.nix b/default.nix index 5505951c34..7b1b90bd1c 100644 --- a/default.nix +++ b/default.nix @@ -2,10 +2,9 @@ let haskellNix = { checkMaterialization ? false, # Allows us to easily switch on materialization checking defaultCompilerNixName ? null, # Quick way to override the default compiler e.g. "ghc883" system ? builtins.currentSystem, - ... }: rec { - sources = { - inherit (import ./nixpkgs/default.nix) nixpkgs-1909 nixpkgs-2003 nixpkgs-default; - }; + sourcesOverride ? {}, + ... }@args: rec { + sources = (import ./nix/sources.nix) // sourcesOverride; config = import ./config.nix; overlays = [ allOverlays.combined ] ++ ( @@ -29,7 +28,7 @@ let haskellNix = { )] else [] ); - allOverlays = import ./overlays; + allOverlays = import ./overlays args; nixpkgsArgs = { inherit config overlays system; }; pkgs = import sources.nixpkgs-default nixpkgsArgs; }; diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000000..8ec5d0441d --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,50 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "f73bf8d584148677b01859677a63191c31911eae", + "sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-1909": { + "branch": "nixpkgs-19.09-darwin", + "description": "Nix Packages collection", + "homepage": null, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9237a09d8edbae9951a67e9a3434a07ef94035b7", + "sha256": "05bizymljzzd665bpsjbhxamcgzq7bkjjzjfapkl2nicy774ak4x", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/9237a09d8edbae9951a67e9a3434a07ef94035b7.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-2003": { + "branch": "nixpkgs-20.03-darwin", + "description": "Nix Packages collection", + "homepage": null, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cac363c661817666e43d047addfaa722610d425f", + "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-default": { + "branch": "nixpkgs-20.03-darwin", + "description": "Nix Packages collection", + "homepage": null, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cac363c661817666e43d047addfaa722610d425f", + "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000000..8a725cb4e7 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,134 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of 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 -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 -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 = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + 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 == "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 + builtins_fetchTarball = { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = fetch config.pkgs name spec; } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? ./sources.json + , sources ? builtins.fromJSON (builtins.readFile sourcesFile) + , pkgs ? mkPkgs sources + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/nixpkgs/default.nix b/nixpkgs/default.nix index 51bdd82966..867d2d7fa9 100644 --- a/nixpkgs/default.nix +++ b/nixpkgs/default.nix @@ -1,16 +1,4 @@ -# see ../docs/dev/nixpkgs-pin.md -let - fetch = jsonFile: - with builtins; - let spec = fromJSON (readFile jsonFile); - in fetchTarball { - name = "nixpkgs"; - inherit (spec) sha256; - url = "${spec.url}/archive/${spec.rev}.tar.gz"; - }; -in +# This file is for backwards compatibility only { - nixpkgs-2003 = fetch (./. + "/release-20.03.json"); - nixpkgs-1909 = fetch (./. + "/release-19.09.json"); - nixpkgs-default = fetch (./. + "/github.json"); + inherit (import ../nix/sources.nix) nixpkgs-2003 nixpkgs-1909 nixpkgs-default; } diff --git a/nixpkgs/github.json b/nixpkgs/github.json deleted file mode 100644 index e10e117e58..0000000000 --- a/nixpkgs/github.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "url": "https://github.com/NixOS/nixpkgs", - "rev": "cac363c661817666e43d047addfaa722610d425f", - "date": "2020-03-24T13:44:58+01:00", - "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf", - "fetchSubmodules": false, - "deepClone": false, - "leaveDotGit": false -} diff --git a/nixpkgs/hackage-src.json b/nixpkgs/hackage-src.json deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/nixpkgs/release-19.09.json b/nixpkgs/release-19.09.json deleted file mode 100644 index b52c040394..0000000000 --- a/nixpkgs/release-19.09.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "url": "https://github.com/NixOS/nixpkgs", - "rev": "9237a09d8edbae9951a67e9a3434a07ef94035b7", - "date": "2020-04-19T11:10:38+05:30", - "sha256": "05bizymljzzd665bpsjbhxamcgzq7bkjjzjfapkl2nicy774ak4x", - "fetchSubmodules": false, - "deepClone": false, - "leaveDotGit": false -} diff --git a/nixpkgs/release-20.03.json b/nixpkgs/release-20.03.json deleted file mode 100644 index e10e117e58..0000000000 --- a/nixpkgs/release-20.03.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "url": "https://github.com/NixOS/nixpkgs", - "rev": "cac363c661817666e43d047addfaa722610d425f", - "date": "2020-03-24T13:44:58+01:00", - "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf", - "fetchSubmodules": false, - "deepClone": false, - "leaveDotGit": false -} diff --git a/overlays/default.nix b/overlays/default.nix index 40f0c68756..00eeade884 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,9 +1,11 @@ +args: + let overlays = { wine = import ./wine.nix; #ghcjs = import ./ghcjs-asterius-triple.nix; #python = import ./python.nix; - haskell = import ./haskell.nix; + haskell = import ./haskell.nix args; hackage-quirks = import ./hackage-quirks.nix; bootstrap = import ./bootstrap.nix; ghc = import ./ghc.nix; diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 958029abda..c267163669 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -1,3 +1,5 @@ +{ sourcesOverride ? {} +, ... }: # The haskell.nix infrastructure # # for hygenic reasons we'll use haskell-nix as a prefix. @@ -10,6 +12,26 @@ final: prev: { # overlays. defaultModules = []; + # Niv based source pins. See https://github.com/nmattia/niv#niv + # for details on how to update this using the niv tool + # or edit nix/sources.json manually if you prefer. + sources = { + # Hackage and stackage still updated by scripts + # that predate our use of niv. We have moved them + # here though so that you can still use the + # sourcesOverride arg or `niv add` to replace them. + hackage = fetchExternal { + name = "hackage-exprs-source"; + specJSON = hackageSourceJSON; + override = "hackage"; + }; + stackage = fetchExternal { + name = "stackage-snapshot-source"; + specJSON = stackageSourceJSON; + override = "stackage"; + }; + } // (import ../nix/sources.nix) // sourcesOverride; + # We provide a `callPackage` function to consumers for # convenience. We will however refrain from using it # here and be explicit about imports and dependencies. @@ -37,11 +59,7 @@ final: prev: { cleanSourceHaskell; # All packages from Hackage as Nix expressions - hackageSrc = fetchExternal { - name = "hackage-exprs-source"; - specJSON = hackageSourceJSON; - override = "hackage"; - }; + hackageSrc = sources.hackage; hackage = import hackageSrc; # Contains the hashes of the cabal 01-index.tar.gz for given @@ -49,12 +67,7 @@ final: prev: { indexStateHashesPath = hackageSrc + "/index-state-hashes.nix"; # The set of all Stackage snapshots - stackageSrc = fetchExternal { - name = "stackage-snapshot-source"; - specJSON = stackageSourceJSON; - override = "stackage"; - }; - + stackageSrc = sources.stackage; stackage = import stackageSrc; # Utility functions for working with the component builder.