From 20951c584a80239f3c8bbd0f6afb7ffce4669285 Mon Sep 17 00:00:00 2001 From: Bryan Richter Date: Fri, 31 Jan 2025 10:30:52 +0200 Subject: [PATCH] Add flake Care was taken to ensure Nix uses the same Haskell deps as Stack. --- flake.lock | 59 +++++++++++++++++++++++++++++ flake.nix | 14 +++++++ nix/amazonka-core.nix | 33 ++++++++++++++++ nix/crypton-connection.nix | 21 +++++++++++ nix/gen-packages.sh | 36 ++++++++++++++++++ nix/hoogle.nix | 35 +++++++++++++++++ nix/pantry.nix | 45 ++++++++++++++++++++++ nix/safe.nix | 12 ++++++ nix/stackage-server.nix | 77 ++++++++++++++++++++++++++++++++++++++ nix/tls.nix | 30 +++++++++++++++ package.nix | 33 ++++++++++++++++ 11 files changed, 395 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/amazonka-core.nix create mode 100644 nix/crypton-connection.nix create mode 100755 nix/gen-packages.sh create mode 100644 nix/hoogle.nix create mode 100644 nix/pantry.nix create mode 100644 nix/safe.nix create mode 100644 nix/stackage-server.nix create mode 100644 nix/tls.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..16d4c44 --- /dev/null +++ b/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1738136902, + "narHash": "sha256-pUvLijVGARw4u793APze3j6mU1Zwdtz7hGkGGkD87qw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9a5db3142ce450045840cc8d832b13b8a2018e0c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e68acd4 --- /dev/null +++ b/flake.nix @@ -0,0 +1,14 @@ +{ + description = "stackage-server"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem + (system: + let pkgs = nixpkgs.legacyPackages.${system}; in + { + defaultPackage = pkgs.callPackage ./package.nix {}; + } + ); +} diff --git a/nix/amazonka-core.nix b/nix/amazonka-core.nix new file mode 100644 index 0000000..aa62e68 --- /dev/null +++ b/nix/amazonka-core.nix @@ -0,0 +1,33 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, aeson, attoparsec, base, bytestring +, case-insensitive, conduit, conduit-extra, containers, crypton +, data-ordlist, deepseq, fetchzip, hashable, http-client +, http-conduit, http-types, lens, lib, memory, QuickCheck +, quickcheck-unicode, regex-posix, resourcet, scientific, tasty +, tasty-hunit, tasty-quickcheck, template-haskell, text, time +, transformers, unordered-containers, xml-conduit, xml-types +}: +mkDerivation { + pname = "amazonka-core"; + version = "2.0"; + src = fetchzip { + url = "https://github.com/brendanhay/amazonka/archive/85e0289f8dc23c54b00f7f1a09845be7e032a1eb.zip"; + sha256 = "1mgdz9b7wwc05xksczvzp2hllp7nzl4nr6as5q2fafkgxqzwwx53"; + }; + postUnpack = "sourceRoot+=/lib/amazonka-core; echo source root reset to $sourceRoot"; + libraryHaskellDepends = [ + aeson attoparsec base bytestring case-insensitive conduit + conduit-extra containers crypton deepseq hashable http-client + http-conduit http-types lens memory regex-posix resourcet + scientific text time transformers unordered-containers xml-conduit + xml-types + ]; + testHaskellDepends = [ + aeson base bytestring case-insensitive conduit data-ordlist + http-conduit http-types QuickCheck quickcheck-unicode tasty + tasty-hunit tasty-quickcheck template-haskell text time + ]; + homepage = "https://github.com/brendanhay/amazonka"; + description = "Core data types and functionality for Amazonka libraries"; + license = lib.licenses.mpl20; +} diff --git a/nix/crypton-connection.nix b/nix/crypton-connection.nix new file mode 100644 index 0000000..77957b9 --- /dev/null +++ b/nix/crypton-connection.nix @@ -0,0 +1,21 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, base, basement, bytestring, containers +, crypton-x509, crypton-x509-store, crypton-x509-system +, crypton-x509-validation, data-default-class, lib, network, socks +, tls +}: +mkDerivation { + pname = "crypton-connection"; + version = "0.3.2"; + sha256 = "208be23bc910f8e5f9431995b9c011ed376bb947d79f74c8f51a5e4ecd9e991e"; + revision = "1"; + editedCabalFile = "1rkana1ghppras20pgpwp2bc8dnsf8lspq90r6124jqd4ckbvx2b"; + libraryHaskellDepends = [ + base basement bytestring containers crypton-x509 crypton-x509-store + crypton-x509-system crypton-x509-validation data-default-class + network socks tls + ]; + homepage = "https://github.com/kazu-yamamoto/crypton-connection"; + description = "Simple and easy network connections API"; + license = lib.licenses.bsd3; +} diff --git a/nix/gen-packages.sh b/nix/gen-packages.sh new file mode 100755 index 0000000..3a77491 --- /dev/null +++ b/nix/gen-packages.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail + +filter=${1:-.} + +gen () { + f="$(mktemp)" + # shellcheck disable=SC2064 + trap "rm -f $f" EXIT + if grep -q "$filter" <<< "$1"; then + echo "Generating $1..." + echo "# Generated by $0" > "$f" + cabal2nix "$2" >> "$f" "${@:3}" + mv "$f" "${1}.nix" + else + echo "Skipping $1..." + fi +} + +cd "$(dirname "$0")" + +gen stackage-server --hpack ../. + +# Has my R2 patch, which is still unreleased on 2025-01-24 +#echo "...please ignore useless error below..." +2>/dev/null gen amazonka-core https://github.com/brendanhay/amazonka/archive/85e0289f8dc23c54b00f7f1a09845be7e032a1eb.zip --subpath lib/amazonka-core + +# Pinned to 5.0.18.4 to avoid accidentally regenerating hoogle files. See +# warning in stack.yaml! +gen hoogle cabal://hoogle-5.0.18.4 + +# FIXME: I don't remember why this had to be patched. +gen pantry https://github.com/commercialhaskell/pantry/archive/5df643cc1deb561d9c52a9cb6f593aba2bc4c08e.zip + +echo "Success!" diff --git a/nix/hoogle.nix b/nix/hoogle.nix new file mode 100644 index 0000000..4dc5de7 --- /dev/null +++ b/nix/hoogle.nix @@ -0,0 +1,35 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, aeson, base, binary, blaze-html, blaze-markup +, bytestring, cmdargs, conduit, conduit-extra, containers +, crypton-connection, deepseq, directory, extra, filepath +, foundation, hashable, haskell-src-exts, http-conduit, http-types +, js-flot, js-jquery, lib, mmap, old-locale, process-extras +, QuickCheck, resourcet, safe, storable-tuple, tar +, template-haskell, text, time, transformers, uniplate, utf8-string +, vector, wai, wai-logger, warp, warp-tls, zlib +}: +mkDerivation { + pname = "hoogle"; + version = "5.0.18.4"; + sha256 = "9d0f2de39821d14e8a436d5fda3523e789258b8041f02dd655f0e37d5013e323"; + revision = "1"; + editedCabalFile = "1129flhhb1992rijw46dclvmpqlylmbrzl4swsnk2knylx6jgw5a"; + isLibrary = true; + isExecutable = true; + enableSeparateDataOutput = true; + libraryHaskellDepends = [ + aeson base binary blaze-html blaze-markup bytestring cmdargs + conduit conduit-extra containers crypton-connection deepseq + directory extra filepath foundation hashable haskell-src-exts + http-conduit http-types js-flot js-jquery mmap old-locale + process-extras QuickCheck resourcet safe storable-tuple tar + template-haskell text time transformers uniplate utf8-string vector + wai wai-logger warp warp-tls zlib + ]; + executableHaskellDepends = [ base ]; + testTarget = "--test-option=--no-net"; + homepage = "https://hoogle.haskell.org/"; + description = "Haskell API Search"; + license = lib.licenses.bsd3; + mainProgram = "hoogle"; +} diff --git a/nix/pantry.nix b/nix/pantry.nix new file mode 100644 index 0000000..5c938c9 --- /dev/null +++ b/nix/pantry.nix @@ -0,0 +1,45 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, aeson, ansi-terminal, base, bytestring, Cabal +, casa-client, casa-types, conduit, conduit-extra, containers +, cryptonite, cryptonite-conduit, digest, exceptions, fetchzip +, filelock, generic-deriving, hackage-security, hedgehog, hpack +, hspec, http-client, http-client-tls, http-conduit, http-download +, http-types, lib, memory, mtl, network-uri, path, path-io +, persistent, persistent-sqlite, persistent-template, primitive +, QuickCheck, raw-strings-qq, resourcet, rio, rio-orphans +, rio-prettyprint, tar-conduit, text, text-metrics, time +, transformers, unix-compat, unliftio, unordered-containers, vector +, yaml, zip-archive +}: +mkDerivation { + pname = "pantry"; + version = "0.5.7"; + src = fetchzip { + url = "https://github.com/commercialhaskell/pantry/archive/5df643cc1deb561d9c52a9cb6f593aba2bc4c08e.zip"; + sha256 = "15m9ggg5jf30c1lxi0wgn76savrarwr2khzcd1rpnprdq3jnppzs"; + }; + libraryHaskellDepends = [ + aeson ansi-terminal base bytestring Cabal casa-client casa-types + conduit conduit-extra containers cryptonite cryptonite-conduit + digest filelock generic-deriving hackage-security hpack http-client + http-client-tls http-conduit http-download http-types memory mtl + network-uri path path-io persistent persistent-sqlite + persistent-template primitive resourcet rio rio-orphans + rio-prettyprint tar-conduit text text-metrics time transformers + unix-compat unliftio unordered-containers vector yaml zip-archive + ]; + testHaskellDepends = [ + aeson ansi-terminal base bytestring Cabal casa-client casa-types + conduit conduit-extra containers cryptonite cryptonite-conduit + digest exceptions filelock generic-deriving hackage-security + hedgehog hpack hspec http-client http-client-tls http-conduit + http-download http-types memory mtl network-uri path path-io + persistent persistent-sqlite persistent-template primitive + QuickCheck raw-strings-qq resourcet rio rio-orphans rio-prettyprint + tar-conduit text text-metrics time transformers unix-compat + unliftio unordered-containers vector yaml zip-archive + ]; + homepage = "https://github.com/commercialhaskell/pantry#readme"; + description = "Content addressable Haskell package management"; + license = lib.licenses.bsd3; +} diff --git a/nix/safe.nix b/nix/safe.nix new file mode 100644 index 0000000..8cbd86e --- /dev/null +++ b/nix/safe.nix @@ -0,0 +1,12 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, base, deepseq, lib, QuickCheck }: +mkDerivation { + pname = "safe"; + version = "0.3.20"; + sha256 = "ba9983610f9004a2ab67f5ddf11c9dff34f753b9fe11259f1ff77c2f3166df24"; + libraryHaskellDepends = [ base ]; + testHaskellDepends = [ base deepseq QuickCheck ]; + homepage = "https://github.com/ndmitchell/safe#readme"; + description = "Library of safe (exception free) functions"; + license = lib.licenses.bsd3; +} diff --git a/nix/stackage-server.nix b/nix/stackage-server.nix new file mode 100644 index 0000000..860f420 --- /dev/null +++ b/nix/stackage-server.nix @@ -0,0 +1,77 @@ +# Generated by ./gen-packages.sh +{ mkDerivation, aeson, amazonka, amazonka-core, amazonka-s3 +, auto-update, barrier, base, blaze-html, blaze-markup, bytestring +, Cabal, casa-client, classy-prelude, classy-prelude-conduit +, classy-prelude-yesod, cmark-gfm, conduit, conduit-extra +, containers, deepseq, directory, email-validate, esqueleto +, exceptions, fast-logger, file-embed, filepath, formatting, gauge +, ghc-prim, haddock-library, hashable, hoogle, hpack, html-conduit +, http-client, http-conduit, http-types, lens, lib, monad-logger +, mono-traversable, mtl, optparse-applicative, pantry, path +, path-io, path-pieces, persistent, persistent-postgresql +, persistent-sqlite, persistent-template, process, resource-pool +, resourcet, retry, rio, shakespeare, streaming-commons +, tar-conduit, template-haskell, text, these, transformers +, unliftio, unordered-containers, wai, wai-extra, wai-logger, warp +, xml-conduit, xml-types, yaml, yesod, yesod-auth, yesod-core +, yesod-form, yesod-gitrepo, yesod-gitrev, yesod-newsfeed +, yesod-sitemap, yesod-static, zlib +}: +mkDerivation { + pname = "stackage-server"; + version = "0.0.0"; + src = ../.; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson amazonka amazonka-core amazonka-s3 auto-update barrier base + blaze-html blaze-markup bytestring Cabal classy-prelude + classy-prelude-conduit classy-prelude-yesod cmark-gfm conduit + conduit-extra containers deepseq directory email-validate esqueleto + exceptions fast-logger file-embed filepath formatting ghc-prim + haddock-library hashable hoogle html-conduit http-client + http-conduit http-types lens monad-logger mono-traversable mtl + pantry path path-pieces persistent persistent-postgresql + persistent-sqlite persistent-template process resource-pool + resourcet retry rio shakespeare streaming-commons tar-conduit + template-haskell text these transformers unliftio + unordered-containers wai wai-extra wai-logger warp xml-conduit + xml-types yaml yesod yesod-auth yesod-core yesod-form yesod-gitrepo + yesod-gitrev yesod-newsfeed yesod-sitemap yesod-static zlib + ]; + libraryToolDepends = [ hpack ]; + executableHaskellDepends = [ + aeson amazonka amazonka-core amazonka-s3 auto-update barrier base + blaze-html blaze-markup bytestring Cabal classy-prelude + classy-prelude-conduit classy-prelude-yesod cmark-gfm conduit + conduit-extra containers deepseq directory email-validate esqueleto + exceptions fast-logger file-embed filepath formatting ghc-prim + haddock-library hashable hoogle html-conduit http-client + http-conduit http-types lens monad-logger mono-traversable mtl + optparse-applicative pantry path path-pieces persistent + persistent-postgresql persistent-sqlite persistent-template process + resource-pool resourcet retry rio shakespeare streaming-commons + tar-conduit template-haskell text these transformers unliftio + unordered-containers wai wai-extra wai-logger warp xml-conduit + xml-types yaml yesod yesod-auth yesod-core yesod-form yesod-gitrepo + yesod-gitrev yesod-newsfeed yesod-sitemap yesod-static zlib + ]; + benchmarkHaskellDepends = [ + aeson amazonka amazonka-core amazonka-s3 auto-update barrier base + blaze-html blaze-markup bytestring Cabal casa-client classy-prelude + classy-prelude-conduit classy-prelude-yesod cmark-gfm conduit + conduit-extra containers deepseq directory email-validate esqueleto + exceptions fast-logger file-embed filepath formatting gauge + ghc-prim haddock-library hashable hoogle html-conduit http-client + http-conduit http-types lens monad-logger mono-traversable mtl + pantry path path-io path-pieces persistent persistent-postgresql + persistent-sqlite persistent-template process resource-pool + resourcet retry rio shakespeare streaming-commons tar-conduit + template-haskell text these transformers unliftio + unordered-containers wai wai-extra wai-logger warp xml-conduit + xml-types yaml yesod yesod-auth yesod-core yesod-form yesod-gitrepo + yesod-gitrev yesod-newsfeed yesod-sitemap yesod-static zlib + ]; + prePatch = "hpack"; + license = lib.licenses.mit; +} diff --git a/nix/tls.nix b/nix/tls.nix new file mode 100644 index 0000000..eb0c12c --- /dev/null +++ b/nix/tls.nix @@ -0,0 +1,30 @@ +# Generated by ./gen-package-nix.sh +{ mkDerivation, asn1-encoding, asn1-types, async, base, bytestring +, cereal, crypton, crypton-x509, crypton-x509-store +, crypton-x509-validation, data-default-class, gauge, hourglass +, lib, memory, mtl, network, QuickCheck, tasty, tasty-quickcheck +, transformers, unix-time +}: +mkDerivation { + pname = "tls"; + version = "1.8.0"; + sha256 = "4a8486df3f1bd865753e7ac5f89bb252401fb91c8350226285e1075a78919808"; + libraryHaskellDepends = [ + asn1-encoding asn1-types async base bytestring cereal crypton + crypton-x509 crypton-x509-store crypton-x509-validation + data-default-class memory mtl network transformers unix-time + ]; + testHaskellDepends = [ + asn1-types async base bytestring crypton crypton-x509 + crypton-x509-validation data-default-class hourglass QuickCheck + tasty tasty-quickcheck + ]; + benchmarkHaskellDepends = [ + asn1-types async base bytestring crypton crypton-x509 + crypton-x509-validation data-default-class gauge hourglass + QuickCheck tasty-quickcheck + ]; + homepage = "https://github.com/haskell-tls/hs-tls"; + description = "TLS/SSL protocol native implementation (Server and Client)"; + license = lib.licenses.bsd3; +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..59abd19 --- /dev/null +++ b/package.nix @@ -0,0 +1,33 @@ +{ pkgs }: + +let + hlib = pkgs.haskell.lib; + hpkgs = pkgs.haskellPackages.override { + overrides = self: super: { + + stackage-server = hlib.overrideCabal (self.callPackage nix/stackage-server.nix { }) (old: { + preConfigure = '' + ${pkgs.hpack}/bin/hpack . + ''; + src = pkgs.lib.cleanSource old.src; + }); + + # patched, see gen-package-nix.sh + amazonka-core = self.callPackage nix/amazonka-core.nix { }; + + # We have this old dependency for unexplored reasons. + # Tests fail from attempted network access. + pantry = pkgs.lib.pipe (self.callPackage nix/pantry.nix { }) [hlib.dontCheck hlib.doJailbreak]; + + # Changing this has operational impacts. + hoogle = self.callPackage nix/hoogle.nix { }; + + # Outdated breakage? (TODO: upstream) + barrier = hlib.markUnbroken super.barrier; + + # Tests fail from attempted network access (TODO: upstream) + yesod-gitrev = hlib.markUnbroken (hlib.dontCheck super.yesod-gitrev); + }; + }; +in +hlib.justStaticExecutables hpkgs.stackage-server