Skip to content

Commit

Permalink
build(nix): Add binary distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillespie committed Mar 31, 2024
1 parent e4a42d8 commit 27bc192
Showing 1 changed file with 92 additions and 21 deletions.
113 changes: 92 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,41 @@

overlays = [
haskellNix.overlay
(final: prev: {
gibberishProject = final.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = "ghc964";
name = "gibberish";

flake.variants.profiled = {
modules = [{
(final: prev:
let
project = final.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = "ghc964";
name = "gibberish";

flake.variants.profiled = {
modules = [{
enableLibraryProfiling = true;
enableProfiling = true;
}];
};

shell = {
tools = {
cabal = "latest";
haskell-language-server = "latest";
hp2pretty = "latest";
}];
};

nativeBuildInputs = with final; [fourmolu hlint];
withHoogle = true;
shell = {
tools = {
cabal = "latest";
haskell-language-server = "latest";
hp2pretty = "latest";
};

nativeBuildInputs = with final; [fourmolu hlint];
withHoogle = true;

# No cross platforms should speed up evaluation
crossPlatforms = _: [];
# No cross platforms should speed up evaluation
crossPlatforms = _: [];
};
};
};
})
in {
gibberishProject = project.appendOverlays [
# Add exes
final.haskell-nix.haskellLib.projectOverlays.projectComponents
];
})

(final: prev: {
fourmolu =
Expand Down Expand Up @@ -102,6 +109,67 @@
(pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux
[p.musl64]));
};

cpExesCmd = project:
let
inherit (pkgs) lib;
exes = lib.collect lib.isDerivation project.exes;
in ''
# Create an intermediate dir
mkdir release
# Copy exes to intermediate dir
${lib.concatMapStringsSep
"\n"
(exe: "cp --verbose --remove-destination --update=none ${exe}/bin/* release")
exes}
'';

mkDistMusl =
let
project = pkgs.gibberishProject.projectCross.musl64;
name = "gibberish-${version}-x86_64-linux";
version = project.exes.gibber.identifier.version;
in
pkgs.runCommand
"gibberish-musl64"
{}
''
mkdir -p $out
# Copy exes to intermediate dir
${cpExesCmd project}
# Package distribution
cd release
dist_file=${name}.tar.gz
tar -cvzf $out/$dist_file .
'';

mkDistWin64 =
let
inherit (pkgs) lib;
project = pkgs.gibberishProject.projectCross.mingwW64;
name = "gibberish-${version}-x86_64-windows";
version = project.exes.gibber.identifier.version;
env = {
nativeBuildInputs = [pkgs.zip];
};
in
pkgs.runCommand
"gibberish-win64"
env
''
mkdir -p $out
# Copy exes to intermediate dir
${cpExesCmd project}
# Package distribution
cd release
dist_file=${name}.zip
find . -type f | xargs zip $out/$dist_file
'';
in
with pkgs.lib;
flake // {
Expand All @@ -117,6 +185,9 @@

packages = {
default = flake.packages."gibberish:exe:gibber";
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
dist-musl = mkDistMusl;
dist-win64 = mkDistWin64;
} // mapAttrs' mkPkg flake.packages;
});

Expand Down

0 comments on commit 27bc192

Please sign in to comment.