Make 'nix flake check' work
This commit is contained in:
parent
da3b61b467
commit
7a69fb2363
6 changed files with 27 additions and 20 deletions
15
flake.nix
15
flake.nix
|
|
@ -11,7 +11,7 @@
|
|||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
|
|
@ -27,13 +27,13 @@
|
|||
# Dependency overrides go here
|
||||
};
|
||||
|
||||
defaultPackage = self.packages.${system}.${packageName};
|
||||
packages.default = self.packages.${system}.${packageName};
|
||||
|
||||
apps = {
|
||||
# run with: nix run #.hcat
|
||||
hcat = {
|
||||
type = "app";
|
||||
program = "${self.defaultPackage.${system}}/bin/hcat";
|
||||
program = "${self.packages.${system}.default}/bin/hcat";
|
||||
};
|
||||
|
||||
# run with: nix run
|
||||
|
|
@ -43,6 +43,8 @@
|
|||
checks = {
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
settings = { ormolu.defaultExtensions = [ "GHC2021" ]; };
|
||||
tools.fourmolu = haskellPackages.fourmolu;
|
||||
hooks = {
|
||||
nixfmt.enable = true;
|
||||
fourmolu.enable = true;
|
||||
|
|
@ -51,17 +53,18 @@
|
|||
doctest = {
|
||||
enable = true;
|
||||
name = "Run documentation tests";
|
||||
entry = "doctest";
|
||||
entry = "${haskellPackages.doctest}/bin/doctest src app";
|
||||
files = "\\.l?hs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
devShell = haskellPackages.shellFor {
|
||||
devShells.default = haskellPackages.shellFor {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
|
||||
packages = p: [ self.defaultPackage.${system} ];
|
||||
packages = p: [ self.packages.${system}.default ];
|
||||
|
||||
withHoogle = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ library
|
|||
default-extensions:
|
||||
BlockArguments
|
||||
OverloadedStrings
|
||||
ImportQualifiedPost
|
||||
ghc-options: -Wall -Wunused-packages -fdefer-typed-holes
|
||||
build-depends:
|
||||
base >=4.13 && <5
|
||||
|
|
@ -41,6 +42,7 @@ executable hcat
|
|||
default-extensions:
|
||||
BlockArguments
|
||||
OverloadedStrings
|
||||
ImportQualifiedPost
|
||||
ghc-options: -Wall -Wunused-packages -fdefer-typed-holes
|
||||
build-depends:
|
||||
base >=4.13 && <5
|
||||
|
|
@ -59,6 +61,7 @@ test-suite spec
|
|||
default-extensions:
|
||||
BlockArguments
|
||||
OverloadedStrings
|
||||
ImportQualifiedPost
|
||||
ghc-options: -Wall -Wunused-packages -fdefer-typed-holes
|
||||
cpp-options: -DTEST
|
||||
build-tool-depends:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ ghc-options:
|
|||
default-extensions:
|
||||
- BlockArguments
|
||||
- OverloadedStrings
|
||||
- ImportQualifiedPost
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
|
|
|||
12
src/HCat.hs
12
src/HCat.hs
|
|
@ -1,6 +1,6 @@
|
|||
module HCat (
|
||||
runHCat,
|
||||
defaultMain,
|
||||
runHCat,
|
||||
defaultMain,
|
||||
) where
|
||||
|
||||
import System.Environment qualified as Env
|
||||
|
|
@ -15,16 +15,16 @@ import HCat.Internal (parseArgs)
|
|||
|
||||
runHCat :: IO ()
|
||||
runHCat = do
|
||||
fileNameOrError <- parseArgs <$> Env.getArgs
|
||||
fileName <- eitherToError fileNameOrError
|
||||
TextIO.readFile fileName >>= TextIO.putStr
|
||||
fileNameOrError <- parseArgs <$> Env.getArgs
|
||||
fileName <- eitherToError fileNameOrError
|
||||
TextIO.readFile fileName >>= TextIO.putStr
|
||||
|
||||
eitherToError :: Show a => Either a b -> IO b
|
||||
eitherToError = either (Exception.throwIO . IOError.userError . show) return
|
||||
|
||||
handleError :: IOError -> IO ()
|
||||
handleError e = do
|
||||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||
|
||||
defaultMain :: IO ()
|
||||
defaultMain = Exception.catch runHCat handleError
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ module HCat.Internal where
|
|||
-- Right "foo"
|
||||
parseArgs :: [String] -> Either String FilePath
|
||||
parseArgs args = case args of
|
||||
[] -> Left "No filename given!"
|
||||
[arg] -> Right arg
|
||||
_ -> Left "Only a single file is supported"
|
||||
[] -> Left "No filename given!"
|
||||
[arg] -> Right arg
|
||||
_ -> Left "Only a single file is supported"
|
||||
|
||||
-- | @chunksOf n@ splits a list into chunks of at most @n@ items.
|
||||
--
|
||||
|
|
@ -24,7 +24,7 @@ parseArgs args = case args of
|
|||
chunksOf :: Int -> [a] -> [[a]]
|
||||
chunksOf _ [] = []
|
||||
chunksOf n xs@(_ : _)
|
||||
| n <= 0 = []
|
||||
| otherwise =
|
||||
let (chunk, rest) = splitAt n xs
|
||||
in chunk : chunksOf n rest
|
||||
| n <= 0 = []
|
||||
| otherwise =
|
||||
let (chunk, rest) = splitAt n xs
|
||||
in chunk : chunksOf n rest
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{-# LANGUAGE GHC2021 #-}
|
||||
-- {-# LANGUAGE GHC2021 #-}
|
||||
|
||||
module HCatSpec (spec) where
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue