Skip to content

Commit 3a6b2fa

Browse files
committed
55 - Refactor to use same Atom setup implementation on all Linux distributions
1 parent b6d7956 commit 3a6b2fa

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

src/OS/Linux.hs

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,60 +27,64 @@ data ExtensionInfo = ExtensionInfo MisoString Text
2727
nixOsAtom :: Sink Action -> IO ()
2828
nixOsAtom sink = do
2929

30-
mapM_ configureNixPackage $ uncurry ExtensionInfo <$>
30+
mapM_ (configureNixPackage sink) $ uncurry ExtensionInfo <$>
3131
[ ("Haskell GHC", "haskell.compiler.ghc865")
3232
, ("cabal-install", "haskellPackages.cabal-install")
3333
, ("Atom", "atom")
3434
, ("Haskell IDE Engine", "((import (fetchTarball \"https://github.com/infinisil/all-hies/tarball/master\")\
3535
\ {}).selection { selector = p: { inherit (p) ghc865; }; })") ]
3636

37-
mapM_ configureAtomPackage [ "nix"
38-
, "atom-ide-ui"
39-
, "autocomplete-haskell"
40-
, "hasklig"
41-
, "ide-haskell-cabal"
42-
, "ide-haskell-hasktags"
43-
, "ide-haskell-hie"
44-
, "ide-haskell-hoogle"
45-
, "ide-haskell-repl"
46-
, "language-haskell" ]
37+
mapM_ (configureAtomPackage sink) [ "nix"
38+
, "atom-ide-ui"
39+
, "autocomplete-haskell"
40+
, "hasklig"
41+
, "ide-haskell-cabal"
42+
, "ide-haskell-hasktags"
43+
, "ide-haskell-hie"
44+
, "ide-haskell-hoogle"
45+
, "ide-haskell-repl"
46+
, "language-haskell" ]
4747

48-
where
49-
appendLog text = sink $ Append (text <> "\n")
50-
logStep text actions = do
51-
appendLog $ "BEGIN : " <> text
52-
_ <- actions
53-
appendLog $ "END : " <> text
54-
configureNixPackage (ExtensionInfo name package) =
55-
logStep ("Configuring " <> name) $ do
56-
let configurationNixFile = "/etc/nixos/configuration.nix"
57-
oldConfigurationNixText <- liftIO $ readFile configurationNixFile
48+
appendLog :: MisoString -> Sink Action -> IO ()
49+
appendLog text sink = sink $ Append (text <> "\n")
5850

59-
-- FIXME vvv requires Nix parsing using HNIX
60-
let environmentSystemPackages = "environment.systemPackages = with pkgs; ["
61-
newConfigurationNixText =
62-
if isPackagePresent
63-
then oldConfigurationNixText
51+
logStep :: MisoString -> Sink Action -> IO a -> IO ()
52+
logStep text sink actions = do
53+
appendLog ("BEGIN : " <> text) sink
54+
_ <- actions
55+
appendLog ("END : " <> text) sink
56+
57+
configureNixPackage :: Sink Action -> ExtensionInfo -> IO ()
58+
configureNixPackage sink (ExtensionInfo name package) =
59+
logStep ("Configuring " <> name) sink $ do
60+
let configurationNixFile = "/etc/nixos/configuration.nix"
61+
oldConfigurationNixText <- liftIO $ readFile configurationNixFile
6462

65-
else replace
66-
environmentSystemPackages
67-
(environmentSystemPackages <> "\n\
68-
\ " <> package)
69-
oldConfigurationNixText
70-
where isPackagePresent = package `isInfixOf` oldConfigurationNixText
71-
-- ^^^
63+
-- FIXME vvv requires Nix parsing using HNIX
64+
let environmentSystemPackages = "environment.systemPackages = with pkgs; ["
65+
isPackagePresent = package `isInfixOf` oldConfigurationNixText
66+
newConfigurationNixText =
67+
if isPackagePresent
68+
then oldConfigurationNixText
69+
else replace
70+
environmentSystemPackages
71+
(environmentSystemPackages <> "\n\
72+
\ " <> package)
73+
oldConfigurationNixText
74+
-- ^^^
7275

73-
liftIO $ writeFile configurationNixFile newConfigurationNixText
74-
if oldConfigurationNixText == newConfigurationNixText -- OPTIMIZE
75-
then appendLog "Nix package already installed"
76-
else logStep (toMisoString package) (runShellCommand "nixos-rebuild switch")
76+
liftIO $ writeFile configurationNixFile newConfigurationNixText
77+
if oldConfigurationNixText == newConfigurationNixText -- OPTIMIZE
78+
then appendLog "Nix package already installed" sink
79+
else logStep (toMisoString package) sink (runShellCommand "nixos-rebuild switch")
7780

78-
-- TODO install or update? extension or log message
79-
-- TODO ensure extensions are enabled if not enable them
80-
configureAtomPackage package = do
81-
-- check if package isAtomPackageInstalled
82-
-- install if not installed
83-
-- update if installed
84-
let installingPackage = "Installing Atom package - " <> toMisoString package
85-
logStep installingPackage $
86-
installAtomPackage package
81+
-- TODO install or update? extension or log message
82+
-- TODO ensure extensions are enabled if not enable them
83+
configureAtomPackage :: Sink Action -> Text -> IO ()
84+
configureAtomPackage sink package = do
85+
-- check if package isAtomPackageInstalled
86+
-- install if not installed
87+
-- update if installed
88+
let installingPackage = "Installing Atom package - " <> toMisoString package
89+
logStep installingPackage sink $
90+
installAtomPackage package

0 commit comments

Comments
 (0)