Skip to content

Commit

Permalink
Disable nix integration when run in windows #3600
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Feb 1, 2018
1 parent a08ecad commit 3e3c6bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/Stack/Config/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{..}
Expand Down
23 changes: 11 additions & 12 deletions src/test/Stack/NixSpec.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand All @@ -37,9 +38,6 @@ sampleConfigNixDisabled =
"nix:\n" ++
" enable: False"

stackDotYaml :: Path Rel File
stackDotYaml = $(mkRelFile "stack.yaml")

setup :: IO ()
setup = unsetEnv "STACK_YAML"

Expand All @@ -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
Expand All @@ -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"])
Expand All @@ -87,19 +86,19 @@ 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"])
nixEnable (configNix $ lcConfig lc) `shouldBe` False
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"]
Expand Down

0 comments on commit 3e3c6bd

Please sign in to comment.