From 572378e7b8cdd343622ecca08dcd29d9fa56e425 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sat, 20 Jun 2020 13:22:37 +1200 Subject: [PATCH 1/2] Revert "Remove backwards compatibility with V1 code (#710)" This reverts commit da44734265e298fa28e9a7219d602a8aa1cf0cf2. --- default.nix | 78 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/default.nix b/default.nix index 6f236babb1..7b1b90bd1c 100644 --- a/default.nix +++ b/default.nix @@ -1,33 +1,49 @@ -{ 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 -, sourcesOverride ? {} -, ... }@args: rec { - sources = (import ./nix/sources.nix) // sourcesOverride; +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, + sourcesOverride ? {}, + ... }@args: rec { + sources = (import ./nix/sources.nix) // sourcesOverride; - config = import ./config.nix; - overlays = [ allOverlays.combined ] ++ ( - if checkMaterialization == true - then [( - final: prev: { - haskell-nix = prev.haskell-nix // { - checkMaterialization = true; - }; - } - )] - else [] - ) ++ ( - if defaultCompilerNixName != null - then [( - final: prev: { - haskell-nix = prev.haskell-nix // { - inherit defaultCompilerNixName; - }; - } - )] - else [] - ); - allOverlays = import ./overlays args; - nixpkgsArgs = { inherit config overlays system; }; - pkgs = import sources.nixpkgs-default nixpkgsArgs; + config = import ./config.nix; + overlays = [ allOverlays.combined ] ++ ( + if checkMaterialization == true + then [( + final: prev: { + haskell-nix = prev.haskell-nix // { + checkMaterialization = true; + }; + } + )] + else [] + ) ++ ( + if defaultCompilerNixName != null + then [( + final: prev: { + haskell-nix = prev.haskell-nix // { + inherit defaultCompilerNixName; + }; + } + )] + else [] + ); + allOverlays = import ./overlays args; + nixpkgsArgs = { inherit config overlays system; }; + pkgs = import sources.nixpkgs-default nixpkgsArgs; + }; + + haskellNixV1 = (haskellNix {}).nixpkgsArgs; + haskellNixV2 = haskellNix; + + v1DeprecationMessage = "Version 1 is deprecated: use version 2 (nixpkgs arguments are available as the `nixpkgsArgs` attribute of version 2)"; +# If no arguments, then you get V1 +# I'd like to make importing directly issue a warning, but I couldn't figure out a way to make it happen +in haskellNixV1 // { + __functor = _: { version ? 2, ... }@args: + if version == 1 + then builtins.trace v1DeprecationMessage haskellNixV1 + else if version == 2 + then haskellNixV2 args + else builtins.throw ("haskell.nix: unknown version: " + (builtins.toString version)); } From e176150dbf3b88b18d756ecabd2b5547cfcfae1e Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sat, 20 Jun 2020 13:40:22 +1200 Subject: [PATCH 2/2] Fix issue with warning not being displayed --- default.nix | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 7b1b90bd1c..c351d71944 100644 --- a/default.nix +++ b/default.nix @@ -33,16 +33,23 @@ let haskellNix = { pkgs = import sources.nixpkgs-default nixpkgsArgs; }; - haskellNixV1 = (haskellNix {}).nixpkgsArgs; + v1DeprecationMessage = "Version 1 is deprecated: use version 2 (nixpkgs arguments are available as the `nixpkgsArgs` attribute of version 2)"; + haskellNixV1 = (haskellNix {}).nixpkgsArgs // { + overlays = builtins.trace v1DeprecationMessage (haskellNix {}).nixpkgsArgs.overlays; + }; haskellNixV2 = haskellNix; - v1DeprecationMessage = "Version 1 is deprecated: use version 2 (nixpkgs arguments are available as the `nixpkgsArgs` attribute of version 2)"; # If no arguments, then you get V1 -# I'd like to make importing directly issue a warning, but I couldn't figure out a way to make it happen in haskellNixV1 // { - __functor = _: { version ? 2, ... }@args: + __functor = _: { + version ? 2, + 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, + sourcesOverride ? {}, + ... }@args: if version == 1 - then builtins.trace v1DeprecationMessage haskellNixV1 + then haskellNixV1 else if version == 2 then haskellNixV2 args else builtins.throw ("haskell.nix: unknown version: " + (builtins.toString version));