From b6240f6527e6602b46731bfa2042425264f06593 Mon Sep 17 00:00:00 2001 From: Kirill Elizarov Date: Mon, 18 Oct 2021 17:42:30 +0700 Subject: [PATCH 1/3] Adds nix build support without the shell. --- .gitignore | 7 ++++++ default.nix | 38 +++++++++++++++++++++++++++++ haskell-starter-kit.nix | 53 +++++++++++++++++++++++++++++++++++++++++ nix/nixpkgs.json | 10 ++++++++ 4 files changed, 108 insertions(+) create mode 100644 default.nix create mode 100644 haskell-starter-kit.nix create mode 100644 nix/nixpkgs.json diff --git a/.gitignore b/.gitignore index 274184d..9e0fe80 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,13 @@ *~ haskell-starter-kit.cabal +# cabal specific +dist +dist-* + +# nix specific +result* + # Auth key keys/* !keys/.git-keep diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..86c477c --- /dev/null +++ b/default.nix @@ -0,0 +1,38 @@ +{ compiler ? "ghc8104" }: + +let + config = { + packageOverrides = pkgs: rec { + haskell = pkgs.haskell // { + packages = pkgs.haskell.packages // { + "${compiler}" = pkgs.haskell.packages."${compiler}".override { + overrides = haskellPackagesNew: haskellPackagesOld: rec { + + haskell-starter-kit = + pkgs.haskell.lib.dontCheck ( # Temporary solution + haskellPackagesNew.callPackage ./haskell-starter-kit.nix { } + ); + + }; + }; + }; + }; + }; + }; + + boostrap = import { }; + + nixpkgs = builtins.fromJSON (builtins.readFile ./nix/nixpkgs.json); + + src = boostrap.fetchFromGitHub { + owner = "NixOS"; + repo = "nixpkgs"; + inherit (nixpkgs) rev sha256; + }; + + pkgs = import src { inherit config; }; +in + { + haskell-starter-kit = pkgs.haskell.packages.${compiler}.haskell-starter-kit; + } + \ No newline at end of file diff --git a/haskell-starter-kit.nix b/haskell-starter-kit.nix new file mode 100644 index 0000000..401cb2f --- /dev/null +++ b/haskell-starter-kit.nix @@ -0,0 +1,53 @@ +{ mkDerivation, aeson, base, basement, bytestring, co-log +, configurator, containers, cryptonite, directory, esqueleto, hpack +, hspec, hspec-core, hspec-wai, http-client, http-client-tls +, http-types, jose, lib, memory, monad-logger, mtl, persistent +, persistent-postgresql, persistent-template, postgresql-simple +, random, resource-pool, resourcet, safe-exceptions, servant-auth +, servant-auth-server, servant-client, servant-foreign +, servant-options, servant-server, stm, tasty, tasty-hspec, text +, time, typerep-map, unliftio, unliftio-core, wai, wai-cors +, wai-extra, wai-logger, warp +}: +mkDerivation { + pname = "haskell-starter-kit"; + version = "0.1.0.0"; + src = ./.; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson base basement bytestring co-log configurator containers + cryptonite directory esqueleto http-client http-client-tls jose + memory monad-logger mtl persistent persistent-postgresql + persistent-template postgresql-simple random resource-pool + resourcet safe-exceptions servant-auth servant-auth-server + servant-client servant-foreign servant-options servant-server stm + text time typerep-map unliftio unliftio-core wai wai-cors + wai-logger warp + ]; + libraryToolDepends = [ hpack ]; + executableHaskellDepends = [ + aeson base basement bytestring co-log configurator containers + cryptonite directory esqueleto http-client http-client-tls jose + memory monad-logger mtl persistent persistent-postgresql + persistent-template postgresql-simple random resource-pool + resourcet safe-exceptions servant-auth servant-auth-server + servant-client servant-foreign servant-options servant-server stm + text time typerep-map unliftio unliftio-core wai wai-cors + wai-logger warp + ]; + testHaskellDepends = [ + aeson base basement bytestring co-log configurator containers + cryptonite directory esqueleto hspec hspec-core hspec-wai + http-client http-client-tls http-types jose memory monad-logger mtl + persistent persistent-postgresql persistent-template + postgresql-simple random resource-pool resourcet safe-exceptions + servant-auth servant-auth-server servant-client servant-foreign + servant-options servant-server stm tasty tasty-hspec text time + typerep-map unliftio unliftio-core wai wai-cors wai-extra + wai-logger warp + ]; + prePatch = "hpack"; + homepage = "https://github.com/fullstack-development/haskell-starter-kit#readme"; + license = lib.licenses.bsd3; +} diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json new file mode 100644 index 0000000..f0ed78b --- /dev/null +++ b/nix/nixpkgs.json @@ -0,0 +1,10 @@ +{ + "url": "https://github.com/NixOS/nixpkgs.git", + "rev": "efee454783c5c14ae78687439077c1d3f0544d97", + "date": "2021-05-22T09:16:50+02:00", + "path": "/nix/store/gpibzvspwz5k6514azylvfq759jvdwk8-nixpkgs-efee454", + "sha256": "1qk4g8rav2mkbd6y2zr1pi3pxs4rwlkpr8xk51m0p26khprxvjaf", + "fetchSubmodules": false, + "deepClone": false, + "leaveDotGit": false +} From 28283953c98b296f9ef50998b8efa80e61a36a2a Mon Sep 17 00:00:00 2001 From: Kirill Elizarov Date: Wed, 20 Oct 2021 17:18:30 +0700 Subject: [PATCH 2/3] Use IOHK haskell.nix to define nix env --- .gitignore | 1 - default.nix | 49 ++------ haskell-starter-kit.cabal | 249 ++++++++++++++++++++++++++++++++++++++ haskell-starter-kit.nix | 53 -------- nix/nixpkgs.json | 10 -- nix/sources.json | 38 ++++++ nix/sources.nix | 174 ++++++++++++++++++++++++++ package.yaml | 132 -------------------- shell.nix | 14 +++ stack.yaml | 70 ----------- stack.yaml.lock | 33 ----- 11 files changed, 487 insertions(+), 336 deletions(-) create mode 100644 haskell-starter-kit.cabal delete mode 100644 haskell-starter-kit.nix delete mode 100644 nix/nixpkgs.json create mode 100644 nix/sources.json create mode 100644 nix/sources.nix delete mode 100644 package.yaml create mode 100644 shell.nix delete mode 100644 stack.yaml delete mode 100644 stack.yaml.lock diff --git a/.gitignore b/.gitignore index 9e0fe80..f0371bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ # needed for stack .stack-work/ *~ -haskell-starter-kit.cabal # cabal specific dist diff --git a/default.nix b/default.nix index 86c477c..3ed5ee9 100644 --- a/default.nix +++ b/default.nix @@ -1,38 +1,13 @@ -{ compiler ? "ghc8104" }: - -let - config = { - packageOverrides = pkgs: rec { - haskell = pkgs.haskell // { - packages = pkgs.haskell.packages // { - "${compiler}" = pkgs.haskell.packages."${compiler}".override { - overrides = haskellPackagesNew: haskellPackagesOld: rec { - - haskell-starter-kit = - pkgs.haskell.lib.dontCheck ( # Temporary solution - haskellPackagesNew.callPackage ./haskell-starter-kit.nix { } - ); - - }; - }; - }; - }; - }; +let + sources = import ./nix/sources.nix {}; + haskellNix = import sources.haskellNix {}; + pkgs = import + haskellNix.sources.nixpkgs-2105 + haskellNix.nixpkgsArgs; +in pkgs.haskell-nix.project { + src = pkgs.haskell-nix.haskellLib.cleanGit { + name = "haskell-starter-kit"; + src = ./.; }; - - boostrap = import { }; - - nixpkgs = builtins.fromJSON (builtins.readFile ./nix/nixpkgs.json); - - src = boostrap.fetchFromGitHub { - owner = "NixOS"; - repo = "nixpkgs"; - inherit (nixpkgs) rev sha256; - }; - - pkgs = import src { inherit config; }; -in - { - haskell-starter-kit = pkgs.haskell.packages.${compiler}.haskell-starter-kit; - } - \ No newline at end of file + compiler-nix-name = "ghc8107"; +} \ No newline at end of file diff --git a/haskell-starter-kit.cabal b/haskell-starter-kit.cabal new file mode 100644 index 0000000..f748c92 --- /dev/null +++ b/haskell-starter-kit.cabal @@ -0,0 +1,249 @@ +cabal-version: 1.12 +name: haskell-starter-kit +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/fullstack-development/haskell-starter-kit#readme +bug-reports: https://github.com/fullstack-development/haskell-starter-kit/issues +author: Author name here +maintainer: example@example.com +copyright: 2021 Author name here +license: BSD-3-Clause +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/fullstack-development/haskell-starter-kit + +common lang + default-language: Haskell2010 + default-extensions: + RecordWildCards + NamedFieldPuns + OverloadedStrings + FlexibleContexts + FlexibleInstances + StandaloneDeriving + ScopedTypeVariables + ExplicitForAll + TypeOperators + DeriveGeneric + MonoLocalBinds + LambdaCase + DeriveFoldable + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + ExplicitForAll + GeneralizedNewtypeDeriving + + ghc-options: + -Wall -Wnoncanonical-monad-instances -Wincomplete-uni-patterns + -Wincomplete-record-updates -Wredundant-constraints -Widentities + -fobject-code -fno-ignore-interface-pragmas + -fno-omit-interface-pragmas + +library + exposed-modules: + AppName.API + AppName.API.PhoneVerification + AppName.API.User + AppName.AppHandle + AppName.Auth + AppName.Auth.Combinators + AppName.Auth.Commands + AppName.Auth.ServantInstances + AppName.Auth.User + AppName.Config + AppName.Domain.PhoneVerification + AppName.Gateways.CryptoRandomGen + AppName.Gateways.Database + AppName.Gateways.Database.Connection + AppName.Gateways.Database.Setup + AppName.Gateways.Database.Tables.User + AppName.Gateways.Endpoints.FakeLogin + AppName.Gateways.Endpoints.GetUsers + AppName.Gateways.Endpoints.PhoneVerification + AppName.Gateways.Endpoints.SaveUsers + AppName.Gateways.PhoneVerificationStorage + AppName.Server + Ext.Data.Aeson + Ext.Data.Text + Ext.Data.Time + Ext.HTTP.Error + Ext.HTTP.Response + Ext.Logger + Ext.Logger.Colog + Ext.Logger.Config + Lib + other-modules: + Paths_haskell_starter_kit + ghc-options: + -Wunused-packages + hs-source-dirs: + src + default-extensions: + ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns + build-depends: + aeson + , base >=4.7 && <5 + , basement + , bytestring + , co-log + , containers + , configurator + , cryptonite + , dhall + , directory + , esqueleto + , http-client + , http-client-tls + , jose + , memory + , monad-logger + , mtl + , persistent + , persistent-postgresql + , persistent-template + , postgresql-simple + , random + , resource-pool + , resourcet + , safe-exceptions + , servant-auth + , servant-auth-server + , servant-client + , servant-foreign + , servant-options + , servant-server + , stm + , text + , time + , typerep-map + , unliftio + , unliftio-core + , wai + , wai-cors + , wai-logger + , warp + default-language: Haskell2010 + +executable haskell-starter-kit-exe + main-is: Main.hs + hs-source-dirs: + app + default-extensions: RecordWildCards NamedFieldPuns OverloadedStrings FlexibleContexts FlexibleInstances StandaloneDeriving ScopedTypeVariables ExplicitForAll TypeOperators DeriveGeneric MonoLocalBinds LambdaCase + ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns -threaded -rtsopts -with-rtsopts=-N + build-depends: + aeson + , base >=4.7 && <5 + , basement + , bytestring + , co-log + , containers + , cryptonite + , dhall + , directory + , esqueleto + , haskell-starter-kit + , http-client + , http-client-tls + , jose + , memory + , monad-logger + , mtl + , persistent + , persistent-postgresql + , persistent-template + , postgresql-simple + , random + , resource-pool + , resourcet + , safe-exceptions + , servant-auth + , servant-auth-server + , servant-client + , servant-foreign + , servant-options + , servant-server + , stm + , text + , time + , typerep-map + , unliftio + , unliftio-core + , wai + , wai-cors + , wai-logger + , warp + if false + other-modules: + Paths_haskell_starter_kit + default-language: Haskell2010 + +test-suite haskell-starter-kit-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + PhoneVerification + hs-source-dirs: + test + default-extensions: RecordWildCards NamedFieldPuns OverloadedStrings FlexibleContexts FlexibleInstances StandaloneDeriving ScopedTypeVariables ExplicitForAll TypeOperators DeriveGeneric MonoLocalBinds LambdaCase + ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns -threaded -rtsopts -with-rtsopts=-N + build-depends: + aeson + , base >=4.7 && <5 + , basement + , bytestring + , co-log + , containers + , cryptonite + , dhall + , directory + , esqueleto + , haskell-starter-kit + , hspec + , hspec-core + , hspec-wai + , http-client + , http-client-tls + , http-types + , jose + , memory + , monad-logger + , mtl + , persistent + , persistent-postgresql + , persistent-template + , postgresql-simple + , random + , resource-pool + , resourcet + , safe-exceptions + , servant-auth + , servant-auth-server + , servant-client + , servant-foreign + , servant-options + , servant-server + , stm + , tasty + , tasty-hspec + , text + , time + , typerep-map + , unliftio + , unliftio-core + , wai + , wai-cors + , wai-extra + , wai-logger + , warp + if false + other-modules: + Paths_haskell_starter_kit + default-language: Haskell2010 diff --git a/haskell-starter-kit.nix b/haskell-starter-kit.nix deleted file mode 100644 index 401cb2f..0000000 --- a/haskell-starter-kit.nix +++ /dev/null @@ -1,53 +0,0 @@ -{ mkDerivation, aeson, base, basement, bytestring, co-log -, configurator, containers, cryptonite, directory, esqueleto, hpack -, hspec, hspec-core, hspec-wai, http-client, http-client-tls -, http-types, jose, lib, memory, monad-logger, mtl, persistent -, persistent-postgresql, persistent-template, postgresql-simple -, random, resource-pool, resourcet, safe-exceptions, servant-auth -, servant-auth-server, servant-client, servant-foreign -, servant-options, servant-server, stm, tasty, tasty-hspec, text -, time, typerep-map, unliftio, unliftio-core, wai, wai-cors -, wai-extra, wai-logger, warp -}: -mkDerivation { - pname = "haskell-starter-kit"; - version = "0.1.0.0"; - src = ./.; - isLibrary = true; - isExecutable = true; - libraryHaskellDepends = [ - aeson base basement bytestring co-log configurator containers - cryptonite directory esqueleto http-client http-client-tls jose - memory monad-logger mtl persistent persistent-postgresql - persistent-template postgresql-simple random resource-pool - resourcet safe-exceptions servant-auth servant-auth-server - servant-client servant-foreign servant-options servant-server stm - text time typerep-map unliftio unliftio-core wai wai-cors - wai-logger warp - ]; - libraryToolDepends = [ hpack ]; - executableHaskellDepends = [ - aeson base basement bytestring co-log configurator containers - cryptonite directory esqueleto http-client http-client-tls jose - memory monad-logger mtl persistent persistent-postgresql - persistent-template postgresql-simple random resource-pool - resourcet safe-exceptions servant-auth servant-auth-server - servant-client servant-foreign servant-options servant-server stm - text time typerep-map unliftio unliftio-core wai wai-cors - wai-logger warp - ]; - testHaskellDepends = [ - aeson base basement bytestring co-log configurator containers - cryptonite directory esqueleto hspec hspec-core hspec-wai - http-client http-client-tls http-types jose memory monad-logger mtl - persistent persistent-postgresql persistent-template - postgresql-simple random resource-pool resourcet safe-exceptions - servant-auth servant-auth-server servant-client servant-foreign - servant-options servant-server stm tasty tasty-hspec text time - typerep-map unliftio unliftio-core wai wai-cors wai-extra - wai-logger warp - ]; - prePatch = "hpack"; - homepage = "https://github.com/fullstack-development/haskell-starter-kit#readme"; - license = lib.licenses.bsd3; -} diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json deleted file mode 100644 index f0ed78b..0000000 --- a/nix/nixpkgs.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "url": "https://github.com/NixOS/nixpkgs.git", - "rev": "efee454783c5c14ae78687439077c1d3f0544d97", - "date": "2021-05-22T09:16:50+02:00", - "path": "/nix/store/gpibzvspwz5k6514azylvfq759jvdwk8-nixpkgs-efee454", - "sha256": "1qk4g8rav2mkbd6y2zr1pi3pxs4rwlkpr8xk51m0p26khprxvjaf", - "fetchSubmodules": false, - "deepClone": false, - "leaveDotGit": false -} diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..132349a --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,38 @@ +{ + "haskellNix": { + "branch": "master", + "description": "Alternative Haskell Infrastructure for Nixpkgs", + "homepage": "https://input-output-hk.github.io/haskell.nix", + "owner": "input-output-hk", + "repo": "haskell.nix", + "rev": "8cac12db77edfde52377a6a29813e007f11d38e3", + "sha256": "18zmis0n2q578gylyl8383fzackwppng5xwdnrsmr49kf6kby0vx", + "type": "tarball", + "url": "https://github.com/input-output-hk/haskell.nix/archive/8cac12db77edfde52377a6a29813e007f11d38e3.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "65a61b147f307d24bfd0a5cd56ce7d7b7cc61d2e", + "sha256": "17mirpsx5wyw262fpsd6n6m47jcgw8k2bwcp1iwdnrlzy4dhcgqh", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/65a61b147f307d24bfd0a5cd56ce7d7b7cc61d2e.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "release-20.03", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eb73405ecceb1dc505b7cbbd234f8f94165e2696", + "sha256": "06k21wbyhhvq2f1xczszh3c2934p0m02by3l2ixvd6nkwrqklax7", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb73405ecceb1dc505b7cbbd234f8f94165e2696.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..1938409 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,174 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + if spec ? ref then spec.ref else + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + in + builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else {}; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/package.yaml b/package.yaml deleted file mode 100644 index 5368236..0000000 --- a/package.yaml +++ /dev/null @@ -1,132 +0,0 @@ -name: haskell-starter-kit -version: 0.1.0.0 -github: "fullstack-development/haskell-starter-kit" -license: BSD3 -author: "Author name here" -maintainer: "example@example.com" -copyright: "2021 Author name here" - -extra-source-files: -- README.md -- ChangeLog.md - -# Metadata used when publishing your package -# synopsis: Short description of your package -# category: Web - -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. -description: Please see the README on GitHub at - -dependencies: -- base >= 4.7 && < 5 -- mtl -- bytestring -- text -- containers -- time -- unliftio-core -- unliftio -- safe-exceptions -- typerep-map -- random -- stm -- directory -- cryptonite -- memory -- basement - -- configurator -- resourcet -- resource-pool - -# Logger -- co-log -- monad-logger - -# Database -- postgresql-simple -- persistent -- persistent-postgresql -- persistent-template -- esqueleto - -# Web -- aeson -- jose -- http-client -- http-client-tls -- wai -- warp -- wai-logger -- wai-cors -- servant-client -- servant-options -- servant-server -- servant-auth -- servant-auth-server -- servant-foreign - -ghc-options: -- -Wall -- -Werror=missing-fields -- -Werror=incomplete-record-updates -- -Werror=missing-methods -- -Werror=incomplete-patterns - -default-extensions: -- RecordWildCards -- NamedFieldPuns -- OverloadedStrings -- FlexibleContexts -- FlexibleInstances -- StandaloneDeriving -- ScopedTypeVariables -- ExplicitForAll -- TypeOperators -- DeriveGeneric -- MonoLocalBinds -- LambdaCase - -library: - source-dirs: src - - -executables: - haskell-starter-kit-exe: - main: Main.hs - source-dirs: app - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - haskell-starter-kit - when: # workaround from https://github.com/sol/hpack/issues/303 - - condition: false - other-modules: Paths_haskell_starter_kit - -tests: - haskell-starter-kit-test: - main: Spec.hs - source-dirs: test - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - haskell-starter-kit - - - hspec - - hspec-core - - hspec-wai - - tasty - - tasty-hspec - - # extra - - http-types - - wai-extra - when: # workaround from https://github.com/sol/hpack/issues/303 - - condition: false - other-modules: Paths_haskell_starter_kit diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..4208e76 --- /dev/null +++ b/shell.nix @@ -0,0 +1,14 @@ +let + project = import ./default.nix; +in +project.shellFor { + withHoogle = true; + tools = { + cabal = "3.2.0.0"; + hlint = "latest"; + haskell-language-server = "latest"; + }; + + buildInputs = [(import {}).git]; + exactDeps = true; +} \ No newline at end of file diff --git a/stack.yaml b/stack.yaml deleted file mode 100644 index 27c28f7..0000000 --- a/stack.yaml +++ /dev/null @@ -1,70 +0,0 @@ -# This file was automatically generated by 'stack init' -# -# Some commonly used options have been documented as comments in this file. -# For advanced use and comprehensive documentation of the format, please see: -# https://docs.haskellstack.org/en/stable/yaml_configuration/ - -# Resolver to choose a 'specific' stackage snapshot or a compiler version. -# A snapshot resolver dictates the compiler version and the set of packages -# to be used for project dependencies. For example: -# -# resolver: lts-3.5 -# resolver: nightly-2015-09-21 -# resolver: ghc-7.10.2 -# -# The location of a snapshot can be provided as a file or url. Stack assumes -# a snapshot provided as a file might change, whereas a url resource does not. -# -# resolver: ./custom-snapshot.yaml -# resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-17.5 - -# User packages to be built. -# Various formats can be used as shown in the example below. -# -# packages: -# - some-directory -# - https://example.com/foo/bar/baz-0.0.2.tar.gz -# subdirs: -# - auto-update -# - wai -packages: -- . -# Dependency packages to be pulled from upstream that are not in the resolver. -# These entries can reference officially published versions as well as -# forks / in-progress versions pinned to a git hash. For example: -# -# - acme-missiles-0.3 -# - git: https://github.com/commercialhaskell/stack.git -# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a -extra-deps: - - servant-options-0.1.0.0 - - servant-auth-0.4.0.0 - - servant-auth-server-0.4.6.0 - -# -# extra-deps: [] - -# Override default flag values for local packages and extra-deps -# flags: {} - -# Extra package databases containing global packages -# extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true -# -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: ">=2.5" -# -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 -# -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] -# -# Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor diff --git a/stack.yaml.lock b/stack.yaml.lock deleted file mode 100644 index 92040a6..0000000 --- a/stack.yaml.lock +++ /dev/null @@ -1,33 +0,0 @@ -# This file was autogenerated by Stack. -# You should not edit this file by hand. -# For more information, please see the documentation at: -# https://docs.haskellstack.org/en/stable/lock_files - -packages: -- completed: - hackage: servant-options-0.1.0.0@sha256:39f50166a68006250e79370372f553ca476f14d06d93fa0c401050253aeba803,914 - pantry-tree: - size: 293 - sha256: 7812baf1b27c62068ba634207fbd7077b886424d666b36739a78c6d4008a1fd4 - original: - hackage: servant-options-0.1.0.0 -- completed: - hackage: servant-auth-0.4.0.0@sha256:01d02dfb7df4747fc96442517146d7d4ab0e575e597a124e238e8763036ea4ff,2125 - pantry-tree: - size: 332 - sha256: a7ec2c54fddfa417ee2467f1131b1d83ad43cc29ddfd4b98869fc924e4b5e980 - original: - hackage: servant-auth-0.4.0.0 -- completed: - hackage: servant-auth-server-0.4.6.0@sha256:b411b44f4252e91e5da2455d71a7113c8b5b8ff2d943d19b2ddedcfcf0392351,5111 - pantry-tree: - size: 1376 - sha256: 8cd29612112546a02085e2cb30dd5a72ea46ed81e644195c589d0b26652279cb - original: - hackage: servant-auth-server-0.4.6.0 -snapshots: -- completed: - size: 565266 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/5.yaml - sha256: 78e8ebabf11406261abbc95b44f240acf71802630b368888f6d758de7fc3a2f7 - original: lts-17.5 From fc2fb0f3b0d684ae83dd43e0aeae74e25c4135ed Mon Sep 17 00:00:00 2001 From: Kirill Elizarov Date: Thu, 21 Oct 2021 13:35:52 +0700 Subject: [PATCH 3/3] Fixed cabal configs to work with nix environment. --- .gitignore | 1 + haskell-starter-kit.cabal | 63 ++++++++++++-------------- src/AppName/Auth/ServantInstances.hs | 4 ++ src/AppName/Gateways/Database/Setup.hs | 5 +- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index f0371bf..80da994 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # system .DS_Store +.vscode # needed for stack .stack-work/ diff --git a/haskell-starter-kit.cabal b/haskell-starter-kit.cabal index f748c92..c379fc2 100644 --- a/haskell-starter-kit.cabal +++ b/haskell-starter-kit.cabal @@ -1,4 +1,4 @@ -cabal-version: 1.12 +cabal-version: 2.2 name: haskell-starter-kit version: 0.1.0.0 description: Please see the README on GitHub at @@ -20,34 +20,35 @@ source-repository head common lang default-language: Haskell2010 - default-extensions: - RecordWildCards - NamedFieldPuns - OverloadedStrings - FlexibleContexts - FlexibleInstances - StandaloneDeriving - ScopedTypeVariables - ExplicitForAll - TypeOperators - DeriveGeneric - MonoLocalBinds - LambdaCase - DeriveFoldable - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - ExplicitForAll - GeneralizedNewtypeDeriving + default-extensions: + RecordWildCards + NamedFieldPuns + OverloadedStrings + FlexibleContexts + FlexibleInstances + StandaloneDeriving + ScopedTypeVariables + ExplicitForAll + TypeOperators + DeriveGeneric + MonoLocalBinds + LambdaCase + DeriveFoldable + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + ExplicitForAll + GeneralizedNewtypeDeriving - ghc-options: - -Wall -Wnoncanonical-monad-instances -Wincomplete-uni-patterns - -Wincomplete-record-updates -Wredundant-constraints -Widentities - -fobject-code -fno-ignore-interface-pragmas - -fno-omit-interface-pragmas + ghc-options: + -Wall -Wnoncanonical-monad-instances -Wincomplete-uni-patterns + -Wincomplete-record-updates -Wredundant-constraints -Widentities + -fobject-code -fno-ignore-interface-pragmas + -fno-omit-interface-pragmas library + import: lang exposed-modules: AppName.API AppName.API.PhoneVerification @@ -82,12 +83,8 @@ library Lib other-modules: Paths_haskell_starter_kit - ghc-options: - -Wunused-packages hs-source-dirs: src - default-extensions: - ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns build-depends: aeson , base >=4.7 && <5 @@ -134,10 +131,9 @@ library executable haskell-starter-kit-exe main-is: Main.hs + import: lang hs-source-dirs: app - default-extensions: RecordWildCards NamedFieldPuns OverloadedStrings FlexibleContexts FlexibleInstances StandaloneDeriving ScopedTypeVariables ExplicitForAll TypeOperators DeriveGeneric MonoLocalBinds LambdaCase - ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns -threaded -rtsopts -with-rtsopts=-N build-depends: aeson , base >=4.7 && <5 @@ -187,13 +183,12 @@ executable haskell-starter-kit-exe test-suite haskell-starter-kit-test type: exitcode-stdio-1.0 + import: lang main-is: Spec.hs other-modules: PhoneVerification hs-source-dirs: test - default-extensions: RecordWildCards NamedFieldPuns OverloadedStrings FlexibleContexts FlexibleInstances StandaloneDeriving ScopedTypeVariables ExplicitForAll TypeOperators DeriveGeneric MonoLocalBinds LambdaCase - ghc-options: -Wall -Werror=missing-fields -Werror=incomplete-record-updates -Werror=missing-methods -Werror=incomplete-patterns -threaded -rtsopts -with-rtsopts=-N build-depends: aeson , base >=4.7 && <5 diff --git a/src/AppName/Auth/ServantInstances.hs b/src/AppName/Auth/ServantInstances.hs index df90238..e507c6c 100644 --- a/src/AppName/Auth/ServantInstances.hs +++ b/src/AppName/Auth/ServantInstances.hs @@ -1,6 +1,10 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE FlexibleContexts #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module AppName.Auth.ServantInstances where diff --git a/src/AppName/Gateways/Database/Setup.hs b/src/AppName/Gateways/Database/Setup.hs index 7294fa1..172e738 100644 --- a/src/AppName/Gateways/Database/Setup.hs +++ b/src/AppName/Gateways/Database/Setup.hs @@ -16,7 +16,8 @@ import Control.Monad.Logger NoLoggingT, runNoLoggingT, runStdoutLoggingT, - ) + MonadLoggerIO + )˝ import Data.Functor (($>)) import Data.Pool (Pool, destroyAllResources) import Database.Persist.Postgresql (SqlBackend, createPostgresqlPoolModified) @@ -29,7 +30,7 @@ withDbPool :: C.Config -> (Pool SqlBackend -> NoLoggingT IO a) -> IO a withDbPool = withLoggedDbPool runNoLoggingT withLoggedDbPool :: - (MonadUnliftIO m, MonadLogger m, MonadMask m) => + (MonadUnliftIO m, MonadMask m, MonadLoggerIO m) => (m a -> IO a) -> C.Config -> (Pool SqlBackend -> m a) ->