Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Various updates #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
packages: .

source-repository-package
type: git
location: https://github.com/amesgen/hs-rustls
tag: af95cd7d3f79913d2864f46931bbfe339f9c396d
--sha256: 0a2drcy9893r06ghh7cpj21lg2n8ma737x0mhqh0spsf3znsd4db
subdir: rustls http-client-rustls

constraints: rustls -derive-storable-plugin
106 changes: 106 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
inputs.flake-utils.follows = "flake-utils";
};
flake-utils.url = "github:numtide/flake-utils";
nix-rustls = {
url = "github:amesgen/hs-rustls?dir=nix-rustls";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { self, nixpkgs, flake-utils, haskellNix, nur, pre-commit-hooks }:
outputs = { self, nixpkgs, flake-utils, haskellNix, nur, pre-commit-hooks, nix-rustls }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
inherit (haskellNix) config;
overlays = [ haskellNix.overlay nur.overlay ];
overlays = [
haskellNix.overlay
nur.overlay
nix-rustls.overlays.default
];
};
inherit (pkgs) lib;
hsPkgs = pkgs.haskell-nix.cabalProject {
Expand Down Expand Up @@ -53,28 +62,23 @@
--hie-directory ${hellsmack.components.tests.tasty.hie}
'';
pre-commit-check =
let ormolu = pkgs.nur.repos.amesgen.ormolu; in
pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
ormolu = {
enable = true;
entry = lib.mkForce "${ormolu}/bin/ormolu -i";
};
ormolu.enable = true;
hlint.enable = true;
};
tools = {
inherit ormolu;
hlint = pkgs.nur.repos.amesgen.hlint;
inherit (pkgs.nur.repos.amesgen) ormolu hlint;
};
};
};
devShells.default = hsPkgs.shellFor {
tools = { cabal = { }; };
buildInputs = [ pkgs.nur.repos.amesgen.cabal-docspec ];
withHoogle = false;
exactDeps = true;
exactDeps = false;
inherit (self.checks.${system}.pre-commit-check) shellHook;
};

Expand Down
7 changes: 2 additions & 5 deletions hellsmack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ library
, temporary >= 1.3
, http-types >= 0.12
, http-client >= 0.7
, rustls >= 0.0
, http-client-rustls >= 0.0
, network-uri >= 2.6
, aeson >= 2.0
, deriving-aeson >= 0.2.7
Expand Down Expand Up @@ -68,11 +70,6 @@ library
, semigroups >= 0.19
, optparse-applicative >= 0.16
, th-env >= 0.1
if os(windows)
build-depends: http-client-tls >= 0.3
cpp-options: -DUSE_HASKELL_TLS
else
build-depends: http-client-openssl >= 0.3.3

exposed-modules:
Prelude
Expand Down
36 changes: 21 additions & 15 deletions src/HellSmack/Http.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{-# LANGUAGE CPP #-}
module HellSmack.Http (newTLSManager) where

module HellSmack.Http (newTLSManager, Manager) where
import Network.HTTP.Client qualified as HTTP
import Network.HTTP.Client.Rustls (rustlsManagerSettings)
import Rustls qualified
import UnliftIO.Exception

import Network.HTTP.Client
#if USE_HASKELL_TLS
import Network.HTTP.Client.TLS
#else
import Network.HTTP.Client.OpenSSL
#endif

newTLSManager :: MonadIO m => m Manager
#if USE_HASKELL_TLS
newTLSManager = newTlsManager
#else
newTLSManager = liftIO $ withOpenSSL newOpenSSLManager
#endif
newTLSManager :: MonadIO m => m HTTP.Manager
newTLSManager = liftIO do
roots <-
fmap (Rustls.ClientRootsInMemory . pure . Rustls.PEMCertificatesStrict) $
defaultCertFile `onException` envCertFile
clientConfig <- Rustls.buildClientConfig $ Rustls.defaultClientConfigBuilder roots
HTTP.newManager $ rustlsManagerSettings clientConfig
where
defaultCertFile = readFileBS "/etc/ssl/certs/ca-certificates.crt"
envCertFile =
lookupEnv envKey >>= \case
Just file | not (null file) -> readFileBS file
_ -> throwString [i|default SSL certs not found, please set $envKey|]
where
envKey :: String
envKey = "SSL_CERT_FILE"