Skip to content

Commit

Permalink
Restore nix-tools support for GHC 9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Oct 22, 2024
1 parent 70d5eef commit 9f1bcd2
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions nix-tools/nix-tools/hackage2nix/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE LambdaCase #-}
Expand All @@ -6,10 +7,14 @@ module Main (main) where

import Cabal2Nix
import Cabal2Nix.Util ( quoted )
#if !MIN_VERSION_base(4, 17, 0)
import Control.Applicative ( liftA2 )
#endif
import Control.Monad.Trans.State.Strict
import Crypto.Hash.SHA256 ( hash )
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BS
import Data.Char ( isUpper )
import Data.Foldable ( toList
, for_
)
Expand Down Expand Up @@ -49,7 +54,6 @@ import System.Environment ( getArgs )
import System.FilePath ( (</>)
, (<.>)
)
import Data.Char (isUpper)

-- Avoid issues with case insensitive file systems by escaping upper case
-- characters with a leading _ character.
Expand All @@ -74,17 +78,20 @@ main = do
let (nixFiles, cabalFiles) =
runState (fmap (toList . (Seq.sortOn fst)) $ foldMapWithKeyA package2nix db) mempty
createDirectoryIfMissing False out
writeFile (out </> "default.nix") $
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {\n\
\ inherit (data) sha256;\n\
\ revisions = data.revisions // {\n\
\ default = revisions.\"${data.revisions.default}\";\n\
\ };\n\
\})) {\n"
-- Import all the per package nix files
<> mconcat (map (\(pname, _) ->
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;\n") nixFiles)
<> "}\n"
writeFile (out </> "default.nix") $ unlines [
"with builtins; mapAttrs (_: mapAttrs (_: data: rec {",
" inherit (data) sha256;",
" revisions = data.revisions // {",
" default = revisions.\"${data.revisions.default}\";",
" };",
"})) {",
-- Import all the per package nix files
unlines [
" " <> quoted pname <> " = import ./nix/" <> escapeUpperCase pname <> ".nix;"
| (pname, _) <- nixFiles
],
"}"
]

createDirectoryIfMissing False (out </> "nix")
for_ nixFiles $ \(pname, nix) ->
Expand Down

0 comments on commit 9f1bcd2

Please sign in to comment.