git.iko.soy/typeable/cabal2nix
on master help sign in
nix-paths: fix dist target

The auto-generated source file worked fine, but cabal failed the sdist target because it can't deal with a package that doesn't contain any source code files. To remedy that issue, we now *have* a source code file and inject the actual paths from Setup.hs via CPP, similarly to ghc-paths does it.

commit47c9ce6802196748c379ed573b17dc1cd7a1d587 authorPeter Simons <simons@cryp.to> dateWed 9 Sep 2015, 12:35 (11 years ago) parent21be08a
4 files changed+36−22
nix-paths/Setup.lhs+15−20 nix-paths/nix-paths.cabal+1 nix-paths/src/Nix/Paths.hs+19 release.nix+1−2
nix-paths/Setup.lhsmode 100755 → 100644+15−20
@@ -3,14 +3,12 @@
33> module Main ( main ) where
44>
55> import Data.Char
6+> import Data.Maybe
67> import Distribution.PackageDescription
78> import Distribution.Simple
8−> import Distribution.Simple.BuildPaths
99> import Distribution.Simple.LocalBuildInfo
1010> import Distribution.Simple.Program
1111> import Distribution.Simple.Setup
12−> import System.Directory ( createDirectoryIfMissing )
13−> import System.FilePath
1412>
1513> main :: IO ()
1614> main = defaultMainWithHooks simpleUserHooks
@@ -23,23 +21,20 @@
2321>
2422> configure :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo
2523> configure (gpd, hbi) flags = do
26−> lbi <- confHook simpleUserHooks (gpd, hbi) flags
24+> lbi' <- confHook simpleUserHooks (gpd, hbi) flags
2725> let paths = [ (p, programPath pc) | p <- programs, Just pc <- [lookupProgram (simpleProgram p) (withPrograms lbi)] ]
28−> dirPath = autogenModulesDir lbi </> "Nix"
29−> createDirectoryIfMissing True dirPath
30−> writeFile (dirPath </> "Paths.hs") $
31−> unlines $
32−> "module Nix.Paths where\n" : map (uncurry fmtPath) paths
26+> descr = localPkgDescr lbi'
27+> lib = fromJust (library descr)
28+> libbi = libBuildInfo lib
29+> lbi = lbi' { localPkgDescr = descr
30+> { library = Just (lib { libBuildInfo = libbi { cppOptions = cppOptions libbi ++ map fmtCppArg paths } })
31+> }
32+> }
3333> return lbi
3434>
35−> fmtPath :: String -> FilePath -> String
36−> fmtPath name path = unlines
37−> [ "-- | Complete path to the @" ++ name ++ "@ executable."
38−> , mangle name ++ " :: FilePath"
39−> , mangle name ++ " = " ++ show path
40−> ]
41−>
42−> mangle :: String -> String
43−> mangle [] = []
44−> mangle ('-':c:cs) = toUpper c : mangle cs
45−> mangle (c:cs) = c : mangle cs
35+> fmtCppArg :: (String, FilePath) -> String
36+> fmtCppArg (prg, path) = "-DPATH_TO_" ++ map mangle prg ++ "=" ++ show path
37+> where
38+> mangle :: Char -> Char
39+> mangle '-' = '_'
40+> mangle c = toUpper c
nix-paths/nix-paths.cabal+1
@@ -19,6 +19,7 @@ source-repository head
1919
2020library
2121 default-language: Haskell2010
22+ hs-source-dirs: src
2223 exposed-modules: Nix.Paths
2324 build-depends: base < 5
2425 build-tools: nix-instantiate, nix-build, nix-env, nix-store
nix-paths/src/Nix/Paths.hsnew file+19
@@ -0,0 +1,19 @@
1+{-# LANGUAGE CPP #-}
2+
3+module Nix.Paths ( nixInstantiate, nixBuild, nixEnv, nixStore ) where
4+
5+-- | Complete path to the @nix-instantiate@ executable.
6+nixInstantiate :: FilePath
7+nixInstantiate = PATH_TO_NIX_INSTANTIATE
8+
9+-- | Complete path to the @nix-build@ executable.
10+nixBuild :: FilePath
11+nixBuild = PATH_TO_NIX_BUILD
12+
13+-- | Complete path to the @nix-env@ executable.
14+nixEnv :: FilePath
15+nixEnv = PATH_TO_NIX_ENV
16+
17+-- | Complete path to the @nix-store@ executable.
18+nixStore :: FilePath
19+nixStore = PATH_TO_NIX_STORE
release.nix+1−2
@@ -19,8 +19,7 @@ let
1919 });
2020 });
2121
22− # Don't build nix-paths strictly: it doesn't have a working sdist target yet.
23− # nix-paths = self.mkJob "nix-paths";
22+ nix-paths = self.mkJob "nix-paths";
2423
2524 language-nix = self.mkJob "language-nix";
2625