Skip to content

Commit 58dd973

Browse files
authored
Add ignorePackageYaml support to cabalProject (input-output-hk#2094)
* add ignorePackageYaml support to cabal project * move ignorePackageYaml option to project-common
1 parent 1cd599c commit 58dd973

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

lib/call-cabal-project-to-nix.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
# package.
6262
, evalPackages
6363
, supportHpack ? false # Run hpack on package.yaml files with no .cabal file
64+
, ignorePackageYaml ? false # Ignore package.yaml files even if they exist
6465
, ...
6566
}@args:
6667
let
@@ -494,7 +495,7 @@ let
494495
495496
# run `plan-to-nix` in $out. This should produce files right there with the
496497
# proper relative paths.
497-
(cd $out${subDir'} && plan-to-nix --full --plan-json $tmp${subDir'}/dist-newstyle/cache/plan.json -o .)
498+
(cd $out${subDir'} && plan-to-nix --full ${if ignorePackageYaml then "--ignore-package-yaml" else ""} --plan-json $tmp${subDir'}/dist-newstyle/cache/plan.json -o .)
498499
499500
# Replace the /nix/store paths to minimal git repos with indexes (that will work with materialization).
500501
${fixedProject.replaceLocations}

modules/project-common.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,15 @@ with lib.types;
7878
hsPkgs = lib.mkOption {
7979
type = lib.types.unspecified;
8080
};
81+
# Used by stack and cabal projects via
82+
# - ./lib/call-cabal-project-to-nix.nix
83+
# - ./lib/call-stack-to-nix.nix
84+
ignorePackageYaml = mkOption {
85+
type = bool;
86+
default = false;
87+
description = ''
88+
If set, prevents nix-tools from attempting to load package.yaml even if it is present.
89+
'';
90+
};
8191
};
8292
}

modules/stack-project.nix

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ with types;
99
type = str;
1010
default = "stack.yaml";
1111
};
12-
ignorePackageYaml = mkOption {
13-
type = bool;
14-
default = false;
15-
};
1612
cache = mkOption {
1713
type = nullOr unspecified;
1814
default = null;

nix-tools/nix-tools/plan2nix/Plan2Nix.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
8686
cwd <- getCurrentDirectory
8787
extrasNix <- fmap (mkNonRecSet . concat) . forM (Map.toList extras) $ \case
8888
(_name, Just (Package v flags (Just (LocalPath folder)) False)) ->
89-
do cabalFiles <- findCabalFiles folder
89+
do cabalFiles <- findCabalFiles (argHpackUse args) folder
9090
forM cabalFiles $ \cabalFile ->
9191
let pkg = cabalFilePkgName cabalFile
9292
nix = ".plan.nix" </> pkg <.> "nix"
@@ -155,7 +155,7 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
155155
cabalFromPath url rev subdir path = do
156156
d <- liftIO $ doesDirectoryExist path
157157
unless d $ fail ("not a directory: " ++ path)
158-
cabalFiles <- liftIO $ findCabalFiles path
158+
cabalFiles <- liftIO $ findCabalFiles (argHpackUse args) path
159159
return $ \sha256 ->
160160
forM cabalFiles $ \cabalFile -> do
161161
let pkg = cabalFilePkgName cabalFile

nix-tools/nix-tools/plan2nix/Plan2Nix/CLI.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module Plan2Nix.CLI
22
( Args(..)
3+
, HpackUse(..)
34
, parsePlan2NixArgs
45
) where
56

67
import Options.Applicative hiding (option)
78
import Data.Semigroup ((<>))
89
import Cabal2Nix (CabalDetailLevel(..))
10+
import Stack2nix.CLI (HpackUse(..))
911

1012
--------------------------------------------------------------------------------
1113
-- CLI Arguments
@@ -15,6 +17,7 @@ data Args = Args
1517
, argCabalProject :: FilePath
1618
, argCacheFile :: FilePath
1719
, argDetailLevel :: CabalDetailLevel
20+
, argHpackUse :: HpackUse
1821
} deriving Show
1922

2023
-- Argument Parser
@@ -25,6 +28,7 @@ args = Args
2528
<*> strOption ( long "cabal-project" <> value "cabal.project" <> showDefault <> metavar "FILE" <> help "Override path to cabal.project" )
2629
<*> strOption ( long "cache" <> value ".nix-tools.cache" <> showDefault <> metavar "FILE" <> help "Dependency cache file" )
2730
<*> flag MinimalDetails FullDetails ( long "full" <> help "Output details needed to determine what files are used" )
31+
<*> flag UsePackageYamlFirst IgnorePackageYaml (long "ignore-package-yaml" <> help "disable hpack run and use only cabal disregarding package.yaml existence")
2832

2933
parsePlan2NixArgs :: IO Args
3034
parsePlan2NixArgs = execParser opts

nix-tools/nix-tools/plan2nix/Plan2Nix/Project.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ import qualified Hpack.Config as Hpack
1616
import qualified Hpack.Render as Hpack
1717

1818
import Cabal2Nix (CabalFile(..), CabalFileGenerator(..))
19+
import Plan2Nix.CLI (HpackUse(..))
1920

20-
findCabalFiles :: FilePath -> IO [CabalFile]
21-
findCabalFiles path = doesFileExist (path </> Hpack.packageConfig) >>= \case
22-
False -> fmap (OnDisk . (path </>)) . filter (isSuffixOf ".cabal") <$> listDirectory path
21+
findOnlyCabalFiles :: FilePath -> IO [ CabalFile]
22+
findOnlyCabalFiles path = fmap (OnDisk . (path </>)) . filter (isSuffixOf ".cabal") <$> listDirectory path
23+
24+
findCabalFiles :: HpackUse -> FilePath -> IO [CabalFile]
25+
findCabalFiles IgnorePackageYaml path = findOnlyCabalFiles path
26+
findCabalFiles UsePackageYamlFirst path = doesFileExist (path </> Hpack.packageConfig) >>= \case
27+
False -> findOnlyCabalFiles path
2328
True -> do
2429
mbPkg <- Hpack.readPackageConfig Hpack.defaultDecodeOptions {Hpack.decodeOptionsTarget = path </> Hpack.packageConfig}
2530
case mbPkg of

0 commit comments

Comments
 (0)