[Chore] Use new flake template

Problem: We have introduced a new template for Haskell libraries and
need to update this package according to this template.

Solution: Use new template, bump dependencies, remove unused license,
apply formatting and hlint suggestions.
This commit is contained in:
Sergey Gulin 2023-03-08 21:31:19 +03:00
parent e74dcfafbf
commit 2629e86f7b
No known key found for this signature in database
GPG Key ID: 4974F364CB8EDF61
16 changed files with 1040 additions and 128 deletions

60
.github/workflows/check.yml vendored Normal file
View File

@ -0,0 +1,60 @@
# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0
name: Nix flake check
on: push
jobs:
validate:
runs-on: [self-hosted, nix]
steps:
- uses: actions/checkout@v3
- name: xrefcheck
run: nix run github:serokell/xrefcheck
- name: reuse
run: nix build -L .#checks.x86_64-linux.reuse-lint
# Run step even if the previous one has failed
if: success() || failure()
- name: hlint
run: nix build -L .#checks.x86_64-linux.hlint
if: success() || failure()
- name: stylish-haskell
run: nix build -L .#checks.x86_64-linux.stylish-haskell
if: success() || failure()
- name: check-trailing-whitespace
run: nix build -L .#checks.x86_64-linux.trailing-whitespace
if: success() || failure()
# Export JSON serialized ghc-versions
ghc-versions:
runs-on: [self-hosted, nix]
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "matrix=$(nix eval --json .#ghc-matrix.x86_64-linux)" >> $GITHUB_OUTPUT
build-and-test:
needs: ghc-versions
name: ghc${{ matrix.ghc }}
runs-on: [self-hosted, nix]
strategy:
fail-fast: false
matrix: ${{fromJson(needs.ghc-versions.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
- name: build
run: nix build -L .#checks.x86_64-linux.ghc${{ matrix.ghc }}:build-all --keep-going
- name: test
run: nix build -L .#checks.x86_64-linux.ghc${{ matrix.ghc }}:test-all --keep-going
if: success() || failure()

63
.stylish-haskell.yaml Normal file
View File

@ -0,0 +1,63 @@
# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: Unlicense
steps:
- simple_align:
cases: false
top_level_patterns: false
records: false
- imports:
align: none
list_align: after_alias
pad_module_names: false
long_list_align: new_line
empty_list_align: inherit
list_padding: 2
separate_lists: true
space_surround: false
post_qualify: false
- trailing_whitespace: {}
columns: 100
newline: native
language_extensions:
- BangPatterns
- BlockArguments
- ConstraintKinds
- DataKinds
- DefaultSignatures
- DeriveAnyClass
- DeriveDataTypeable
- DeriveGeneric
- DerivingStrategies
- DerivingVia
- EmptyCase
- ExistentialQuantification
- ExplicitNamespaces
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- ImportQualifiedPost
- LambdaCase
- MultiParamTypeClasses
- MultiWayIf
- NamedFieldPuns
- NumericUnderscores
- OverloadedLabels
- OverloadedStrings
- PatternSynonyms
- QuantifiedConstraints
- RebindableSyntax
- RecordWildCards
- RecursiveDo
- ScopedTypeVariables
- StandaloneDeriving
- TemplateHaskell
- TemplateHaskellQuotes
- TupleSections
- TypeApplications
- TypeFamilies
- TypeOperators
- ViewPatterns

View File

@ -1,7 +0,0 @@
Copyright 2019 Nicolas Mattia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

24
LICENSES/Unlicense.txt Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View File

@ -2,9 +2,9 @@
-- --
-- SPDX-License-Identifier: MPL-2.0 -- SPDX-License-Identifier: MPL-2.0
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
#include <HsBaseConfig.h> #include <HsBaseConfig.h>
@ -57,7 +57,7 @@ showEnvVar name = do
putStr $ " * " <> name <> " " putStr $ " * " <> name <> " "
lookupEnv name >>= \case lookupEnv name >>= \case
Nothing -> putStrLn "is not set" Nothing -> putStrLn "is not set"
Just v -> putStrLn $ "= " <> v Just v -> putStrLn $ "= " <> v
showSystem :: IO () showSystem :: IO ()
@ -107,7 +107,7 @@ showCbits = do
enc <- c_libcharsetEncoding >>= peekCAString enc <- c_libcharsetEncoding >>= peekCAString
putStrLn $ " * libcharset:locale_charset = " <> enc putStrLn $ " * libcharset:locale_charset = " <> enc
#else #else
putStrLn $ " * No libcharset." putStrLn " * No libcharset."
#endif #endif
showLanginfoh :: IO () showLanginfoh :: IO ()
@ -116,7 +116,7 @@ showCbits = do
enc <- c_langinfoEncoding >>= peekCAString enc <- c_langinfoEncoding >>= peekCAString
putStrLn $ " * langinfo.h:nl_langinfo(CODESET) = " <> enc putStrLn $ " * langinfo.h:nl_langinfo(CODESET) = " <> enc
#else #else
putStrLn $ " * No <langinfo.h>." putStrLn " * No <langinfo.h>."
#endif #endif
#if defined(HAVE_LIBCHARSET) #if defined(HAVE_LIBCHARSET)
@ -143,7 +143,7 @@ showLocales = do
putStrLn "# Locales" putStrLn "# Locales"
tryIO callLocalectl >>= \case tryIO callLocalectl >>= \case
Right out -> do Right out -> do
putStrLn $ " * localectl list-locales:" putStrLn " * localectl list-locales:"
showLocaleList (lines out) showLocaleList (lines out)
Left _ -> do Left _ -> do
listDir "/usr/lib/locale" listDir "/usr/lib/locale"

View File

@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0
(import ( (import (
fetchTarball { fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";

File diff suppressed because it is too large Load Diff

2
flake.lock.license Normal file
View File

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
SPDX-License-Identifier: MPL-2.0

114
flake.nix
View File

@ -1,38 +1,110 @@
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io/> # SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io/>
# #
# SPDX-License-Identifier: MPL-2.0 # SPDX-License-Identifier: MPL-2.0
{ {
description = "Get your UTF-8 IO right on the first try";
nixConfig = { nixConfig = {
flake-registry = "https://github.com/serokell/flake-registry/raw/master/flake-registry.json"; flake-registry = "https://github.com/serokell/flake-registry/raw/master/flake-registry.json";
}; };
inputs = { inputs = {
nixpkgs.url = "github:serokell/nixpkgs"; flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
flake = false;
};
haskell-nix = { haskell-nix = {
inputs.hackage.follows = "hackage"; inputs.hackage.follows = "hackage";
inputs.stackage.follows = "stackage"; inputs.stackage.follows = "stackage";
}; };
hackage.flake = false; hackage = {
stackage.flake = false; flake = false;
};
stackage = {
flake = false;
};
}; };
outputs = { self, nixpkgs, flake-utils, serokell-nix, haskell-nix, hackage, stackage }: outputs = { self, nixpkgs, haskell-nix, hackage, stackage, serokell-nix, flake-compat, flake-utils, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}.extend haskell-nix.overlay; haskellPkgs = haskell-nix.legacyPackages."${system}";
pkgs = import nixpkgs {
inherit system;
overlays = [
serokell-nix.overlay
];
};
flake = lib = pkgs.lib;
serokell-nix.lib.haskell.makeFlake pkgs.haskell-nix pkgs.haskell-nix.stackProject {
src = ./.; hs-package-name = "with-utf8";
ghcVersions = [ "884" "8107" "901" "921" ];
modules = [ serokell-nix.lib.haskell.ciBuildOptions ]; ghc-versions = [ "884" "8107" "902" "926" "944" ];
};
in flake // { # invoke haskell.nix for each ghc version listed in ghc-versions
defaultPackage = flake.packages."with-utf8:lib:with-utf8"; pkgs-per-ghc = lib.genAttrs (map (v: "ghc${v}") ghc-versions)
defaultApp = flake.apps."with-utf8:exe:utf8-troubleshoot"; (ghc: haskellPkgs.haskell-nix.cabalProject {
} src = haskellPkgs.haskell-nix.haskellLib.cleanGit {
); name = hs-package-name;
src = ./.;
};
compiler-nix-name = ghc;
# haskell.nix configuration
modules = [{
packages.${hs-package-name} = {
ghcOptions = [
# fail on warnings
"-Werror"
# disable optimisations, we don't need them if we don't package or deploy the executable
"-O0"
];
};
}];
});
# returns the list of all components for a package
get-package-components = pkg:
# library
lib.optional (pkg ? library) pkg.library
# haddock
++ lib.optional (pkg ? library) pkg.library.haddock
# exes, tests and benchmarks
++ lib.attrValues pkg.exes
++ lib.attrValues pkg.tests
++ lib.attrValues pkg.benchmarks;
# all components for each specified ghc version
build-all = lib.mapAttrs'
(ghc: pkg:
let components = get-package-components pkg.${hs-package-name}.components;
in lib.nameValuePair "${ghc}:build-all"
(pkgs.linkFarmFromDrvs "build-all" components)) pkgs-per-ghc;
# all tests for each specified ghc version
test-all = lib.mapAttrs'
(ghc: pkg:
let tests = lib.filter lib.isDerivation
(lib.attrValues pkg.${hs-package-name}.checks);
in lib.nameValuePair "${ghc}:test-all"
(pkgs.linkFarmFromDrvs "test-all" tests)) pkgs-per-ghc;
in {
# nixpkgs revision pinned by this flake
legacyPackages = pkgs;
# used to dynamically build a matrix in the GitHub pipeline
ghc-matrix = {
include = map (ver: { ghc = ver; }) ghc-versions;
};
# derivations that we can run from CI
checks = build-all // test-all // {
trailing-whitespace = pkgs.build.checkTrailingWhitespace ./.;
reuse-lint = pkgs.build.reuseLint ./.;
hlint = pkgs.build.haskell.hlint ./.;
stylish-haskell = pkgs.build.haskell.stylish-haskell ./.;
};
});
} }

View File

@ -62,7 +62,7 @@ withUtf8 act = withStdTerminalHandles $
bracket bracket
(liftIO $ getLocaleEncoding <* setLocaleEncoding utf8) (liftIO $ getLocaleEncoding <* setLocaleEncoding utf8)
(liftIO . setLocaleEncoding) (liftIO . setLocaleEncoding)
(\_ -> act) (const act)
-- | Make standard handles safe to write anything to them. -- | Make standard handles safe to write anything to them.
-- --

View File

@ -3,7 +3,7 @@
- SPDX-License-Identifier: MPL-2.0 - SPDX-License-Identifier: MPL-2.0
-} -}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |

View File

@ -3,8 +3,7 @@
- SPDX-License-Identifier: MPL-2.0 - SPDX-License-Identifier: MPL-2.0
-} -}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
-- | Internal functions that implement encoding selection logic. -- | Internal functions that implement encoding selection logic.
module System.IO.Utf8.Internal module System.IO.Utf8.Internal
@ -83,4 +82,4 @@ chooseBestEnc h hIsTerm (Just enc) = case textEncodingName enc of
| "//TRANSLIT" `isSuffixOf` name -> pure Keep | "//TRANSLIT" `isSuffixOf` name -> pure Keep
| otherwise -> hIsTerm h >>= \case | otherwise -> hIsTerm h >>= \case
False -> pure $ ChangeFromTo enc (textEncodingName utf8) False -> pure $ ChangeFromTo enc (textEncodingName utf8)
True -> pure $ ChangeFromTo enc (name ++ "//TRANSLIT") True -> pure $ ChangeFromTo enc (name ++ "//TRANSLIT")

