separate simple packages from archives packages for releases

This commit is contained in:
Clément DOUIN 2024-04-18 16:54:48 +02:00
parent 10de8e9fb4
commit 7899484942
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72

205
flake.nix
View file

@ -33,81 +33,98 @@
x86_64-linux = { x86_64-linux = {
x86_64-linux = { x86_64-linux = {
rustTarget = "x86_64-unknown-linux-musl"; rustTarget = "x86_64-unknown-linux-musl";
override = { ... }: { };
}; };
arm64-linux = rec { aarch64-linux = rec {
rustTarget = "aarch64-unknown-linux-musl"; rustTarget = "aarch64-unknown-linux-musl";
override = { system, pkgs }: runner = pkgs: "${pkgs.qemu}/bin/qemu-aarch64 ./himalaya";
mkPackage = { system, pkgs }: package:
let let
inherit (mkPkgsCross system rustTarget) stdenv; inherit (mkPkgsCross system rustTarget) stdenv;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; in cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
rec { in
package // {
TARGET_CC = cc; TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = staticRustFlags ++ [ "-Clinker=${cc}" ]; CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
postInstall = mkPostInstall {
inherit pkgs;
bin = "${pkgs.qemu}/bin/qemu-aarch64 ./himalaya";
};
}; };
}; };
x86_64-windows = { x86_64-windows = {
rustTarget = "x86_64-pc-windows-gnu"; rustTarget = "x86_64-pc-windows-gnu";
override = { system, pkgs }: runner = pkgs:
let wine = pkgs.wine.override { wineBuild = "wine64"; };
in "${wine}/bin/wine64 ./himalaya.exe";
mkPackage = { system, pkgs }: package:
let let
inherit (pkgs) pkgsCross zip; inherit (pkgs.pkgsCross.mingwW64) stdenv windows;
inherit (pkgsCross.mingwW64) stdenv windows;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
wine = pkgs.wine.override { wineBuild = "wine64"; };
postInstall = mkPostInstall {
inherit pkgs;
bin = "${wine}/bin/wine64 ./himalaya.exe";
};
in in
{ package // {
depsBuildBuild = [ stdenv.cc windows.pthreads ]; depsBuildBuild = [ stdenv.cc windows.pthreads ];
TARGET_CC = cc; TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = staticRustFlags ++ [ "-Clinker=${cc}" ]; CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
postInstall = ''
export WINEPREFIX="$(mktemp -d)"
${postInstall}
'';
}; };
}; };
}; };
aarch64-linux = {
aarch64-linux = {
rustTarget = "aarch64-unknown-linux-musl";
};
};
# FIXME: attribute 'sharedLibrary' missing?
# x86_64-windows = {
# x86_64-windows = {
# rustTarget = "x86_64-pc-windows-gnu";
# runner = _: "./himalaya.exe";
# mkPackage = { system, pkgs }: package: package;
# };
# };
x86_64-darwin = { x86_64-darwin = {
x86_64-macos = { x86_64-darwin = {
rustTarget = "x86_64-apple-darwin"; rustTarget = "x86_64-apple-darwin";
override = { pkgs, ... }: mkPackage = { pkgs, ... }: package:
let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa; in let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa;
{ in package // {
buildInputs = [ Cocoa ]; buildInputs = [ Cocoa ];
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit"; NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
}; };
}; };
# FIXME: infinite recursion in stdenv?! # FIXME: infinite recursion in stdenv?!
arm64-macos = { # aarch64-darwin = {
# rustTarget = "aarch64-apple-darwin";
# override = { system, pkgs }:
# let
# # inherit (mkPkgsCross system "aarch64-darwin") stdenv;
# inherit ((mkPkgsCross system "aarch64-darwin").pkgsStatic) stdenv darwin;
# inherit (darwin.apple_sdk.frameworks) AppKit Cocoa;
# cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
# in
# {
# buildInputs = [ Cocoa ];
# NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit -F${Cocoa}/Library/Frameworks -framework Cocoa";
# NIX_CFLAGS_COMPILE = "-F${AppKit}/Library/Frameworks -framework AppKit -F${Cocoa}/Library/Frameworks -framework Cocoa";
# TARGET_CC = cc;
# CARGO_BUILD_RUSTFLAGS = staticRustFlags ++ [ "-Clinker=${cc}" "-lframework=${Cocoa}/Library/Frameworks" ];
# postInstall = mkPostInstall {
# inherit pkgs;
# bin = "${pkgs.qemu}/bin/qemu-aarch64 ./himalaya";
# };
# };
# };
};
aarch64-darwin = {
aarch64-darwin = {
rustTarget = "aarch64-apple-darwin"; rustTarget = "aarch64-apple-darwin";
override = { system, pkgs }: mkPackage = { pkgs, ... }: package:
let let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa;
# inherit (mkPkgsCross system "aarch64-darwin") stdenv; in package // {
inherit ((mkPkgsCross system "aarch64-darwin").pkgsStatic) stdenv darwin;
inherit (darwin.apple_sdk.frameworks) AppKit Cocoa;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
in
rec {
buildInputs = [ Cocoa ]; buildInputs = [ Cocoa ];
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit -F${Cocoa}/Library/Frameworks -framework Cocoa"; NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
NIX_CFLAGS_COMPILE = "-F${AppKit}/Library/Frameworks -framework AppKit -F${Cocoa}/Library/Frameworks -framework Cocoa";
TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = staticRustFlags ++ [ "-Clinker=${cc}" "-lframework=${Cocoa}/Library/Frameworks" ];
postInstall = mkPostInstall {
inherit pkgs;
bin = "${pkgs.qemu}/bin/qemu-aarch64 ./himalaya";
};
}; };
}; };
}; };
@ -120,17 +137,18 @@
crossSystem.config = crossSystem; crossSystem.config = crossSystem;
}; };
mkPostInstall = { pkgs, bin ? "./himalaya" }: with pkgs; '' mkPackageArchives = { pkgs, runner ? "./himalaya" }: ''
export WINEPREFIX="$(mktemp -d)"
cd $out/bin cd $out/bin
mkdir -p {man,completions} mkdir -p {man,completions}
${bin} man ./man ${runner} man ./man
${bin} completion bash > ./completions/himalaya.bash ${runner} completion bash > ./completions/himalaya.bash
${bin} completion elvish > ./completions/himalaya.elvish ${runner} completion elvish > ./completions/himalaya.elvish
${bin} completion fish > ./completions/himalaya.fish ${runner} completion fish > ./completions/himalaya.fish
${bin} completion powershell > ./completions/himalaya.powershell ${runner} completion powershell > ./completions/himalaya.powershell
${bin} completion zsh > ./completions/himalaya.zsh ${runner} completion zsh > ./completions/himalaya.zsh
tar -czf himalaya.tgz himalaya* man completions tar -czf himalaya.tgz himalaya* man completions
${zip}/bin/zip -r himalaya.zip himalaya* man completions ${pkgs.zip}/bin/zip -r himalaya.zip himalaya* man completions
''; '';
mkDevShells = buildPlatform: mkDevShells = buildPlatform:
@ -143,7 +161,7 @@
nativeBuildInputs = with pkgs; [ pkg-config ]; nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ buildInputs = with pkgs; [
# Nix # Nix
# rnix-lsp nixd
nixpkgs-fmt nixpkgs-fmt
# Rust # Rust
@ -159,43 +177,58 @@
}; };
}; };
mkPackage = pkgs: buildPlatform: targetPlatform: package: mkPackages = buildPlatform:
let let
toolchain = mkToolchain.fromTarget { pkgs = import nixpkgs { system = buildPlatform; };
inherit pkgs buildPlatform targetPlatform;
}; mkPackage = targetPlatform: crossBuild:
naersk' = naersk.lib.${buildPlatform}.override { let mkPackage' = crossBuild.mkPackage or (_: p: p);
cargo = toolchain; in mkPackage' { inherit pkgs; system = buildPlatform; } {
rustc = toolchain; name = "himalaya";
}; src = gitignoreSource ./.;
package' = { # overrideMain = _: {
name = "himalaya"; # postInstall = ''
src = gitignoreSource ./.; # mkdir -p $out/share/applications/
# overrideMain = _: { # cp assets/himalaya.desktop $out/share/applications/
# postInstall = '' # '';
# mkdir -p $out/share/applications/ # };
# cp assets/himalaya.desktop $out/share/applications/ doCheck = false;
# ''; auditable = false;
# }; strictDeps = true;
doCheck = false; CARGO_BUILD_TARGET = targetPlatform;
auditable = false; CARGO_BUILD_RUSTFLAGS = staticRustFlags;
strictDeps = true; };
CARGO_BUILD_TARGET = targetPlatform;
CARGO_BUILD_RUSTFLAGS = staticRustFlags; buildPackage = doPostInstall: targetPlatform: crossBuild:
postInstall = mkPostInstall { inherit pkgs; }; let
} // package; toolchain = mkToolchain.fromTarget {
in inherit pkgs buildPlatform;
naersk'.buildPackage package'; targetPlatform = crossBuild.rustTarget;
};
rust = naersk.lib.${buildPlatform}.override {
cargo = toolchain;
rustc = toolchain;
};
package = mkPackage targetPlatform crossBuild;
postInstall = pkgs.lib.optionalAttrs doPostInstall {
postInstall = mkPackageArchives {
inherit pkgs;
runner = (crossBuild.runner or (_: null)) pkgs;
};
};
in
rust.buildPackage package // postInstall;
defaultPackage = buildPackage false buildPlatform crossBuildTargets.${buildPlatform}.${buildPlatform};
packages = builtins.mapAttrs (buildPackage false) crossBuildTargets.${buildPlatform};
archives = pkgs.lib.foldlAttrs (p: k: v: p // { "${k}-archives" = buildPackage true k v; }) { } crossBuildTargets.${buildPlatform};
mkPackages = system:
let
pkgs = import nixpkgs { inherit system; };
mkPackage' = target: package: mkPackage pkgs system package.rustTarget (package.override { inherit system pkgs; });
in in
builtins.mapAttrs mkPackage' crossBuildTargets.${system}; { default = defaultPackage; } // packages // archives;
mkApp = drv: mkApp = drv:
let exePath = drv.passthru.exePath or "/bin/himalaya"; in let exePath = drv.passthru.exePath or "/bin/himalaya";
in
{ {
type = "app"; type = "app";
program = "${drv}${exePath}"; program = "${drv}${exePath}";