@@ -9,13 +9,16 @@ module Stack.Config.Nix
99 ) where
1010
1111import Stack.Prelude
12+ import Control.Monad.Extra (ifM )
1213import qualified Data.Text as T
14+ import qualified Data.Text.IO as TIO
1315import Distribution.System (OS (.. ))
1416import Stack.Constants
1517import Stack.Types.Version
1618import Stack.Types.Nix
1719import Stack.Types.Compiler
1820import Stack.Types.Runner
21+ import System.Directory (doesFileExist )
1922
2023-- | Interprets NixOptsMonoid options.
2124nixOptsFromMonoid
@@ -34,12 +37,17 @@ nixOptsFromMonoid NixOptsMonoid{..} os = do
3437 nixShellOptions = fromFirst [] nixMonoidShellOptions
3538 ++ prefixAll (T. pack " -I" ) (fromFirst [] nixMonoidPath)
3639 nixAddGCRoots = fromFirst False nixMonoidAddGCRoots
37- nixEnable <-
38- if nixEnable0 && osIsWindows
39- then do
40- logInfo " Note: Disabling nix integration, since this is being run in Windows"
41- return False
42- else return nixEnable0
40+
41+ osIsNixOS <- isNixOS
42+ nixEnable <- case () of _
43+ | nixEnable0 && osIsWindows -> do
44+ logInfo " Note: Disabling nix integration, since this is being run in Windows"
45+ return False
46+ | not nixEnable0 && osIsNixOS -> do
47+ logInfo " Note: Enabling Nix integration, as it is required under NixOS"
48+ return True
49+ | otherwise -> return nixEnable0
50+
4351 when (not (null nixPackages) && isJust nixInitFile) $
4452 throwIO NixCannotUseShellFileAndPackagesException
4553 return NixOpts {.. }
@@ -77,3 +85,10 @@ instance Exception StackNixException
7785instance Show StackNixException where
7886 show NixCannotUseShellFileAndPackagesException =
7987 " You cannot have packages and a shell-file filled at the same time in your nix-shell configuration."
88+
89+ isNixOS :: MonadIO m => m Bool
90+ isNixOS = liftIO $ do
91+ let fp = " /etc/os-release"
92+ ifM (doesFileExist fp)
93+ (T. isInfixOf " ID=nixos" <$> TIO. readFile fp)
94+ (return False )
0 commit comments