diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8e25dde6f..7707e35c2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,6 +30,7 @@ jobs: id: build-nix run: | nix build -j auto --no-link + nix path-info -rSh .#default | sort -rhk2 | head - name: Build as docker img id: build run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb03e927..82a12b8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Revision history for emanote +## Unreleased + +- Nix + - Reduce Emanote's Nix runtime closure size + ## 1.0.0.0 (2022-12-04) - UI diff --git a/emanote.cabal b/emanote.cabal index b6e198202..8b4fdc438 100644 --- a/emanote.cabal +++ b/emanote.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 name: emanote -version: 1.0.0.0 +version: 1.0.1.0 license: AGPL-3.0-only copyright: 2022 Sridhar Ratnakumar maintainer: srid@srid.ca diff --git a/flake.nix b/flake.nix index e9298eac4..34585ab2e 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ ./nix/stork.nix ./nix/tailwind.nix ]; - perSystem = { pkgs, config, ... }: { + perSystem = { pkgs, lib, config, ... }: { haskellProjects.default = { packages.emanote.root = ./.; buildTools = hp: { @@ -45,16 +45,41 @@ heist-extra heist; ema = inputs.ema + /ema; }; - overrides = self: super: with pkgs.haskell.lib; { - heist = dontCheck super.heist; # Tests are broken. - tailwind = addBuildDepends (unmarkBroken super.tailwind) [ config.packages.tailwind ]; - commonmark-extensions = self.callHackage "commonmark-extensions" "0.2.3.2" { }; - emanote = addBuildDepends super.emanote [ config.packages.stork ]; - }; + overrides = with pkgs.haskell.lib; + let + # Remove the given references from drv's executables. + # We shouldn't need this after https://github.com/haskell/cabal/pull/8534 + removeReferencesTo = disallowedReferences: drv: + drv.overrideAttrs (old: rec { + inherit disallowedReferences; + # Ditch data dependencies that are not needed at runtime. + # cf. https://github.com/NixOS/nixpkgs/pull/204675 + # cf. https://srid.ca/remove-references-to + postInstall = (old.postInstall or "") + '' + ${lib.concatStrings (map (e: "echo Removing reference to: ${e}\n") disallowedReferences)} + ${lib.concatStrings (map (e: "remove-references-to -t ${e} $out/bin/*\n") disallowedReferences)} + ''; + }); + in + self: super: { + heist = dontCheck super.heist; # Tests are broken. + tailwind = addBuildDepends (unmarkBroken super.tailwind) [ config.packages.tailwind ]; + commonmark-extensions = self.callHackage "commonmark-extensions" "0.2.3.2" { }; + emanote = + lib.pipe super.emanote [ + (lib.flip addBuildDepends [ config.packages.stork ]) + justStaticExecutables + (removeReferencesTo [ + self.pandoc + self.pandoc-types + self.warp + ]) + ]; + }; }; packages.default = config.packages.emanote; emanote = { - package = config.packages.emanote; + package = config.packages.default; sites = { "docs" = { layers = [ ./docs ];