5
5
6
6
-- | Nix configuration
7
7
module Stack.Config.Nix
8
- ( nixOptsFromMonoid
9
- , nixCompiler
10
- , nixCompilerVersion
11
- ) where
8
+ ( nixCompiler
9
+ , nixCompilerVersion
10
+ , nixOptsFromMonoid
11
+ ) where
12
12
13
13
import Control.Monad.Extra ( ifM )
14
14
import qualified Data.Text as T
15
15
import qualified Data.Text.IO as TIO
16
16
import Distribution.System ( OS (.. ) )
17
- import Stack.Constants
17
+ import Stack.Constants ( osIsWindows )
18
18
import Stack.Prelude
19
- import Stack.Types.Config
20
- import Stack.Types.Nix
19
+ import Stack.Types.Config ( HasRunner )
20
+ import Stack.Types.Nix ( NixOpts ( .. ), NixOptsMonoid ( .. ) )
21
21
import System.Directory ( doesFileExist )
22
22
23
23
-- | Type representing exceptions thrown by functions exported by the
@@ -42,37 +42,40 @@ instance Exception ConfigNixException where
42
42
++ " Only GHC is supported by 'stack --nix'."
43
43
44
44
-- | Interprets NixOptsMonoid options.
45
- nixOptsFromMonoid
46
- :: HasRunner env
47
- => NixOptsMonoid
48
- -> OS
49
- -> RIO env NixOpts
45
+ nixOptsFromMonoid ::
46
+ HasRunner env
47
+ => NixOptsMonoid
48
+ -> OS
49
+ -> RIO env NixOpts
50
50
nixOptsFromMonoid NixOptsMonoid {.. } os = do
51
- let defaultPure = case os of
52
- OSX -> False
53
- _ -> True
54
- nixPureShell = fromFirst defaultPure nixMonoidPureShell
55
- nixPackages = fromFirst [] nixMonoidPackages
56
- nixInitFile = getFirst nixMonoidInitFile
57
- nixShellOptions = fromFirst [] nixMonoidShellOptions
58
- ++ prefixAll (T. pack " -I" ) (fromFirst [] nixMonoidPath)
59
- nixAddGCRoots = fromFirstFalse nixMonoidAddGCRoots
51
+ let defaultPure = case os of
52
+ OSX -> False
53
+ _ -> True
54
+ nixPureShell = fromFirst defaultPure nixMonoidPureShell
55
+ nixPackages = fromFirst [] nixMonoidPackages
56
+ nixInitFile = getFirst nixMonoidInitFile
57
+ nixShellOptions = fromFirst [] nixMonoidShellOptions
58
+ ++ prefixAll (T. pack " -I" ) (fromFirst [] nixMonoidPath)
59
+ nixAddGCRoots = fromFirstFalse nixMonoidAddGCRoots
60
60
61
- -- Enable Nix-mode by default on NixOS, unless Docker-mode was specified
62
- osIsNixOS <- isNixOS
63
- let nixEnable0 = fromFirst osIsNixOS nixMonoidEnable
61
+ -- Enable Nix-mode by default on NixOS, unless Docker-mode was specified
62
+ osIsNixOS <- isNixOS
63
+ let nixEnable0 = fromFirst osIsNixOS nixMonoidEnable
64
64
65
- nixEnable <- case () of _
66
- | nixEnable0 && osIsWindows -> do
67
- logInfo " Note: Disabling nix integration, since this is being run in Windows"
68
- pure False
69
- | otherwise -> pure nixEnable0
65
+ nixEnable <- case () of
66
+ _
67
+ | nixEnable0 && osIsWindows -> do
68
+ logInfo
69
+ " Note: Disabling nix integration, since this is being run in Windows"
70
+ pure False
71
+ | otherwise -> pure nixEnable0
70
72
71
- when (not (null nixPackages) && isJust nixInitFile) $
72
- throwIO NixCannotUseShellFileAndPackagesException
73
- pure NixOpts {.. }
74
- where prefixAll p (x: xs) = p : x : prefixAll p xs
75
- prefixAll _ _ = []
73
+ when (not (null nixPackages) && isJust nixInitFile) $
74
+ throwIO NixCannotUseShellFileAndPackagesException
75
+ pure NixOpts {.. }
76
+ where
77
+ prefixAll p (x: xs) = p : x : prefixAll p xs
78
+ prefixAll _ _ = []
76
79
77
80
nixCompiler :: WantedCompiler -> Either ConfigNixException T. Text
78
81
nixCompiler compilerVersion =
@@ -112,7 +115,7 @@ nixCompilerVersion compilerVersion =
112
115
113
116
isNixOS :: MonadIO m => m Bool
114
117
isNixOS = liftIO $ do
115
- let fp = " /etc/os-release"
116
- ifM (doesFileExist fp)
117
- (T. isInfixOf " ID=nixos" <$> TIO. readFile fp)
118
- (pure False )
118
+ let fp = " /etc/os-release"
119
+ ifM (doesFileExist fp)
120
+ (T. isInfixOf " ID=nixos" <$> TIO. readFile fp)
121
+ (pure False )
0 commit comments