Skip to content

Commit 9e5d2c0

Browse files
committed
55 - Refactor to use same Atom setup implementation on all Linux distributions
1 parent f0afea1 commit 9e5d2c0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/OS/Common.hs

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import qualified Turtle as T
1515
isExecutableInPath :: T.FilePath -> IO Bool
1616
isExecutableInPath name = isJust <$> T.which name
1717

18+
isNixInstalled :: IO Bool
19+
isNixInstalled = isExecutableInPath "nix"
20+
1821
isGhcInstalled :: IO Bool
1922
isGhcInstalled = isExecutableInPath "ghc"
2023

@@ -28,11 +31,16 @@ data NixConfiguration
2831
= User | NixOS deriving (Eq, Show)
2932

3033
doesFileExist' :: FilePath -> IO Bool
31-
doesFileExist' path
32-
| "~" `isPrefixOf` path = do
34+
doesFileExist' filePath = do
35+
fullFilePath <- toFullFilePath filePath
36+
doesFileExist fullFilePath
37+
38+
toFullFilePath :: FilePath -> IO FilePath
39+
toFullFilePath filePath
40+
| "~" `isPrefixOf` filePath = do
3341
homepath <- getHomeDirectory
34-
doesFileExist $ homepath ++ RU.tail path
35-
| otherwise = doesFileExist path
42+
return $ homepath ++ RU.tail filePath
43+
| otherwise = return filePath
3644

3745
getExistingNixConfigurations :: IO [NixConfiguration]
3846
getExistingNixConfigurations = map fst <$> filterM

src/OS/Linux.hs

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ logStep text sink actions = do
5252
appendLog ("END : " <> text) sink
5353

5454
configureNix :: Bool -> Sink Action -> IO ()
55-
configureNix run sink = undefined
55+
configureNix run sink = do
56+
isNixInstalled' <- isNixInstalled
57+
if isNixInstalled'
58+
then
59+
appendLog "Nix is already installed" sink
60+
else
61+
logStep "Installing Nix" sink (when run $ do
62+
_ <- runShellCommand "curl -L https://nixos.org/nix/install | sh"
63+
return ())
5664

5765
configureNixPackage :: Bool -> Sink Action -> ExtensionInfo -> IO ()
5866
configureNixPackage run sink (ExtensionInfo name package) = do
5967
nixConfiguration <- getOptimalNixConfiguration
60-
let configurationNixFilePath = unpack $ getNixConfigurationPath nixConfiguration
68+
configurationNixFilePath <- toFullFilePath $ unpack $ getNixConfigurationPath nixConfiguration
6169
oldConfigurationNixText <- liftIO $ readFile configurationNixFilePath
6270

6371
-- FIXME vvv requires Nix parsing using HNIX

0 commit comments

Comments
 (0)