2021-04-17 22:06:11 +00:00
|
|
|
{
|
2023-12-31 10:05:08 +00:00
|
|
|
description = "CLI to manage emails";
|
2021-04-17 22:06:11 +00:00
|
|
|
|
|
|
|
inputs = {
|
2024-01-01 15:22:30 +00:00
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
|
2023-04-30 22:19:59 +00:00
|
|
|
gitignore = {
|
|
|
|
url = "github:hercules-ci/gitignore.nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
fenix = {
|
2024-04-16 19:26:00 +00:00
|
|
|
url = "github:soywod/fenix";
|
2023-04-30 22:19:59 +00:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
naersk = {
|
|
|
|
url = "github:nix-community/naersk";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2021-04-17 22:06:11 +00:00
|
|
|
};
|
2023-05-03 14:54:39 +00:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
2021-04-17 22:06:11 +00:00
|
|
|
};
|
|
|
|
|
2024-03-07 17:40:35 +00:00
|
|
|
outputs = { self, nixpkgs, gitignore, fenix, naersk, ... }:
|
2023-04-30 22:19:59 +00:00
|
|
|
let
|
2024-04-18 21:34:15 +00:00
|
|
|
inherit (nixpkgs) lib;
|
2023-04-30 22:19:59 +00:00
|
|
|
inherit (gitignore.lib) gitignoreSource;
|
2021-04-17 22:06:11 +00:00
|
|
|
|
2024-04-16 19:26:00 +00:00
|
|
|
# Map of map matching supported Nix build systems with Rust
|
|
|
|
# cross target systems.
|
2024-04-18 20:06:24 +00:00
|
|
|
crossSystems = {
|
2024-04-16 19:26:00 +00:00
|
|
|
x86_64-linux = {
|
|
|
|
x86_64-linux = {
|
|
|
|
rustTarget = "x86_64-unknown-linux-musl";
|
|
|
|
};
|
|
|
|
|
2024-04-18 14:54:48 +00:00
|
|
|
aarch64-linux = rec {
|
2024-04-16 19:26:00 +00:00
|
|
|
rustTarget = "aarch64-unknown-linux-musl";
|
2024-04-18 20:06:24 +00:00
|
|
|
runner = { pkgs, himalaya }: "${pkgs.qemu}/bin/qemu-aarch64 ${himalaya}";
|
2024-04-18 14:54:48 +00:00
|
|
|
mkPackage = { system, pkgs }: package:
|
2024-04-16 19:26:00 +00:00
|
|
|
let
|
|
|
|
inherit (mkPkgsCross system rustTarget) stdenv;
|
2024-04-18 14:54:48 +00:00
|
|
|
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
|
|
in
|
|
|
|
package // {
|
2024-04-16 19:26:00 +00:00
|
|
|
TARGET_CC = cc;
|
2024-04-18 14:54:48 +00:00
|
|
|
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";
|
2024-04-18 20:06:24 +00:00
|
|
|
runner = { pkgs, himalaya }:
|
2024-04-18 14:54:48 +00:00
|
|
|
let wine = pkgs.wine.override { wineBuild = "wine64"; };
|
2024-04-18 20:42:11 +00:00
|
|
|
in "${wine}/bin/wine64 ${himalaya}.exe";
|
2024-04-18 14:54:48 +00:00
|
|
|
mkPackage = { system, pkgs }: package:
|
2024-04-16 19:26:00 +00:00
|
|
|
let
|
2024-04-18 14:54:48 +00:00
|
|
|
inherit (pkgs.pkgsCross.mingwW64) stdenv windows;
|
2024-04-16 19:26:00 +00:00
|
|
|
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
|
|
in
|
2024-04-18 14:54:48 +00:00
|
|
|
package // {
|
2024-04-16 19:26:00 +00:00
|
|
|
depsBuildBuild = [ stdenv.cc windows.pthreads ];
|
|
|
|
TARGET_CC = cc;
|
2024-04-18 14:54:48 +00:00
|
|
|
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
|
2024-04-16 19:26:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-18 14:54:48 +00:00
|
|
|
aarch64-linux = {
|
|
|
|
aarch64-linux = {
|
|
|
|
rustTarget = "aarch64-unknown-linux-musl";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-16 19:26:00 +00:00
|
|
|
x86_64-darwin = {
|
2024-04-18 14:54:48 +00:00
|
|
|
x86_64-darwin = {
|
2024-04-16 19:26:00 +00:00
|
|
|
rustTarget = "x86_64-apple-darwin";
|
2024-04-18 14:54:48 +00:00
|
|
|
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?!
|
2024-04-19 05:22:25 +00:00
|
|
|
aarch64-darwin = {
|
|
|
|
rustTarget = "aarch64-apple-darwin";
|
|
|
|
runner = { pkgs, himalaya }: "${pkgs.qemu}/bin/qemu-aarch64 ${himalaya}";
|
|
|
|
mkPackage = { system, pkgs }: package:
|
|
|
|
let
|
|
|
|
inherit ((mkPkgsCross system "aarch64-darwin").pkgsStatic) stdenv darwin;
|
|
|
|
inherit (darwin.apple_sdk.frameworks) AppKit Cocoa;
|
|
|
|
cc = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
|
|
in
|
|
|
|
package // {
|
|
|
|
buildInputs = [ Cocoa ];
|
|
|
|
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
|
|
|
|
TARGET_CC = cc;
|
|
|
|
CARGO_BUILD_RUSTFLAGS = package.CARGO_BUILD_RUSTFLAGS ++ [ "-Clinker=${cc}" ];
|
|
|
|
};
|
|
|
|
};
|
2024-04-18 14:54:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
aarch64-darwin = {
|
|
|
|
aarch64-darwin = {
|
2024-04-16 19:26:00 +00:00
|
|
|
rustTarget = "aarch64-apple-darwin";
|
2024-04-18 14:54:48 +00:00
|
|
|
mkPackage = { pkgs, ... }: package:
|
|
|
|
let inherit (pkgs.darwin.apple_sdk.frameworks) AppKit Cocoa;
|
|
|
|
in package // {
|
2024-04-16 19:26:00 +00:00
|
|
|
buildInputs = [ Cocoa ];
|
2024-04-18 14:54:48 +00:00
|
|
|
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
|
2024-04-16 19:26:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-01 14:13:31 +00:00
|
|
|
mkToolchain = import ./rust-toolchain.nix fenix;
|
2021-04-17 22:06:11 +00:00
|
|
|
|
2024-04-16 19:26:00 +00:00
|
|
|
mkPkgsCross = buildSystem: crossSystem: import nixpkgs {
|
|
|
|
system = buildSystem;
|
|
|
|
crossSystem.config = crossSystem;
|
|
|
|
};
|
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
mkDevShells = buildSystem:
|
2023-04-30 22:19:59 +00:00
|
|
|
let
|
2024-04-18 20:06:24 +00:00
|
|
|
pkgs = import nixpkgs { system = buildSystem; };
|
|
|
|
rust-toolchain = mkToolchain.fromFile { inherit buildSystem; };
|
2023-04-30 22:19:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
default = pkgs.mkShell {
|
2024-04-16 19:26:00 +00:00
|
|
|
nativeBuildInputs = with pkgs; [ pkg-config ];
|
2023-04-30 22:19:59 +00:00
|
|
|
buildInputs = with pkgs; [
|
2023-12-31 10:05:08 +00:00
|
|
|
# Nix
|
2024-04-18 14:54:48 +00:00
|
|
|
nixd
|
2022-05-28 12:36:32 +00:00
|
|
|
nixpkgs-fmt
|
|
|
|
|
2023-12-31 10:05:08 +00:00
|
|
|
# Rust
|
2023-04-30 22:19:59 +00:00
|
|
|
rust-toolchain
|
2024-01-12 09:16:43 +00:00
|
|
|
cargo-watch
|
2022-05-28 12:36:32 +00:00
|
|
|
|
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
|
2022-02-02 01:21:35 +00:00
|
|
|
];
|
2021-04-17 22:06:11 +00:00
|
|
|
};
|
2023-04-30 22:19:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
mkPackages = buildSystem:
|
2023-04-30 22:19:59 +00:00
|
|
|
let
|
2024-04-18 20:06:24 +00:00
|
|
|
pkgs = import nixpkgs { system = buildSystem; };
|
2024-04-18 14:54:48 +00:00
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
mkPackage = targetSystem: targetConfig:
|
2024-04-19 05:22:25 +00:00
|
|
|
let
|
|
|
|
mkPackage' = targetConfig.mkPackage or (_: p: p);
|
|
|
|
himalaya = "./himalaya";
|
|
|
|
runner = targetConfig.runner or (_: himalaya) { inherit pkgs himalaya; };
|
|
|
|
in
|
|
|
|
mkPackage' { inherit pkgs; system = buildSystem; } {
|
2024-04-18 14:54:48 +00:00
|
|
|
name = "himalaya";
|
|
|
|
src = gitignoreSource ./.;
|
2024-04-19 05:52:02 +00:00
|
|
|
strictDeps = true;
|
2024-04-18 14:54:48 +00:00
|
|
|
doCheck = false;
|
|
|
|
auditable = false;
|
2024-04-19 05:52:02 +00:00
|
|
|
nativeBuildInputs = with pkgs; [ pkg-config ];
|
2024-04-18 20:06:24 +00:00
|
|
|
CARGO_BUILD_TARGET = targetConfig.rustTarget;
|
2024-04-19 07:44:16 +00:00
|
|
|
CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" ];
|
2024-04-19 05:52:02 +00:00
|
|
|
postInstall = ''
|
|
|
|
export WINEPREFIX="$(mktemp -d)"
|
|
|
|
|
|
|
|
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
|
|
|
|
${pkgs.zip}/bin/zip -r himalaya.zip himalaya* share
|
|
|
|
|
|
|
|
mv share ../
|
|
|
|
mv himalaya.tgz himalaya.zip ../
|
|
|
|
'';
|
2024-04-18 14:54:48 +00:00
|
|
|
};
|
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
buildPackage = targetSystem: targetConfig:
|
2024-04-18 14:54:48 +00:00
|
|
|
let
|
|
|
|
toolchain = mkToolchain.fromTarget {
|
2024-04-18 20:06:24 +00:00
|
|
|
inherit pkgs buildSystem;
|
|
|
|
targetSystem = targetConfig.rustTarget;
|
2024-04-18 14:54:48 +00:00
|
|
|
};
|
2024-04-18 20:06:24 +00:00
|
|
|
rust = naersk.lib.${buildSystem}.override {
|
2024-04-18 14:54:48 +00:00
|
|
|
cargo = toolchain;
|
|
|
|
rustc = toolchain;
|
|
|
|
};
|
2024-04-18 20:06:24 +00:00
|
|
|
package = mkPackage targetSystem targetConfig;
|
2024-04-18 14:54:48 +00:00
|
|
|
in
|
2024-04-18 20:06:24 +00:00
|
|
|
rust.buildPackage package;
|
|
|
|
|
|
|
|
defaultPackage = buildPackage buildSystem crossSystems.${buildSystem}.${buildSystem};
|
|
|
|
packages = builtins.mapAttrs buildPackage crossSystems.${buildSystem};
|
2023-04-30 22:19:59 +00:00
|
|
|
|
2024-04-18 14:54:48 +00:00
|
|
|
in
|
2024-04-19 05:22:25 +00:00
|
|
|
{ default = defaultPackage; } // packages;
|
2023-04-30 22:19:59 +00:00
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
mkApps = buildSystem:
|
2024-01-01 15:22:30 +00:00
|
|
|
let
|
2024-04-18 20:06:24 +00:00
|
|
|
pkgs = import nixpkgs { system = buildSystem; };
|
|
|
|
mkAppWrapper = { targetSystem }:
|
|
|
|
let
|
|
|
|
targetConfig = crossSystems.${buildSystem}.${targetSystem};
|
|
|
|
drv = self.packages.${buildSystem}.${targetSystem};
|
|
|
|
exePath = drv.passthru.exePath or "/bin/himalaya";
|
|
|
|
himalaya = "${drv}${exePath}";
|
|
|
|
himalayaWrapper = targetConfig.runner or (_: himalaya) { inherit pkgs himalaya; };
|
|
|
|
wrapper = pkgs.writeShellScriptBin "himalaya" "${himalayaWrapper} $@";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
type = "app";
|
|
|
|
program = "${wrapper}/bin/himalaya";
|
|
|
|
};
|
|
|
|
mkApp = targetSystem: _: mkAppWrapper { inherit targetSystem; };
|
2024-04-19 05:22:25 +00:00
|
|
|
|
2024-04-18 20:06:24 +00:00
|
|
|
defaultApp = mkApp buildSystem null;
|
|
|
|
apps = builtins.mapAttrs mkApp crossSystems.${buildSystem};
|
2024-01-01 15:22:30 +00:00
|
|
|
in
|
2024-04-18 20:06:24 +00:00
|
|
|
{ default = defaultApp; } // apps;
|
2024-04-16 19:26:00 +00:00
|
|
|
|
2024-04-18 21:34:15 +00:00
|
|
|
eachSystem = lib.genAttrs (builtins.attrNames crossSystems);
|
|
|
|
|
2023-04-30 22:19:59 +00:00
|
|
|
in
|
2024-03-07 17:40:35 +00:00
|
|
|
{
|
2024-04-18 21:34:15 +00:00
|
|
|
apps = eachSystem mkApps;
|
|
|
|
packages = eachSystem mkPackages;
|
|
|
|
devShells = eachSystem mkDevShells;
|
2024-03-07 17:40:35 +00:00
|
|
|
};
|
2021-04-17 22:06:11 +00:00
|
|
|
}
|