mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-25 04:20:22 +00:00
ed5407a5c7
As requested in <https://todo.sr.ht/~soywod/pimalaya/131> I removed flake-utils. This reduces the number of flake inputs and doesn't add much code. The way this works, is that instead of `eachDefaultSystem` we have a function `forEachSupportedSystem`, this function generates an attrset with a key for each system in the `supportedSystems` array, whose value is the result of calling the provided function with the system as an argument: ```nix repl repl> forEachSupportedSystem f { "x86_64-linux" = f "x86_64-linux"; ... } ``` This is slightly clumsier than `flake-utils.lib.eachDefaultSystem`, which rewrites the returned attrset, but it is much less code and simpler to understand. I tested the build with `nix build` on `x86_64-linux` and it still works c:
154 lines
4.8 KiB
Nix
154 lines
4.8 KiB
Nix
{
|
|
description = "CLI to manage emails";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
|
|
gitignore = {
|
|
url = "github:hercules-ci/gitignore.nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
fenix = {
|
|
url = "github:nix-community/fenix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
naersk = {
|
|
url = "github:nix-community/naersk";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
flake-compat = {
|
|
url = "github:edolstra/flake-compat";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, gitignore, fenix, naersk, ... }:
|
|
let
|
|
inherit (gitignore.lib) gitignoreSource;
|
|
|
|
mkToolchain = import ./rust-toolchain.nix fenix;
|
|
|
|
mkDevShells = buildPlatform:
|
|
let
|
|
pkgs = import nixpkgs { system = buildPlatform; };
|
|
rust-toolchain = mkToolchain.fromFile { system = buildPlatform; };
|
|
in
|
|
{
|
|
default = pkgs.mkShell {
|
|
nativeBuildInputs = with pkgs; [
|
|
pkg-config
|
|
];
|
|
buildInputs = with pkgs; [
|
|
# Nix
|
|
rnix-lsp
|
|
nixpkgs-fmt
|
|
|
|
# Rust
|
|
rust-toolchain
|
|
cargo-watch
|
|
|
|
# OpenSSL
|
|
openssl.dev
|
|
|
|
# Notmuch
|
|
notmuch
|
|
|
|
# GPG
|
|
gnupg
|
|
gpgme
|
|
];
|
|
};
|
|
};
|
|
|
|
mkPackage = pkgs: buildPlatform: targetPlatform: package:
|
|
let
|
|
toolchain = mkToolchain.fromTarget {
|
|
inherit pkgs buildPlatform targetPlatform;
|
|
};
|
|
naersk' = naersk.lib.${buildPlatform}.override {
|
|
cargo = toolchain;
|
|
rustc = toolchain;
|
|
};
|
|
package' = {
|
|
name = "himalaya";
|
|
src = gitignoreSource ./.;
|
|
overrideMain = _: {
|
|
postInstall = ''
|
|
mkdir -p $out/share/applications/
|
|
cp assets/himalaya.desktop $out/share/applications/
|
|
'';
|
|
};
|
|
doCheck = true;
|
|
cargoTestOptions = opts: opts ++ [ "--lib" ];
|
|
} // pkgs.lib.optionalAttrs (!isNull targetPlatform) {
|
|
CARGO_BUILD_TARGET = targetPlatform;
|
|
} // package;
|
|
in
|
|
naersk'.buildPackage package';
|
|
|
|
mkPackages = buildPlatform:
|
|
let
|
|
pkgs = import nixpkgs { system = buildPlatform; };
|
|
mkPackage' = mkPackage pkgs buildPlatform;
|
|
in
|
|
rec {
|
|
default = if pkgs.stdenv.isDarwin then macos else linux;
|
|
linux = mkPackage' null { };
|
|
linux-musl = mkPackage' "x86_64-unknown-linux-musl" (with pkgs.pkgsStatic; {
|
|
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
|
|
hardeningDisable = [ "all" ];
|
|
});
|
|
macos = mkPackage' null (with pkgs.darwin.apple_sdk.frameworks; {
|
|
# NOTE: needed to prevent error Undefined symbols
|
|
# "_OBJC_CLASS_$_NSImage" and
|
|
# "_LSCopyApplicationURLsForBundleIdentifier"
|
|
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
|
|
buildInputs = [ Cocoa ];
|
|
});
|
|
# FIXME: bzlip: fatal error: windows.h: No such file or directory
|
|
# May be related to SQLite.
|
|
windows = mkPackage' "x86_64-pc-windows-gnu" {
|
|
strictDeps = true;
|
|
depsBuildBuild = with pkgs.pkgsCross.mingwW64; [
|
|
stdenv.cc
|
|
windows.pthreads
|
|
];
|
|
};
|
|
};
|
|
|
|
mkApp = drv:
|
|
let exePath = drv.passthru.exePath or "/bin/himalaya";
|
|
in
|
|
{
|
|
type = "app";
|
|
program = "${drv}${exePath}";
|
|
};
|
|
|
|
mkApps = buildPlatform:
|
|
let
|
|
pkgs = import nixpkgs { system = buildPlatform; };
|
|
in
|
|
rec {
|
|
default = if pkgs.stdenv.isDarwin then macos else linux;
|
|
linux = mkApp self.packages.${buildPlatform}.linux;
|
|
linux-musl = mkApp self.packages.${buildPlatform}.linux-musl;
|
|
macos = mkApp self.packages.${buildPlatform}.macos;
|
|
windows =
|
|
let
|
|
wine = pkgs.wine.override { wineBuild = "wine64"; };
|
|
himalaya = self.packages.${buildPlatform}.windows;
|
|
app = pkgs.writeShellScriptBin "himalaya" ''
|
|
export WINEPREFIX="$(mktemp -d)"
|
|
${wine}/bin/wine64 ${himalaya}/bin/himalaya.exe $@
|
|
'';
|
|
in
|
|
mkApp app;
|
|
};
|
|
supportedSystems = [ "aarch64-linux" "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ];
|
|
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems f;
|
|
in
|
|
{
|
|
apps = forEachSupportedSystem mkApps;
|
|
packages = forEachSupportedSystem mkPackages;
|
|
devShells = forEachSupportedSystem mkDevShells;
|
|
};
|
|
}
|