forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNix.hs
More file actions
71 lines (64 loc) · 2.59 KB
/
Nix.hs
File metadata and controls
71 lines (64 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards, DeriveDataTypeable, OverloadedStrings #-}
-- | Nix configuration
module Stack.Config.Nix
(nixOptsFromMonoid
,nixCompiler
,StackNixException(..)
) where
import Stack.Prelude
import qualified Data.Text as T
import Distribution.System (OS (..))
import Stack.Types.Version
import Stack.Types.Nix
import Stack.Types.Compiler
-- | Interprets NixOptsMonoid options.
nixOptsFromMonoid
:: MonadUnliftIO m
=> NixOptsMonoid
-> OS
-> m NixOpts
nixOptsFromMonoid NixOptsMonoid{..} os = do
let nixEnable = fromFirst (getAny nixMonoidDefaultEnable) nixMonoidEnable
defaultPure = case os of
OSX -> False
_ -> True
nixPureShell = fromFirst defaultPure nixMonoidPureShell
nixPackages = fromFirst [] nixMonoidPackages
nixInitFile = getFirst nixMonoidInitFile
nixShellOptions = fromFirst [] nixMonoidShellOptions
++ prefixAll (T.pack "-I") (fromFirst [] nixMonoidPath)
nixAddGCRoots = fromFirst False nixMonoidAddGCRoots
when (not (null nixPackages) && isJust nixInitFile) $
throwIO NixCannotUseShellFileAndPackagesException
return NixOpts{..}
where prefixAll p (x:xs) = p : x : prefixAll p xs
prefixAll _ _ = []
nixCompiler :: CompilerVersion a -> Either StringException T.Text
nixCompiler compilerVersion =
let -- These are the latest minor versions for each respective major version available in nixpkgs
fixMinor "8.2" = "8.2.1"
fixMinor "8.0" = "8.0.2"
fixMinor "7.10" = "7.10.3"
fixMinor "7.8" = "7.8.4"
fixMinor "7.6" = "7.6.3"
fixMinor "7.4" = "7.4.2"
fixMinor "7.2" = "7.2.2"
fixMinor "6.12" = "6.12.3"
fixMinor "6.10" = "6.10.4"
fixMinor v = v
nixCompilerFromVersion v = T.append (T.pack "haskell.compiler.ghc")
(T.filter (/= '.')
(fixMinor (versionText v)))
in case compilerVersion of
GhcVersion v -> Right $ nixCompilerFromVersion v
_ -> Left $ stringException "Only GHC is supported by stack --nix"
-- Exceptions thown specifically by Stack.Nix
data StackNixException
= NixCannotUseShellFileAndPackagesException
-- ^ Nix can't be given packages and a shell file at the same time
deriving (Typeable)
instance Exception StackNixException
instance Show StackNixException where
show NixCannotUseShellFileAndPackagesException =
"You cannot have packages and a shell-file filled at the same time in your nix-shell configuration."