himalaya/flake.nix

253 lines
8.8 KiB
Nix
Raw Normal View History

{
description = "CLI to manage emails";
inputs = {
2024-01-01 15:22:30 +00:00
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
2024-04-16 19:26:00 +00:00
url = "github:soywod/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-05-03 14:54:39 +00:00
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, gitignore, fenix, naersk, ... }:
let
inherit (gitignore.lib) gitignoreSource;
2024-04-16 19:26:00 +00:00
staticRustFlags = [ "-Ctarget-feature=+crt-static" ];
# Map of map matching supported Nix build systems with Rust
# cross target systems.
crossBuildTargets = {
x86_64-linux = {
x86_64-linux = {
rustTarget = "x86_64-unknown-linux-musl";
};
aarch64-linux = rec {
2024-04-16 19:26:00 +00:00
rustTarget = "aarch64-unknown-linux-musl";
runner = pkgs: "${pkgs.qemu}/bin/qemu-aarch64 ./himalaya";
mkPackage = { system, pkgs }: package:
2024-04-16 19:26:00 +00:00
let
inherit (mkPkgsCross system rustTarget) stdenv;
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
in
package // {
2024-04-16 19:26:00 +00:00
TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
2024-04-16 19:26:00 +00:00
};
};
x86_64-windows = {
rustTarget = "x86_64-pc-windows-gnu";
runner = pkgs:
let wine = pkgs.wine.override { wineBuild = "wine64"; };
in "${wine}/bin/wine64 ./himalaya.exe";
mkPackage = { system, pkgs }: package:
2024-04-16 19:26:00 +00:00
let
inherit (pkgs.pkgsCross.mingwW64) stdenv windows;
2024-04-16 19:26:00 +00:00
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
in
package // {
2024-04-16 19:26:00 +00:00
depsBuildBuild = [ stdenv.cc windows.pthreads ];
TARGET_CC = cc;
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
2024-04-16 19:26:00 +00:00
};
};
};
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;
# };
# };
2024-04-16 19:26:00 +00:00
x86_64-darwin = {
x86_64-darwin = {
2024-04-16 19:26:00 +00:00
rustTarget = "x86_64-apple-darwin";
mkPackage = { pkgs, ... }: package:
let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa;
in package // {
2024-04-16 19:26:00 +00:00
buildInputs = [ Cocoa ];
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
};
};
# FIXME: infinite recursion in stdenv?!
# 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 = {
2024-04-16 19:26:00 +00:00
rustTarget = "aarch64-apple-darwin";
mkPackage = { pkgs, ... }: package:
let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa;
in package // {
2024-04-16 19:26:00 +00:00
buildInputs = [ Cocoa ];
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
2024-04-16 19:26:00 +00:00
};
};
};
};
mkToolchain = import ./rust-toolchain.nix fenix;
2024-04-16 19:26:00 +00:00
mkPkgsCross = buildSystem: crossSystem: import nixpkgs {
system = buildSystem;
crossSystem.config = crossSystem;
};
mkPackageArchives = { pkgs, runner ? "./himalaya" }: ''
export WINEPREFIX="$(mktemp -d)"
2024-04-16 19:26:00 +00:00
cd $out/bin
mkdir -p {man,completions}
${runner} man ./man
${runner} completion bash > ./completions/himalaya.bash
${runner} completion elvish > ./completions/himalaya.elvish
${runner} completion fish > ./completions/himalaya.fish
${runner} completion powershell > ./completions/himalaya.powershell
${runner} completion zsh > ./completions/himalaya.zsh
2024-04-16 19:26:00 +00:00
tar -czf himalaya.tgz himalaya* man completions
${pkgs.zip}/bin/zip -r himalaya.zip himalaya* man completions
2024-04-16 19:26:00 +00:00
'';
mkDevShells = buildPlatform:
let
pkgs = import nixpkgs { system = buildPlatform; };
rust-toolchain = mkToolchain.fromFile { system = buildPlatform; };
in
{
default = pkgs.mkShell {
2024-04-16 19:26:00 +00:00
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [
# Nix
nixd
nixpkgs-fmt
# Rust
rust-toolchain
2024-01-12 09:16:43 +00:00
cargo-watch
2024-04-16 19:26:00 +00:00
# Email env
2023-08-28 07:04:13 +00:00
gnupg
2023-08-05 10:10:25 +00:00
gpgme
2024-04-16 19:26:00 +00:00
msmtp
notmuch
release v0.5.2 (#282) * doc: fix blur in list msg screenshots (#181) * fix a typo in mbox arg (#245) `targetted` to `targeted` 👌🏻 * make inbox, sent and drafts folder customizable (#246) * mbox: make inbox, sent and drafts folder customizable * msg: update send handler parameters order * vim: fix extracting message ids from list (#247) The current method doesn't work because the list uses a fancy line character (`│`) as the separator, not a regular pipe character (`|`). Matching for the first number in the line instead solves the problem and will continue to work regardless of what separator is used. * add new line after printing strings (#251) * init cargo workspace (#252) * init cargo workspaces * nix: fix assets path * doc: update rtp vim plugin * vim: add error message if loading vim plugin from vim/ * init sub crates (#253) * init sub crates * doc: update readme * doc: improve main readme * doc: add links, add missing crate task * doc: update emojis * update cargo lock * implement contact completion with completefunc (#250) This allows users to define a command for contact completion with `g:himalaya_complete_contact_cmd` and trigger it with `<C-x><C-u>` when writing an email. * fix clippy lints (#255) * revert cargo workspace feature * fix nix run (#274) * replace cargo2nix by naersk * add rust-analyzer and rustfmt to nix build inputs * remove wiki from git submodules, update changelog * fix missing range when fetch fails, add more logs (#276) * add missing fix in changelog * remove blank lines and spaces from plain parts (#280) * fix watch command (#271) * remove also tabs from text parts (#280) * pin native-tls minor version (#278) * improve msg sanitization (#280) * fix mbox vim plugin telescope preview (#249) * bump version v0.5.2 * update changelog Co-authored-by: Austin Traver <austintraver@gmail.com> Co-authored-by: Jason Cox <dev@jasoncarloscox.com> Co-authored-by: Gökmen Görgen <gkmngrgn@gmail.com> Co-authored-by: Ethiraric <ethiraric@gmail.com>
2022-02-02 01:21:35 +00:00
];
};
};
mkPackages = buildPlatform:
let
pkgs = import nixpkgs { system = buildPlatform; };
mkPackage = targetPlatform: crossBuild:
let mkPackage' = crossBuild.mkPackage or (_: p: p);
in mkPackage' { inherit pkgs; system = buildPlatform; } {
name = "himalaya";
src = gitignoreSource ./.;
# overrideMain = _: {
# postInstall = ''
# mkdir -p $out/share/applications/
# cp assets/himalaya.desktop $out/share/applications/
# '';
# };
doCheck = false;
auditable = false;
strictDeps = true;
CARGO_BUILD_TARGET = targetPlatform;
CARGO_BUILD_RUSTFLAGS = staticRustFlags;
};
buildPackage = doPostInstall: targetPlatform: crossBuild:
let
toolchain = mkToolchain.fromTarget {
inherit pkgs buildPlatform;
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};
in
{ default = defaultPackage; } // packages // archives;
mkApp = drv:
let exePath = drv.passthru.exePath or "/bin/himalaya";
in
{
type = "app";
program = "${drv}${exePath}";
};
2024-01-01 15:22:30 +00:00
mkApps = buildPlatform:
let
pkgs = import nixpkgs { system = buildPlatform; };
2024-04-16 19:26:00 +00:00
mkApp' = target: package: mkApp self.packages.${buildPlatform}.${target};
2024-01-01 15:22:30 +00:00
in
2024-04-16 19:26:00 +00:00
builtins.mapAttrs mkApp' crossBuildTargets.${buildPlatform};
supportedSystems = builtins.attrNames crossBuildTargets;
mapSupportedSystem = nixpkgs.lib.genAttrs supportedSystems;
in
{
2024-04-16 19:26:00 +00:00
apps = mapSupportedSystem mkApps;
packages = mapSupportedSystem mkPackages;
devShells = mapSupportedSystem mkDevShells;
};
}