diff --git a/ChangeLog.md b/ChangeLog.md index 2da5b39dae..a2c0923957 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -34,6 +34,9 @@ Other enhancements: See [#3716](https://github.com/commercialhaskell/stack/issues/3716) * Improve the error message when an `extra-dep` from a path or git reference can't be found See [#3808](https://github.com/commercialhaskell/stack/pull/3808) +* Nix integration is now disabled on windows even if explicitly enabled, + since it isn't supported. See + [#3600](https://github.com/commercialhaskell/stack/issues/3600) Bug fixes: * 1.6.1 introduced a change that made some precompiled cache files use diff --git a/src/Stack/Config/Nix.hs b/src/Stack/Config/Nix.hs index b747777df5..99ab32689f 100644 --- a/src/Stack/Config/Nix.hs +++ b/src/Stack/Config/Nix.hs @@ -11,18 +11,20 @@ module Stack.Config.Nix import Stack.Prelude import qualified Data.Text as T import Distribution.System (OS (..)) +import Stack.Constants import Stack.Types.Version import Stack.Types.Nix import Stack.Types.Compiler +import Stack.Types.Runner -- | Interprets NixOptsMonoid options. nixOptsFromMonoid - :: MonadUnliftIO m + :: HasRunner env => NixOptsMonoid -> OS - -> m NixOpts + -> RIO env NixOpts nixOptsFromMonoid NixOptsMonoid{..} os = do - let nixEnable = fromFirst False nixMonoidEnable + let nixEnable0 = fromFirst False nixMonoidEnable defaultPure = case os of OSX -> False _ -> True @@ -32,6 +34,12 @@ nixOptsFromMonoid NixOptsMonoid{..} os = do nixShellOptions = fromFirst [] nixMonoidShellOptions ++ prefixAll (T.pack "-I") (fromFirst [] nixMonoidPath) nixAddGCRoots = fromFirst False nixMonoidAddGCRoots + nixEnable <- + if nixEnable0 && osIsWindows + then do + logInfo "Note: Disabling nix integration, since this is being run in Windows" + return False + else return nixEnable0 when (not (null nixPackages) && isJust nixInitFile) $ throwIO NixCannotUseShellFileAndPackagesException return NixOpts{..} diff --git a/src/test/Stack/NixSpec.hs b/src/test/Stack/NixSpec.hs index 870ca9e3be..3864273c94 100644 --- a/src/test/Stack/NixSpec.hs +++ b/src/test/Stack/NixSpec.hs @@ -1,14 +1,17 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TemplateHaskell, OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings #-} module Stack.NixSpec where +import Data.Maybe (fromJust) import Options.Applicative import Path +import Prelude (writeFile) import Stack.Config -import Stack.Options.NixParser import Stack.Config.Nix +import Stack.Constants +import Stack.Options.NixParser import Stack.Prelude import Stack.Types.Compiler import Stack.Types.Config @@ -18,8 +21,6 @@ import Stack.Types.Version import System.Directory import System.Environment import Test.Hspec -import Prelude (writeFile) -import Data.Maybe (fromJust) sampleConfigNixEnabled :: String sampleConfigNixEnabled = @@ -37,9 +38,6 @@ sampleConfigNixDisabled = "nix:\n" ++ " enable: False" -stackDotYaml :: Path Rel File -stackDotYaml = $(mkRelFile "stack.yaml") - setup :: IO () setup = unsetEnv "STACK_YAML" @@ -62,6 +60,7 @@ spec = beforeAll setup $ do (info (nixOptsParser False) mempty) cmdLineOpts parseOpts cmdLineOpts = mempty { configMonoidNixOpts = parseNixOpts cmdLineOpts } + let trueOnNonWindows = not osIsWindows describe "nix disabled in config file" $ around_ (withStackDotYaml sampleConfigNixDisabled) $ do it "sees that the nix shell is not enabled" $ do @@ -70,11 +69,11 @@ spec = beforeAll setup $ do describe "--nix given on command line" $ it "sees that the nix shell is enabled" $ do lc <- loadConfig' (parseOpts ["--nix"]) - nixEnable (configNix $ lcConfig lc) `shouldBe` True + nixEnable (configNix $ lcConfig lc) `shouldBe` trueOnNonWindows describe "--nix-pure given on command line" $ it "sees that the nix shell is enabled" $ do lc <- loadConfig' (parseOpts ["--nix-pure"]) - nixEnable (configNix $ lcConfig lc) `shouldBe` True + nixEnable (configNix $ lcConfig lc) `shouldBe` trueOnNonWindows describe "--no-nix given on command line" $ it "sees that the nix shell is not enabled" $ do lc <- loadConfig' (parseOpts ["--no-nix"]) @@ -87,7 +86,7 @@ spec = beforeAll setup $ do around_ (withStackDotYaml sampleConfigNixEnabled) $ do it "sees that the nix shell is enabled" $ do lc <- loadConfig' mempty - nixEnable (configNix $ lcConfig lc) `shouldBe` True + nixEnable (configNix $ lcConfig lc) `shouldBe` trueOnNonWindows describe "--no-nix given on command line" $ it "sees that the nix shell is not enabled" $ do lc <- loadConfig' (parseOpts ["--no-nix"]) @@ -95,11 +94,11 @@ spec = beforeAll setup $ do describe "--nix-pure given on command line" $ it "sees that the nix shell is enabled" $ do lc <- loadConfig' (parseOpts ["--nix-pure"]) - nixEnable (configNix $ lcConfig lc) `shouldBe` True + nixEnable (configNix $ lcConfig lc) `shouldBe` trueOnNonWindows describe "--no-nix-pure given on command line" $ it "sees that the nix shell is enabled" $ do lc <- loadConfig' (parseOpts ["--no-nix-pure"]) - nixEnable (configNix $ lcConfig lc) `shouldBe` True + nixEnable (configNix $ lcConfig lc) `shouldBe` trueOnNonWindows it "sees that the only package asked for is glpk and asks for the correct GHC derivation" $ do lc <- loadConfig' mempty nixPackages (configNix $ lcConfig lc) `shouldBe` ["glpk"]