Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce closure size of executable #392

Merged
merged 13 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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