This commit is contained in:
Clément DOUIN
2024-11-23 12:33:47 +01:00
parent 924d3cfefd
commit 772f689eda
7 changed files with 185 additions and 46 deletions
+12 -17
View File
@@ -11,20 +11,15 @@ jobs:
matrix:
include:
- os: ubuntu-latest
host: x86_64-linux
target: x86_64-linux
target: null
- os: ubuntu-latest
host: x86_64-linux
target: aarch64-linux
target: aarch64-unknown-linux-musl
- os: ubuntu-latest
host: x86_64-linux
target: x86_64-windows
target: x86_64-pc-windows-gnu
- os: macos-13
host: x86_64-darwin
target: x86_64-darwin
target: null
- os: macos-14
host: aarch64-darwin
target: aarch64-darwin
target: null
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -33,7 +28,7 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-24.05
enable_kvm: true
extra_nix_config: "experimental-features = nix-command flakes"
# extra_nix_config: "experimental-features = nix-command flakes"
- name: Cache Nix store
uses: cachix/cachix-action@v15
with:
@@ -41,13 +36,13 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
extraPullNames: nix-community
- name: Build release
if: ${{ matrix.target }} != null
run: |
nix build -L --expr "
(builtins.getFlake \"git+file://${PWD}?shallow=1&rev=$(git rev-parse HEAD)\")
.outputs.packages.${{ matrix.host }}.${{ matrix.target }}.overrideAttrs {
GIT_DESCRIBE = \"$(git describe --all --always --dirty)\";
}"
nix run -L .#${{ matrix.target }} -- --version
nix-build --arg '{ config = "${{ matrix.target }}"; }'
- name: Build release
if: ${{ matrix.target }} == null
run: |
nix-build
- name: Upload release artifacts
uses: actions/upload-artifact@v4
with:
+2
View File
@@ -74,6 +74,8 @@ fn git_envs() {
// skip the process if the current directory is not a git
// repository (for example, from a nix build root jail)
let Ok(git) = Repository::open(".") else {
println!("cargo::rustc-env=GIT_DESCRIBE=unknown");
println!("cargo::rustc-env=GIT_REV=unknown");
return;
};
+11
View File
@@ -0,0 +1,11 @@
{
aarch64-unknown-linux-musl = {
runner = { qemu, ... }: "${qemu}/bin/qemu-aarch64 ./himalaya";
};
x86_64-pc-windows-gnu = {
runner = { wine, ... }:
let wine64 = wine.override { wineBuild = "wine64"; };
in "${wine64}/bin/wine64 ./himalaya.exe";
};
}
+70 -12
View File
@@ -1,12 +1,70 @@
# This file exists for legacy Nix installs (nix-build & nix-env)
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
# You generally do *not* have to modify this ever.
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).defaultNix
# https://nixos.org/manual/nixpkgs/stable/#sec-cross-usage
{ crossSystem ? null }:
let
crossBuildEnabled = !isNull crossSystem;
crossSystems = import ./cross-systems.nix;
buildPkgs = import <nixpkgs> { };
hostPkgs = if crossBuildEnabled then import <nixpkgs> { inherit crossSystem; } else buildPkgs;
inherit (hostPkgs.stdenv) buildPlatform hostPlatform;
runner = if crossBuildEnabled then crossSystems.${hostPlatform.config}.runner buildPkgs else "./himalaya";
fenix = import (fetchTarball "https://github.com/soywod/fenix/archive/main.tar.gz") { };
mkToolchain = import ./rust-toolchain.nix fenix;
rustToolchain = mkToolchain.fromTarget {
pkgs = hostPkgs;
targetSystem = buildPlatform.config;
};
rustPlatform = hostPkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;
};
himalaya = import ./package.nix {
inherit rustPlatform;
lib = hostPkgs.lib;
fetchFromGitHub = hostPkgs.fetchFromGitHub;
pkg-config = hostPkgs.pkg-config;
darwin = hostPkgs.darwin;
installShellFiles = false;
installShellCompletions = false;
installManPages = false;
notmuch = hostPkgs.notmuch;
gpgme = hostPkgs.gpgme;
stdenv = hostPkgs.stdenv;
};
in
himalaya.overrideAttrs (drv: {
version = "1.0.0";
postInstall = ''
mkdir -p $out/bin/share/{applications,completions,man,services}
cp assets/himalaya.desktop $out/bin/share/applications/
cp assets/himalaya-watch@.service $out/bin/share/services/
cd $out/bin
${runner} man ./share/man
${runner} completion bash > ./share/completions/himalaya.bash
${runner} completion elvish > ./share/completions/himalaya.elvish
${runner} completion fish > ./share/completions/himalaya.fish
${runner} completion powershell > ./share/completions/himalaya.powershell
${runner} completion zsh > ./share/completions/himalaya.zsh
tar -czf himalaya.tgz himalaya* share
mv himalaya.tgz ../
${hostPkgs.zip}/bin/zip -r himalaya.zip himalaya* share
mv himalaya.zip ../
'';
src = hostPkgs.nix-gitignore.gitignoreSource [ ] ./.;
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
})
+71
View File
@@ -0,0 +1,71 @@
{ lib
, rustPlatform
, fetchFromGitHub
, stdenv
, pkg-config
, darwin
, installShellFiles
, installShellCompletions ? stdenv.buildPlatform.canExecute stdenv.hostPlatform
, installManPages ? stdenv.buildPlatform.canExecute stdenv.hostPlatform
, notmuch
, gpgme
, buildNoDefaultFeatures ? false
, buildFeatures ? [ ]
, cargoLock ? null
}:
rustPlatform.buildRustPackage rec {
inherit buildNoDefaultFeatures buildFeatures cargoLock;
pname = "himalaya";
version = "1.0.0-beta.4";
src = fetchFromGitHub {
owner = "soywod";
repo = "himalaya";
rev = "v${version}";
hash = "sha256-NrWBg0sjaz/uLsNs8/T4MkUgHOUvAWRix1O5usKsw6o=";
};
cargoHash = "sha256-YS8IamapvmdrOPptQh2Ef9Yold0IK1XIeGs0kDIQ5b8=";
NIX_BUILD_CORES = 4;
CARGO_TARGET_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" ];
doCheck = false;
cargoTestFlags = [
# Only run lib tests (unit tests)
# All other tests are integration tests which should not be run with Nix build
"--lib"
];
nativeBuildInputs = [ ]
++ lib.optional (builtins.elem "pgp-gpg" buildFeatures) pkg-config
++ lib.optional (installManPages || installShellCompletions) installShellFiles;
buildInputs = [ ]
++ lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ AppKit Cocoa Security ])
++ lib.optional (builtins.elem "notmuch" buildFeatures) notmuch
++ lib.optional (builtins.elem "pgp-gpg" buildFeatures) gpgme;
postInstall = lib.optionalString installManPages ''
mkdir -p $out/man
$out/bin/himalaya man $out/man
installManPage $out/man/*
'' + lib.optionalString installShellCompletions ''
installShellCompletion --cmd himalaya \
--bash <($out/bin/himalaya completion bash) \
--fish <($out/bin/himalaya completion fish) \
--zsh <($out/bin/himalaya completion zsh)
'';
meta = {
description = "CLI to manage emails";
mainProgram = "himalaya";
homepage = "https://github.com/pimalaya/himalaya/";
changelog = "https://github.com/soywod/himalaya/blob/v${version}/CHANGELOG.md";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ soywod toastal yanganto ];
};
}
+5 -5
View File
@@ -4,19 +4,19 @@ let
file = ./rust-toolchain.toml;
sha256 = "+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8=";
in
{
fromFile = { buildSystem }: fenix.packages.${buildSystem}.fromToolchainFile {
inherit file sha256;
};
fromTarget = { pkgs, buildSystem, targetSystem }:
fromTarget = { pkgs, targetSystem }:
let
name = (pkgs.lib.importTOML file).toolchain.channel;
fenixPackage = fenix.packages.${buildSystem};
toolchain = fenixPackage.fromToolchainName { inherit name sha256; };
targetToolchain = fenixPackage.targets.${targetSystem}.fromToolchainName { inherit name sha256; };
toolchain = fenix.fromToolchainName { inherit name sha256; };
targetToolchain = fenix.targets.${targetSystem}.fromToolchainName { inherit name sha256; };
in
fenixPackage.combine [
fenix.combine [
toolchain.rustc
toolchain.cargo
targetToolchain.rust-std
+14 -12
View File
@@ -1,12 +1,14 @@
# This file exists for legacy nix-shell
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
# You generally do *not* have to modify this ever.
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).shellNix
{ pkgs ? import <nixpkgs> {
overlays = [
(import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"))
];
}
}:
let
package = import ./default.nix { inherit pkgs; };
in
pkgs.mkShell {
inputsFrom = [ package ];
}