55
66-- | Nix configuration
77module Stack.Config.Nix
8- ( nixOptsFromMonoid
9- , nixCompiler
10- , nixCompilerVersion
11- ) where
8+ ( nixCompiler
9+ , nixCompilerVersion
10+ , nixOptsFromMonoid
11+ ) where
1212
1313import Control.Monad.Extra ( ifM )
1414import qualified Data.Text as T
1515import qualified Data.Text.IO as TIO
1616import Distribution.System ( OS (.. ) )
17- import Stack.Constants
17+ import Stack.Constants ( osIsWindows )
1818import 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 ( .. ) )
2121import System.Directory ( doesFileExist )
2222
2323-- | Type representing exceptions thrown by functions exported by the
@@ -42,37 +42,40 @@ instance Exception ConfigNixException where
4242 ++ " Only GHC is supported by 'stack --nix'."
4343
4444-- | 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
5050nixOptsFromMonoid 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
6060
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
6464
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
7072
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 _ _ = []
7679
7780nixCompiler :: WantedCompiler -> Either ConfigNixException T. Text
7881nixCompiler compilerVersion =
@@ -112,7 +115,7 @@ nixCompilerVersion compilerVersion =
112115
113116isNixOS :: MonadIO m => m Bool
114117isNixOS = 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