diff --git a/build.nix b/build.nix index 3e232af8..9b349714 100644 --- a/build.nix +++ b/build.nix @@ -35,7 +35,7 @@ in rec { maintainer-scripts = pkgs.dontRecurseIntoAttrs { update-hackage = import ./scripts/update-hackage.nix { inherit (pkgs) stdenv lib writeScript coreutils glibc git - openssh nix-prefetch-git gawk bash curl findutils; + openssh nixFlakes gawk bash curl findutils; # Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version) nix-tools = haskell.internal-nix-tools; cabal-install = haskell.internal-cabal-install; @@ -43,7 +43,7 @@ in rec { }; update-stackage = haskell.callPackage ./scripts/update-stackage.nix { inherit (pkgs) stdenv lib writeScript coreutils glibc git - openssh nix-prefetch-git gawk bash curl findutils; + openssh nixFlakes gawk bash curl findutils; # Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version) nix-tools = haskell.internal-nix-tools; cabal-install = haskell.internal-cabal-install; diff --git a/changelog.md b/changelog.md index 0154cf5c..5e8fcaf9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,12 @@ This file contains a summary of changes to Haskell.nix and `nix-tools` that will impact users. +## Aug 6, 2021 +* Included dependencies of haskell.nix that were tracked in `nix/sources.json` + as flake inputs (`flake.lock` replaces `nix/sources.json`). +* Uses `flake-compat` to continue to provide a compatible interface for non + flake projects. + ## Jul 23, 2021 * `source-repository-package` references in `cabal.project` files are now left as a `source-repository-package` when calculating the the `plan-nix` for diff --git a/ci-lib.nix b/ci-lib.nix index 4aa541cd..23839cf9 100644 --- a/ci-lib.nix +++ b/ci-lib.nix @@ -1,8 +1,8 @@ -let +{ # Generic nixpkgs, use *only* for lib functions that are stable across versions - pkgs = import (import ./nix/sources.nix).nixpkgs {}; - lib = pkgs.lib; -in rec { + pkgs ? (import ./. {}).pkgs, + lib ? pkgs.lib +}: rec { inherit (import ./dimension.nix) dimension; # A filter for removing packages that aren't supported on the current platform diff --git a/ci.nix b/ci.nix index ffd94483..8a93c14c 100644 --- a/ci.nix +++ b/ci.nix @@ -4,10 +4,11 @@ , ifdLevel ? 3 # Whether or not we are evaluating in restricted mode. This is true in Hydra, but not in Hercules. , restrictEval ? false -, checkMaterialization ? false }: +, checkMaterialization ? false +, pkgs ? (import ./. {}).pkgs }: let - inherit (import ./ci-lib.nix) dimension platformFilterGeneric filterAttrsOnlyRecursive; - sources = import ./nix/sources.nix {}; + inherit (import ./ci-lib.nix { inherit pkgs; }) dimension platformFilterGeneric filterAttrsOnlyRecursive; + inherit (pkgs.haskell-nix) sources; nixpkgsVersions = { "R2009" = "nixpkgs-2009"; "R2105" = "nixpkgs-2105"; diff --git a/default.nix b/default.nix index 4702756d..0de8f155 100644 --- a/default.nix +++ b/default.nix @@ -1,23 +1,17 @@ -{ checkMaterialization ? false # Allows us to easily switch on materialization checking -, system ? builtins.currentSystem -, sourcesOverride ? {} -, ... }@args: rec { - sources = (import ./nix/sources.nix { inherit pkgs; }) // sourcesOverride; - config = import ./config.nix; - overlays = [ allOverlays.combined ] ++ ( - if checkMaterialization == true - then [( - final: prev: { - haskell-nix = prev.haskell-nix // { - checkMaterialization = true; - }; - } - )] - else [] - ); - allOverlays = import ./overlays args; - nixpkgsArgs = { inherit config overlays system; }; - pkgs = import sources.nixpkgs nixpkgsArgs; - pkgs-unstable = import sources.nixpkgs-unstable nixpkgsArgs; - hix = import ./hix/default.nix; -} +{...}@args: + +let + nixpkgsSrc = + builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8.tar.gz"; + sha256 = "sha256:0jf9l6j60sa8cms7r4a02kr9j9884pwv1prf79b2ysnxmnhimnch"; + }; + pkgs = args.pkgs or import nixpkgsSrc {}; + flake-compat = + pkgs.fetchzip { + url = "https://github.com/hamishmack/flake-compat/archive/ce16b21b8a5588aa8b532353d3ceea89a38b8e77.tar.gz"; + sha256 = "sha256:054nsfqh3wy6v6bjamw0k91xl8v1rc5x2laic8mphrkrhzvyz5hi"; + }; + self = import flake-compat { src = ./.; inherit pkgs; }; +in self.defaultNix.internal.compat +({ system = args.pkgs.system or builtins.currentSystem; } // args) // self.defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..d4260764 --- /dev/null +++ b/flake.lock @@ -0,0 +1,285 @@ +{ + "nodes": { + "HTTP": { + "flake": false, + "locked": { + "lastModified": 1451647621, + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + }, + "original": { + "owner": "phadej", + "repo": "HTTP", + "type": "github" + } + }, + "cabal-32": { + "flake": false, + "locked": { + "lastModified": 1603716527, + "narHash": "sha256-sDbrmur9Zfp4mPKohCD8IDZfXJ0Tjxpmr2R+kg5PpSY=", + "owner": "haskell", + "repo": "cabal", + "rev": "94aaa8e4720081f9c75497e2735b90f6a819b08e", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.2", + "repo": "cabal", + "type": "github" + } + }, + "cabal-34": { + "flake": false, + "locked": { + "lastModified": 1622475795, + "narHash": "sha256-chwTL304Cav+7p38d9mcb+egABWmxo2Aq+xgVBgEb/U=", + "owner": "haskell", + "repo": "cabal", + "rev": "b086c1995cdd616fc8d91f46a21e905cc50a1049", + "type": "github" + }, + "original": { + "owner": "haskell", + "ref": "3.4", + "repo": "cabal", + "type": "github" + } + }, + "cardano-shell": { + "flake": false, + "locked": { + "lastModified": 1608537748, + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "cardano-shell", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1623875721, + "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "ghc-8.6.5-iohk": { + "flake": false, + "locked": { + "lastModified": 1600920045, + "narHash": "sha256-DO6kxJz248djebZLpSzTGD6s8WRpNI9BTwUeOf5RwY8=", + "owner": "input-output-hk", + "repo": "ghc", + "rev": "95713a6ecce4551240da7c96b6176f980af75cae", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "ref": "release/8.6.5-iohk", + "repo": "ghc", + "type": "github" + } + }, + "hackage": { + "flake": false, + "locked": { + "lastModified": 1628212308, + "narHash": "sha256-UcqeNBgYDRjWN1+VRRKbviPYCRFocamjOe5xTgyqo14=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "9bdefa51c864bbef48a2758b05b4b568f0ded62b", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "hackage.nix", + "type": "github" + } + }, + "hpc-coveralls": { + "flake": false, + "locked": { + "lastModified": 1607498076, + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + }, + "original": { + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "type": "github" + } + }, + "nix-tools": { + "flake": false, + "locked": { + "lastModified": 1626997434, + "narHash": "sha256-1judQmP298ao6cGUNxcGhcAXHOnA9qSLvWk/ZtoUL7w=", + "owner": "input-output-hk", + "repo": "nix-tools", + "rev": "c8c5e6a6fbb12a73598d1a434984a36e880ce3cf", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "nix-tools", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1624291665, + "narHash": "sha256-kNkaoa3dai9WOi7fsPklCCWZ8hRAkXx0ZUhpYKShyUk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-20.09-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2003": { + "locked": { + "lastModified": 1620055814, + "narHash": "sha256-8LEHoYSJiL901bTMVatq+rf8y7QtWuZhwwpKE2fyaRY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-20.03-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2009": { + "locked": { + "lastModified": 1624271064, + "narHash": "sha256-qns/uRW7MR2EfVf6VEeLgCsCp7pIOjDeR44JzTF09MA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "46d1c3f28ca991601a53e9a14fdd53fcd3dd8416", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-20.09-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-2105": { + "locked": { + "lastModified": 1624291665, + "narHash": "sha256-kNkaoa3dai9WOi7fsPklCCWZ8hRAkXx0ZUhpYKShyUk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-21.05-darwin", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1623862044, + "narHash": "sha256-mY7nldu9Wl/Yb0qMPihZrWw0bRWXNsk6iyYztw/6F6Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0747387223edf1aa5beaedf48983471315d95e16", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "old-ghc-nix": { + "flake": false, + "locked": { + "lastModified": 1621819714, + "narHash": "sha256-EJCnYQSWk7FRLwS0lZgTWIiQ6pcvDX1VuD6LGD4Uwzs=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "f089a6f090cdb35fcf95f865fc6a31ba6b3ac4eb", + "type": "github" + }, + "original": { + "owner": "angerman", + "ref": "master2", + "repo": "old-ghc-nix", + "type": "github" + } + }, + "root": { + "inputs": { + "HTTP": "HTTP", + "cabal-32": "cabal-32", + "cabal-34": "cabal-34", + "cardano-shell": "cardano-shell", + "flake-utils": "flake-utils", + "ghc-8.6.5-iohk": "ghc-8.6.5-iohk", + "hackage": "hackage", + "hpc-coveralls": "hpc-coveralls", + "nix-tools": "nix-tools", + "nixpkgs": "nixpkgs", + "nixpkgs-2003": "nixpkgs-2003", + "nixpkgs-2009": "nixpkgs-2009", + "nixpkgs-2105": "nixpkgs-2105", + "nixpkgs-unstable": "nixpkgs-unstable", + "old-ghc-nix": "old-ghc-nix", + "stackage": "stackage" + } + }, + "stackage": { + "flake": false, + "locked": { + "lastModified": 1628125397, + "narHash": "sha256-XXJwp4LJHZhCtGTIrZWV1mCz/0FtZEqxh9Z1k+9msWI=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "452e9c671ca172a355dbd2582bdb50ef5133af26", + "type": "github" + }, + "original": { + "owner": "input-output-hk", + "repo": "stackage.nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 419d3ba0..c418a8ee 100644 --- a/flake.nix +++ b/flake.nix @@ -2,36 +2,125 @@ description = "Alternative Haskell Infrastructure for Nixpkgs"; inputs = { - # Note: keep this in sync with sources.json! - nixpkgs.url = github:NixOS/nixpkgs/3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8; - nixpkgs-2009.url = github:NixOS/nixpkgs/46d1c3f28ca991601a53e9a14fdd53fcd3dd8416; - nixpkgs-2105.url = github:NixOS/nixpkgs/3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8; - nixpkgs-unstable.url = github:NixOS/nixpkgs/0747387223edf1aa5beaedf48983471315d95e16; - }; - - outputs = { self, nixpkgs, ... }: - { - - internal = rec { - config = import ./config.nix; - - nixpkgsArgs = { - inherit config; - overlays = [ self.overlay ]; - }; + nixpkgs = { url = "github:NixOS/nixpkgs/nixpkgs-20.09-darwin"; }; + nixpkgs-2003 = { url = "github:NixOS/nixpkgs/nixpkgs-20.03-darwin"; }; + nixpkgs-2009 = { url = "github:NixOS/nixpkgs/nixpkgs-20.09-darwin"; }; + nixpkgs-2105 = { url = "github:NixOS/nixpkgs/nixpkgs-21.05-darwin"; }; + nixpkgs-unstable = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; + flake-utils = { url = "github:numtide/flake-utils"; }; + hackage = { + url = "github:input-output-hk/hackage.nix"; + flake = false; + }; + stackage = { + url = "github:input-output-hk/stackage.nix"; + flake = false; + }; + cabal-32 = { + url = "github:haskell/cabal/3.2"; + flake = false; + }; + cabal-34 = { + url = "github:haskell/cabal/3.4"; + flake = false; + }; + cardano-shell = { + url = "github:input-output-hk/cardano-shell"; + flake = false; + }; + "ghc-8.6.5-iohk" = { + type = "github"; + owner = "input-output-hk"; + repo = "ghc"; + ref = "release/8.6.5-iohk"; + flake = false; + }; + hpc-coveralls = { + url = "github:sevanspowell/hpc-coveralls"; + flake = false; + }; + nix-tools = { + url = "github:input-output-hk/nix-tools"; + flake = false; + }; + old-ghc-nix = { + url = "github:angerman/old-ghc-nix/master2"; + flake = false; + }; + HTTP = { + url = "github:phadej/HTTP"; + flake = false; }; - - overlay = self.overlays.combined; - overlays = import ./overlays {}; - - legacyPackages = let - genAttrs = lst: f: - builtins.listToAttrs (map (name: { - inherit name; - value = f name; - }) lst); - in genAttrs [ "x86_64-linux" "x86_64-darwin" ] (system: - import nixpkgs - (self.internal.nixpkgsArgs // { localSystem = { inherit system; }; })); }; + + outputs = { self, nixpkgs, nixpkgs-unstable, flake-utils, ... }@inputs: + let compiler = "ghc884"; + in { + overlay = self.overlays.combined; + overlays = import ./overlays { sources = inputs; }; + internal = rec { + config = import ./config.nix; + nixpkgsArgs = { + inherit config; + overlays = [ self.overlay ]; + }; + + sources = inputs; + + overlaysOverrideable = import ./overlays; + # Compatibility with old default.nix + compat = { checkMaterialization ? + false # Allows us to easily switch on materialization checking + , system, sourcesOverride ? { }, ... }@args: rec { + sources = inputs // sourcesOverride; + allOverlays = import ./overlays args; + inherit config nixpkgsArgs; + overlays = [ allOverlays.combined ] + ++ (if checkMaterialization == true then + [ + (final: prev: { + haskell-nix = prev.haskell-nix // { + checkMaterialization = true; + }; + }) + ] + else + [ ]); + pkgs = import nixpkgs + (nixpkgsArgs // { localSystem = { inherit system; }; }); + pkgs-unstable = import nixpkgs-unstable + (nixpkgsArgs // { localSystem = { inherit system; }; }); + hix = import ./hix/default.nix { inherit pkgs; }; + }; + }; + + # Note: `nix flake check` evaluates outputs for all platforms, and haskell.nix + # uses IFD heavily, you have to have the ability to build for all platforms + # supported by haskell.nix, e.g. with remote builders, in order to check this flake. + # If you want to run the tests for just your platform, run `./test/tests.sh` or + # `nix-build -A checks.$PLATFORM` + } // flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system: { + legacyPackages = (self.internal.compat { inherit system; }).pkgs; + + # FIXME: Currently `nix flake check` requires `--impure` because coverage-golden + # (and maybe other tests) import projects that use builtins.currentSystem + checks = builtins.listToAttrs (map (pkg: { + name = pkg.name; + value = pkg; + }) (nixpkgs.lib.collect nixpkgs.lib.isDerivation (import ./test rec { + haskellNix = self.internal.compat { inherit system; }; + compiler-nix-name = compiler; + pkgs = haskellNix.pkgs; + }))); + + devShell = with self.legacyPackages.${system}; + mkShell { + buildInputs = [ + nixUnstable + cabal-install + haskell-nix.compiler.${compiler} + haskell-nix.nix-tools.${compiler} + ]; + }; + }); } diff --git a/hix/default.nix b/hix/default.nix index 55ce6dd5..31cf531b 100644 --- a/hix/default.nix +++ b/hix/default.nix @@ -1,26 +1,25 @@ +{ pkgs }: let - sources = import (../nix/sources.nix) {}; - nixpkgs = import sources.nixpkgs-2009 {}; args = '' --arg userDefaults "$HOME/.config/hix/hix.conf" --arg src ./.''; # Use HIX_ROOT to override the version of hix used when developing new hix features. # See docs/dev/hix.md for details. hixProject = "\${HIX_ROOT:-${./..}}/hix/project.nix"; -in nixpkgs.symlinkJoin { +in pkgs.symlinkJoin { name = "hix"; paths = [ - (nixpkgs.writeScriptBin "hix-shell" '' + (pkgs.writeScriptBin "hix-shell" '' nix-shell ${hixProject} ${args} -A shell "$@" '') - (nixpkgs.writeScriptBin "hix-build" '' + (pkgs.writeScriptBin "hix-build" '' nix-build ${hixProject} ${args} "$@" '') - (nixpkgs.writeScriptBin "hix-instantiate" '' + (pkgs.writeScriptBin "hix-instantiate" '' nix-instantiate ${hixProject} ${args} "$@" '') - (nixpkgs.writeScriptBin "hix-env" '' + (pkgs.writeScriptBin "hix-env" '' nix-env -f ${hixProject} ${args} "$@" '') - (nixpkgs.writeScriptBin "hix" '' + (pkgs.writeScriptBin "hix" '' cmd=$1 shift case $cmd in @@ -41,4 +40,4 @@ in nixpkgs.symlinkJoin { ]; } // { project = import ./project.nix; -} \ No newline at end of file +} diff --git a/hix/project.nix b/hix/project.nix index 74d478b6..6dc3db03 100644 --- a/hix/project.nix +++ b/hix/project.nix @@ -20,7 +20,7 @@ let { _module.args.pkgs = {}; } ]; }).config) name; - sources = import ../nix/sources.nix {}; + inherit (import ./.. {}) sources; lib = import (sources.nixpkgs-unstable + "/lib"); commandArgs' = builtins.listToAttrs ( diff --git a/lib/default.nix b/lib/default.nix index 4b9e6681..65a94a7c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -198,7 +198,7 @@ in { cleanGit = import ./clean-git.nix { inherit lib cleanSourceWith; git = gitMinimal; - inherit (pkgs) runCommand; + inherit (pkgs.evalPackages.buildPackages) runCommand; }; # Some times it is handy to temporarily use a relative path between git diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index af982755..00000000 --- a/nix/sources.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "cabal-32": { - "branch": "3.2", - "builtin": false, - "description": "Official upstream development repository for Cabal and cabal-install", - "homepage": "https://haskell.org/cabal", - "owner": "haskell", - "repo": "cabal", - "rev": "94aaa8e4720081f9c75497e2735b90f6a819b08e", - "sha256": "09m59w794zk4mxk1m3qkkmf5ydi0zhh89a7jk1wglrgxxadfndmh", - "type": "tarball", - "url": "https://github.com/haskell/cabal/archive/94aaa8e4720081f9c75497e2735b90f6a819b08e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "cabal-34": { - "branch": "3.4", - "description": "Official upstream development repository for Cabal and cabal-install", - "homepage": "https://haskell.org/cabal", - "owner": "haskell", - "repo": "cabal", - "rev": "f39af1b67a65dc1bb1fe70e4f02a3e6635f5ee26", - "sha256": "06c7q1y1ggbgczg7f4s5zds16n8bkfkdzg7mr5sw9m6gzbhgcby8", - "type": "tarball", - "url": "https://github.com/haskell/cabal/archive/f39af1b67a65dc1bb1fe70e4f02a3e6635f5ee26.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "cardano-shell": { - "branch": "master", - "builtin": false, - "description": "Node shell, a thin layer for running the node and it's modules.", - "homepage": null, - "owner": "input-output-hk", - "repo": "cardano-shell", - "rev": "9392c75087cb9a3d453998f4230930dea3a95725", - "sha256": "0gk1i8nkyp7c4jis2phcsr83dnd6g3nds8hpkjah4cp2cza5is9y", - "type": "tarball", - "url": "https://github.com/input-output-hk/cardano-shell/archive/9392c75087cb9a3d453998f4230930dea3a95725.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "ghc-8.6.5-iohk": { - "branch": "release/8.6.5-iohk", - "deepClone": true, - "description": "IOHK's ghc fork. See release/X.Y.Z-iohk branches.", - "homepage": "", - "owner": "input-output-hk", - "ref": "release/8.6.5-iohk", - "repo": "https://github.com/input-output-hk/ghc.git", - "rev": "95713a6ecce4551240da7c96b6176f980af75cae", - "sha256": "0hma1zsijw9z2i622qnxpmhahbjdjgq68hz1l57bbm3v9nzh21bc", - "type": "git", - "url": "https://github.com/input-output-hk/ghc.git", - "url_template": "https://github.com///archive/.tar.gz" - }, - "hpc-coveralls": { - "branch": "master", - "builtin": false, - "description": "coveralls.io support for haskell code coverage with hpc", - "homepage": "http://hackage.haskell.org/package/hpc-coveralls", - "owner": "sevanspowell", - "repo": "hpc-coveralls", - "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", - "sha256": "02dmcmqc845s7sdgdnk3xxn7l6jj8faa7547b4cii9mgv09arspj", - "type": "tarball", - "url": "https://github.com/sevanspowell/hpc-coveralls/archive/14df0f7d229f4cd2e79f8eabb1a740097fdfa430.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "niv": { - "branch": "master", - "builtin": false, - "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" - }, - "nix-tools": { - "branch": "master", - "builtin": false, - "description": "Translate Cabals Generic Package Description to a Nix expression", - "homepage": null, - "owner": "input-output-hk", - "repo": "nix-tools", - "rev": "15d2e4b61cb63ff351f3c490c12c4d89eafd31a1", - "sha256": "15p38dhbhk2c0bq8g9jr0gy01livigz0ca34c2mrwipbd4mipqgm", - "type": "tarball", - "url": "https://github.com/input-output-hk/nix-tools/archive/15d2e4b61cb63ff351f3c490c12c4d89eafd31a1.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs": { - "branch": "nixpkgs-21.05-darwin", - "builtin": true, - "description": "Nix Packages collection", - "homepage": null, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8", - "sha256": "0jf9l6j60sa8cms7r4a02kr9j9884pwv1prf79b2ysnxmnhimnch", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-2003": { - "branch": "nixpkgs-20.03-darwin", - "builtin": false, - "description": "Nix Packages collection", - "homepage": null, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", - "sha256": "05k9y9ki6jhaqdhycnidnk5zrdzsdammbk5lsmsbz249hjhhgcgh", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/1db42b7fe3878f3f5f7a4f2dc210772fd080e205.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-2009": { - "branch": "nixpkgs-20.09-darwin", - "builtin": false, - "description": "Nix Packages collection", - "homepage": null, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "46d1c3f28ca991601a53e9a14fdd53fcd3dd8416", - "sha256": "1h7lfhqws2cf8zg30fj8pakh4aw0id3m9yjpgn21scdv2nwkyyxa", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/46d1c3f28ca991601a53e9a14fdd53fcd3dd8416.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-2105": { - "branch": "nixpkgs-21.05-darwin", - "builtin": false, - "description": "Nix Packages collection", - "homepage": null, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8", - "sha256": "0jf9l6j60sa8cms7r4a02kr9j9884pwv1prf79b2ysnxmnhimnch", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/3c6f3f84af60a8ed5b8a79cf3026b7630fcdefb8.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-unstable": { - "branch": "nixpkgs-unstable", - "builtin": false, - "description": "Nix Packages collection", - "homepage": "", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0747387223edf1aa5beaedf48983471315d95e16", - "sha256": "19hpz87vfcr6icxcjdlp2mnk8v5db4l3x32adzc5ynmxvfayg3lr", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/0747387223edf1aa5beaedf48983471315d95e16.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "old-ghc-nix": { - "branch": "master2", - "builtin": false, - "description": "Old and New GHC", - "homepage": null, - "owner": "angerman", - "repo": "old-ghc-nix", - "rev": "f089a6f090cdb35fcf95f865fc6a31ba6b3ac4eb", - "sha256": "0fy32hz1i2ryp1aps39gjzm9122q2fc9bd045x8v34wn0ihsg40h", - "type": "tarball", - "url": "https://github.com/angerman/old-ghc-nix/archive/f089a6f090cdb35fcf95f865fc6a31ba6b3ac4eb.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 1938409d..00000000 --- a/nix/sources.nix +++ /dev/null @@ -1,174 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName 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 = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - 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 name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local 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}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # 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)) - ); - - # 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)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - 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 = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: 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/overlays/default.nix b/overlays/default.nix index 4a541eaa..f001b842 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,4 +1,4 @@ -args: +{ sources, ...}@args: let overlays = { diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 4f3247b1..692b0117 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -1,5 +1,4 @@ -{ sourcesOverride ? {} -, ... }: +{ sources, ... }: # The haskell.nix infrastructure # # for hygienic reasons we'll use haskell-nix as a prefix. @@ -12,25 +11,10 @@ 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 { pkgs = final; }) // sourcesOverride; + # Nix Flake based source pins. + # To update all inputs, get unstable Nix and then `nix flake update --recreate-lock-file` + # Or `nix-shell -p nixUnstable --run "nix --experimental-features 'nix-command flakes' flake update --recreate-lock-file"` + sources = sources; # We provide a `callPackage` function to consumers for # convenience. We will however refrain from using it diff --git a/release.nix b/release.nix index 8f05fc06..d9681546 100644 --- a/release.nix +++ b/release.nix @@ -11,8 +11,8 @@ let then __trace (prefix + n) v else traceNames (prefix + n + ".") v else v); - inherit (import ./ci-lib.nix) stripAttrsForHydra filterDerivations; - genericPkgs = import (import ./nix/sources.nix).nixpkgs {}; + inherit (import ./ci-lib.nix { pkgs = genericPkgs; }) stripAttrsForHydra filterDerivations; + genericPkgs = (import ./. {}).pkgs; lib = genericPkgs.lib; ci = import ./ci.nix { inherit supportedSystems ifdLevel checkMaterialization; restrictEval = true; }; allJobs = stripAttrsForHydra (filterDerivations ci); diff --git a/scripts/check-hydra.nix b/scripts/check-hydra.nix index 5d43ba7d..5db09c8c 100644 --- a/scripts/check-hydra.nix +++ b/scripts/check-hydra.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, writeScript, coreutils, time, gnutar, gzip, hydra-migration, jq }: +{ stdenv, lib, writeScript, coreutils, time, gnutar, gzip, hydra-migration, jq, gitMinimal }: with lib; @@ -7,7 +7,7 @@ writeScript "check-hydra.sh" '' set -euo pipefail - export PATH="${makeBinPath [ coreutils time gnutar gzip hydra-migration jq ]}" + export PATH="${makeBinPath [ coreutils time gnutar gzip hydra-migration jq gitMinimal ]}" echo '~~~ Evaluating release.nix with --arg ifdLevel '$1 command time --format '%e' -o eval-time.txt \ diff --git a/scripts/check-path-support.nix b/scripts/check-path-support.nix index c38833d8..44cb8721 100644 --- a/scripts/check-path-support.nix +++ b/scripts/check-path-support.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, writeScript, coreutils, gnutar, gzip, nix }: +{ stdenv, lib, writeScript, coreutils, gnutar, gzip, nix, gitMinimal }: with lib; @@ -7,7 +7,7 @@ writeScript "check-path-supprot.sh" '' set -euo pipefail - export PATH="${makeBinPath [ coreutils gnutar gzip nix ]}" + export PATH="${makeBinPath [ coreutils gnutar gzip nix gitMinimal ]}" nix-build -E '((import ./. {}).pkgs.haskell-nix.cabalProject { compiler-nix-name = "ghc865"; src = ./test/cabal-simple; }).cabal-simple.components.library' '' diff --git a/scripts/update-external.nix b/scripts/update-external.nix index c47d10e8..88530c87 100644 --- a/scripts/update-external.nix +++ b/scripts/update-external.nix @@ -1,5 +1,5 @@ { stdenv, lib, writeScript, glibc, coreutils, git, openssh -, nix-tools, cabal-install, nix-prefetch-git +, nix-tools, cabal-install, nixFlakes , bash, curl, findutils, gawk }: { name, script }: @@ -16,7 +16,7 @@ in set -euo pipefail - export PATH="${makeBinPath ([ coreutils curl findutils gawk bash git openssh nix-tools cabal-install nix-prefetch-git ] ++ optional stdenv.isLinux glibc)}" + export PATH="${makeBinPath ([ coreutils curl findutils gawk bash git openssh nix-tools cabal-install nixFlakes ] ++ optional stdenv.isLinux glibc)}" ${script} @@ -35,5 +35,5 @@ in cd .. - nix-prefetch-git ${repoHTTPS} --rev "$rev" | tee ${name}-src.json + nix --experimental-features 'nix-command flakes' flake lock --update-input ${name} '' diff --git a/scripts/update-hackage.nix b/scripts/update-hackage.nix index 78c6d891..e0ef77d5 100644 --- a/scripts/update-hackage.nix +++ b/scripts/update-hackage.nix @@ -1,5 +1,5 @@ { stdenv, lib, writeScript, coreutils, glibc, git, openssh -, nix-tools, cabal-install, nix-prefetch-git +, nix-tools, cabal-install, nixFlakes , gawk, bash, curl, findutils , update-index-state-hashes }@args: diff --git a/scripts/update-stackage.nix b/scripts/update-stackage.nix index 0cfa9989..5227b469 100644 --- a/scripts/update-stackage.nix +++ b/scripts/update-stackage.nix @@ -1,5 +1,5 @@ { stdenv, lib, writeScript, coreutils, glibc, git, openssh -, nix-tools, cabal-install, nix-prefetch-git +, nix-tools, cabal-install, nixFlakes , gawk, bash, curl, findutils }@args: import ./update-external.nix args { diff --git a/shell.nix b/shell.nix index eb7532ef..c22e7e63 100644 --- a/shell.nix +++ b/shell.nix @@ -1,12 +1 @@ -let - inherit (import ./default.nix {}) sources nixpkgsArgs; - pkgs = import sources.nixpkgs nixpkgsArgs; -in pkgs.stdenv.mkDerivation rec { - name = "env"; - env = pkgs.buildEnv { name = name; paths = buildInputs; }; - buildInputs = [ - pkgs.cabal-install - pkgs.haskell-nix.ghc - pkgs.haskell-nix.nix-tools - ]; -} +(import ./default.nix {}).devShell.${builtins.currentSystem} diff --git a/test/default.nix b/test/default.nix index 90eab689..7a70cb2f 100644 --- a/test/default.nix +++ b/test/default.nix @@ -1,4 +1,4 @@ -{ haskellNix ? import ../default.nix { inherit checkMaterialization; } +{ haskellNix ? import ../default.nix { } , pkgs ? import nixpkgs nixpkgsArgs , nixpkgs ? haskellNix.sources.nixpkgs-unstable , nixpkgsArgs ? haskellNix.nixpkgsArgs @@ -10,7 +10,7 @@ with pkgs; let - inherit (import ../ci-lib.nix) dimension platformFilterGeneric filterAttrsOnlyRecursive; + inherit (import ../ci-lib.nix { inherit pkgs; }) dimension platformFilterGeneric filterAttrsOnlyRecursive; isDisabled = d: d.meta.disabled or false; # Set recurseForDerivations for both children and grand-children values in diff --git a/test/fully-static/cross.nix b/test/fully-static/cross.nix index fe25d12e..f1ae73a5 100644 --- a/test/fully-static/cross.nix +++ b/test/fully-static/cross.nix @@ -1,5 +1,5 @@ { pkgs ? import nixpkgs { } -, nixpkgs ? import (../../nix/sources.nix).nixpkgs +, nixpkgs ? (import ../.. { }).sources.nixpkgs }: let