Skip to content

Commit

Permalink
Reduce closure size of executable (#392)
Browse files Browse the repository at this point in the history
Also log it in CI.
  • Loading branch information
srid authored Dec 6, 2022
1 parent 9deff5c commit 5693a0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion emanote.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 33 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
./nix/stork.nix
./nix/tailwind.nix
];
perSystem = { pkgs, config, ... }: {
perSystem = { pkgs, lib, config, ... }: {
haskellProjects.default = {
packages.emanote.root = ./.;
buildTools = hp: {
Expand All @@ -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 ];
Expand Down

0 comments on commit 5693a0e

Please sign in to comment.