From be86429c4b806fe20069e8efbf921c20b9e17ee3 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Thu, 3 Oct 2024 14:16:05 +0400 Subject: [PATCH] Initial static builds for HBS2 Use `nix build .#static` to start building --- flake.lock | 29 +- flake.nix | 250 ++++++++++-------- .../HBS2/Git/Web/Html/Fixme.hs | 7 +- .../HBS2/Git/Web/Html/Issue.hs | 7 +- 4 files changed, 173 insertions(+), 120 deletions(-) diff --git a/flake.lock b/flake.lock index e324acc9..1a85dd8e 100644 --- a/flake.lock +++ b/flake.lock @@ -85,12 +85,15 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -154,7 +157,9 @@ }, "haskell-flake-utils": { "inputs": { - "flake-utils": "flake-utils" + "flake-utils": [ + "flake-utils" + ] }, "locked": { "lastModified": 1707809372, @@ -291,6 +296,7 @@ "inputs": { "bytestring-mmap": "bytestring-mmap", "db-pipe": "db-pipe", + "flake-utils": "flake-utils", "fuzzy": "fuzzy", "haskell-flake-utils": "haskell-flake-utils", "hspup": "hspup", @@ -365,6 +371,21 @@ "type": "git", "url": "https://git.hbs2.net/JAuk1UJzZfbDGKVazSQU5yYQ3NGfk4gVeZzBCduf5TgQ" } + }, + "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", diff --git a/flake.nix b/flake.nix index f2255341..40cd1bba 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,11 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; # haskell-flake-utils.url = "github:ivanovs-4/haskell-flake-utils"; - haskell-flake-utils.url = "github:ivanovs-4/haskell-flake-utils/master"; + flake-utils.url = "github:numtide/flake-utils"; + haskell-flake-utils = { # we don't use haskell-flake-utils directly, but we override input evrywhere + url = "github:ivanovs-4/haskell-flake-utils/master"; + inputs.flake-utils.follows = "flake-utils"; + }; hspup.url = "github:voidlizard/hspup"; hspup.inputs.nixpkgs.follows = "nixpkgs"; hspup.inputs.haskell-flake-utils.follows = "haskell-flake-utils"; @@ -41,124 +45,146 @@ inputs = { }; -outputs = { self, nixpkgs, haskell-flake-utils, ... }@inputs: - let - packageNames = [ - "hbs2" - "hbs2-peer" - "hbs2-core" - "hbs2-storage-simple" - "hbs2-git" - "hbs2-git-dashboard" - "hbs2-qblf" - "hbs2-keyman" - "hbs2-keyman-direct-lib" - "hbs2-fixer" - "hbs2-cli" - "hbs2-sync" - "fixme-new" - ]; - in - haskell-flake-utils.lib.simpleCabalProject2flake { - inherit self nixpkgs; - systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - name = "hbs2"; - - haskellFlakes = with inputs; [ - suckless-conf - db-pipe - ]; - - inherit packageNames; - - packageDirs = { - "hbs2" = "./hbs2"; - "hbs2-tests" = "./hbs2-tests"; - "hbs2-core" = "./hbs2-core"; - "hbs2-storage-simple" = "./hbs2-storage-simple"; - "hbs2-peer" = "./hbs2-peer"; - "hbs2-keyman" = "./hbs2-keyman/hbs2-keyman"; - "hbs2-keyman-direct-lib" = "./hbs2-keyman/hbs2-keyman-direct-lib"; - "hbs2-git" = "./hbs2-git"; - "hbs2-git-dashboard" = "./hbs2-git-dashboard"; - "hbs2-fixer" = "./hbs2-fixer"; - "hbs2-cli" = "./hbs2-cli"; - "hbs2-sync" = "./hbs2-sync"; - "fixme-new" = "./fixme-new"; - }; - - hpPreOverrides = {pkgs, ...}: final: prev: ((with pkgs; { - saltine = prev.callCabal2nix "saltine" inputs.saltine { inherit (pkgs) libsodium; }; - scotty = final.callHackage "scotty" "0.21" { }; - bytestring-mmap = prev.callCabal2nix "bytestring-mmap" inputs.bytestring-mmap {}; - skylighting-lucid = final.callHackage "skylighting-lucid" "1.0.4" { }; - # wai-app-file-cgi = final.callHackage "wai-app-file-cgi" "3.1.11" { }; - # htags = final.callHackage "htags" "1.0.1" { }; - }) // - (with haskell-flake-utils.lib; - with pkgs.haskell.lib; +outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"] + (system: let - donts = [ - (jailbreakUnbreak pkgs) - # dontBenchmark + packageNames = + topLevelPackages ++ keymanPackages; + + keymanPackages = + [ + "hbs2-keyman" + "hbs2-keyman-direct-lib" + ]; + + topLevelPackages = + [ + "hbs2" + "hbs2-peer" + "hbs2-core" + "hbs2-storage-simple" + "hbs2-git" + "hbs2-git-dashboard" + "hbs2-qblf" + "hbs2-fixer" + "hbs2-cli" + "hbs2-sync" + "fixme-new" + ]; + + pkgs = import nixpkgs { + inherit system; + overlays = [defaultOverlay]; + }; + + defaultOverlay = final: prev: + (prev.lib.composeManyExtensions + [ + overlay + inputs.suckless-conf.overlays.default + inputs.db-pipe.overlays.default + ]) final prev; + + packagePostOverrides = pkg: with pkgs.haskell.lib.compose; pkgs.lib.pipe pkg [ + disableExecutableProfiling + disableLibraryProfiling + dontBenchmark dontCoverage + dontDistribute + dontHaddock + dontHyperlinkSource + doStrip + enableDeadCodeElimination + justStaticExecutables + dontCheck + + (overrideCabal (drv: { + preBuild = '' + export GIT_HASH="${self.rev or self.dirtyRev or "dirty"}" + ''; + })) ]; - in tunePackages pkgs prev { - wai-app-file-cgi = donts; - } - )); - packagePostOverrides = { pkgs }: with pkgs; with haskell.lib; [ - disableExecutableProfiling - disableLibraryProfiling - dontBenchmark - dontCoverage - dontDistribute - dontHaddock - dontHyperlinkSource - doStrip - enableDeadCodeElimination - justStaticExecutables - dontCheck - - (compose.overrideCabal (drv: { - preBuild = '' - export GIT_HASH="${self.rev or self.dirtyRev or "dirty"}" - ''; - })) - - ]; - - shell = {pkgs, ...}: - pkgs.haskellPackages.shellFor { - packages = _: pkgs.lib.attrsets.attrVals packageNames pkgs.haskellPackages; - # withHoogle = true; - buildInputs = ( - with pkgs.haskellPackages; ([ - ghcid - cabal-install - haskell-language-server - hoogle - # htags - text-icu - magic - pkgs.icu72 - pkgs.openssl - weeder - ]) - ++ - [ pkgs.pkg-config - inputs.hspup.packages.${pkgs.system}.default - ] - ); - - shellHook = '' - export GIT_HASH="${self.rev or self.dirtyRev or "dirty"}" - ''; + jailbreakUnbreak = pkg: + pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); + overlay = final: prev: let pkgs = prev; in + { + haskellPackages = pkgs.haskellPackages.override { + overrides = new: old: with pkgs.haskell.lib; + { + scotty = new.callHackage "scotty" "0.21" { }; + bytestring-mmap = jailbreakUnbreak old.bytestring-mmap; # old.callCabal2nix "bytestring-mmap" inputs.bytestring-mmap {}; + skylighting-lucid = new.callHackage "skylighting-lucid" "1.0.4" { }; + wai-app-file-cgi = dontCoverage (dontCheck (jailbreakUnbreak old.wai-app-file-cgi)); + saltine = old.callCabal2nix "saltine" inputs.saltine { inherit (pkgs) libsodium; }; + } + // pkgs.lib.genAttrs topLevelPackages (name: + old.callCabal2nix name "${self}/${name}" {}) + // pkgs.lib.genAttrs keymanPackages (name: + old.callCabal2nix name "${self}/hbs2-keyman/${name}" {}); + }; }; - }; + + makePackages = pkgs: + pkgs.lib.mapAttrs + (_name: packagePostOverrides) # we can't apply overrides inside our overlay because it will remove linking info + (pkgs.lib.getAttrs packageNames pkgs.haskellPackages); + + # dynamic packages don't work at the moment, because + # ivanovs-4/bytestring-mmap doesn't compile with ghc 9.4 + # and bytestring-mmap doesn't compire with ghc > 9.6 + packagesDynamic = makePackages pkgs; + packagesStatic = makePackages pkgs.pkgsStatic; + in { + legacyPackages = pkgs; + + packages = + packagesDynamic // + { + default = + pkgs.symlinkJoin { + name = "hbs2-all"; + paths = builtins.attrValues packagesDynamic; + }; + static = + pkgs.symlinkJoin { + name = "hbs2-static"; + paths = builtins.attrValues packagesStatic; + }; + }; + + devShell.default = pkgs.haskellPackages.shellFor { + packages = _: pkgs.lib.attrsets.attrVals packageNames pkgs.haskellPackages; + # withHoogle = true; + buildInputs = ( + with pkgs.haskellPackages; [ + ghcid + cabal-install + haskell-language-server + hoogle + # htags + text-icu + magic + pkgs.icu72 + pkgs.openssl + weeder + ] + ++ + [ pkgs.pkg-config + inputs.hspup.packages.${pkgs.system}.default + ] + ); + + shellHook = '' + export GIT_HASH="${self.rev or self.dirtyRev or "dirty"}" + ''; + + }; + } + ); } diff --git a/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Fixme.hs b/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Fixme.hs index c503afca..99147e28 100644 --- a/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Fixme.hs +++ b/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Fixme.hs @@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE CPP #-} module HBS2.Git.Web.Html.Fixme where import HBS2.Git.DashBoard.Prelude @@ -20,6 +21,10 @@ import Data.List qualified as List import Web.Scotty.Trans as Scotty +#if __GLASGOW_HASKELL__ < 906 +import Control.Applicative -- add liftA2 into scope +#endif + instance ToHtml (H FixmeKey) where toHtmlRaw (H k) = toHtmlRaw $ take 10 $ show $ pretty k toHtml (H k) = toHtml $ take 10 $ show $ pretty k @@ -93,5 +98,3 @@ repoFixme q@(FromParams p') lww = do , hxSwap_ "afterend" ] do td_ [colspan_ "3"] mempty - - diff --git a/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Issue.hs b/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Issue.hs index bff792e0..a19d9577 100644 --- a/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Issue.hs +++ b/hbs2-git-dashboard/hbs2-git-dashboard-core/HBS2/Git/Web/Html/Issue.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module HBS2.Git.Web.Html.Issue (issuePage) where @@ -20,6 +22,9 @@ import Data.Text qualified as Text import Lucid.Base import Lucid.Html5 hiding (for_) +#if __GLASGOW_HASKELL__ < 906 +import Control.Applicative -- add liftA2 into scope +#endif data IssueOptionalArg w t = IssueOptionalArg w t @@ -146,5 +151,3 @@ issuePage repo@(RepoLww lww) f = rootPage do where trim before seize txt = Text.lines txt & drop before & take seize & Text.unlines - -