View File

@ -37,7 +37,7 @@ ghc-options:
- -Wredundant-constraints - -Wredundant-constraints
dependencies: dependencies:
- base >= 4.10 && < 4.17 - base >= 4.10 && < 4.19
- text >= 0.7 && < 2.1 - text >= 0.7 && < 2.1
library: library:

View File

@ -3,8 +3,8 @@
- SPDX-License-Identifier: MPL-2.0 - SPDX-License-Identifier: MPL-2.0
-} -}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
module Test.Utf8.ReadWrite where module Test.Utf8.ReadWrite where
@ -18,7 +18,7 @@ import Data.Text (Text)
import GHC.IO.Encoding (utf8) import GHC.IO.Encoding (utf8)
import System.IO.Temp (withSystemTempFile) import System.IO.Temp (withSystemTempFile)
import Hedgehog (Property, (===), forAll, property) import Hedgehog (Property, forAll, property, (===))
import Test.HUnit (Assertion, assertFailure) import Test.HUnit (Assertion, assertFailure)
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
@ -59,7 +59,7 @@ hprop_readFile = property $ do
hprop_writeFile :: Property hprop_writeFile :: Property
hprop_writeFile = property $ do hprop_writeFile = property $ do
str <- forAll $ G.text (R.linear 0 1000) G.unicode str <- forAll $ G.text (R.linear 0 1000) G.unicode
liftIO $ withTestFile str (flip Utf8.writeFile str) liftIO $ withTestFile str (`Utf8.writeFile` str)
hprop_openFile :: Property hprop_openFile :: Property
hprop_openFile = property $ do hprop_openFile = property $ do
@ -78,6 +78,5 @@ hprop_withFile = property $ do
str' <- liftIO $ withTestFile str $ \fp -> str' <- liftIO $ withTestFile str $ \fp ->
Utf8.withFile fp IO.ReadMode $ \h -> do Utf8.withFile fp IO.ReadMode $ \h -> do
res <- T.hGetContents h res <- T.hGetContents h
res' <- evaluate . force $ res evaluate . force $ res
pure res'
str === str' str === str'

View File

@ -1,10 +1,10 @@
cabal-version: 1.18 cabal-version: 1.18
-- This file has been generated from package.yaml by hpack version 0.34.5. -- This file has been generated from package.yaml by hpack version 0.35.2.
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: 930f59e2f7815f238524f9e35825dd18c98fe04cfb768e3922af929bd6cf8c63 -- hash: 983535ba7f77c066ffa634f2a4f800eb8988a0e636f0f901fd187e177b64ca6f
name: with-utf8 name: with-utf8
version: 1.0.2.3 version: 1.0.2.3
@ -50,7 +50,7 @@ library
lib lib
ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints
build-depends: build-depends:
base >=4.10 && <4.17 base >=4.10 && <4.19
, safe-exceptions ==0.1.* , safe-exceptions ==0.1.*
, text >=0.7 && <2.1 , text >=0.7 && <2.1
default-language: Haskell2010 default-language: Haskell2010
@ -65,7 +65,7 @@ executable utf8-troubleshoot
c-sources: c-sources:
app/utf8-troubleshoot/cbits/locale.c app/utf8-troubleshoot/cbits/locale.c
build-depends: build-depends:
base >=4.10 && <4.17 base >=4.10 && <4.19
, directory >=1.2.5.0 && <1.4 , directory >=1.2.5.0 && <1.4
, filepath >=1.0 && <1.5 , filepath >=1.0 && <1.5
, process >=1.0.1.1 && <1.7 , process >=1.0.1.1 && <1.7
@ -91,7 +91,7 @@ test-suite with-utf8-test
tasty-discover:tasty-discover tasty-discover:tasty-discover
build-depends: build-depends:
HUnit HUnit
, base >=4.10 && <4.17 , base >=4.10 && <4.19
, deepseq , deepseq
, hedgehog , hedgehog
, safe-exceptions , safe-exceptions

2
with-utf8.cabal.license Normal file
View File

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
SPDX-License-Identifier: MPL-2.0