mirror of
https://github.com/pimalaya/himalaya.git
synced 2024-12-09 21:18:39 +03:00
make use of pimalaya/nix
This commit is contained in:
71
default.nix
71
default.nix
@@ -1,59 +1,22 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, crossPkgs ? pkgs
|
||||
, fenix ? import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { }
|
||||
, defaultFeatures ? true
|
||||
, features ? ""
|
||||
}:
|
||||
{ pimalaya ? import (fetchTarball "https://github.com/pimalaya/nix/archive/master.tar.gz")
|
||||
, ...
|
||||
} @args:
|
||||
|
||||
let
|
||||
inherit (pkgs) binutils gnutar lib mktemp stdenv wine zip;
|
||||
inherit (crossPkgs) buildPlatform hostPlatform;
|
||||
|
||||
mkToolchain = import ./rust-toolchain.nix { inherit lib fenix; };
|
||||
rustTarget = if buildPlatform == hostPlatform then null else hostPlatform.rust.rustcTarget;
|
||||
rustToolchain = mkToolchain.fromTarget rustTarget;
|
||||
rustPlatform = crossPkgs.makeRustPlatform {
|
||||
rustc = rustToolchain;
|
||||
cargo = rustToolchain;
|
||||
};
|
||||
|
||||
# HACK: https://github.com/NixOS/nixpkgs/issues/177129
|
||||
empty-libgcc_eh = stdenv.mkDerivation {
|
||||
pname = "empty-libgcc_eh";
|
||||
version = "0";
|
||||
dontUnpack = true;
|
||||
installPhase = ''
|
||||
mkdir -p "$out"/lib
|
||||
"${lib.getExe' binutils "ar"}" r "$out"/lib/libgcc_eh.a
|
||||
'';
|
||||
};
|
||||
|
||||
himalaya = import ./package.nix {
|
||||
pimalaya.mkDefault ({
|
||||
src = ./.;
|
||||
version = "1.0.0";
|
||||
mkPackage = ({ lib, pkgs, rustPlatform, defaultFeatures, features }: import ./package.nix {
|
||||
inherit lib rustPlatform;
|
||||
fetchFromGitHub = crossPkgs.fetchFromGitHub;
|
||||
stdenv = crossPkgs.stdenv;
|
||||
apple-sdk = if hostPlatform.isx86_64 then crossPkgs.apple-sdk_13 else crossPkgs.apple-sdk_14;
|
||||
installShellFiles = crossPkgs.installShellFiles;
|
||||
fetchFromGitHub = pkgs.fetchFromGitHub;
|
||||
stdenv = pkgs.stdenv;
|
||||
apple-sdk = if pkgs.hostPlatform.isx86_64 then pkgs.apple-sdk_13 else pkgs.apple-sdk_14;
|
||||
installShellFiles = pkgs.installShellFiles;
|
||||
installShellCompletions = false;
|
||||
installManPages = false;
|
||||
notmuch = crossPkgs.notmuch;
|
||||
gpgme = crossPkgs.gpgme;
|
||||
pkg-config = crossPkgs.pkg-config;
|
||||
notmuch = pkgs.notmuch;
|
||||
gpgme = pkgs.gpgme;
|
||||
pkg-config = pkgs.pkg-config;
|
||||
buildNoDefaultFeatures = !defaultFeatures;
|
||||
buildFeatures = lib.strings.splitString "," features;
|
||||
};
|
||||
in
|
||||
|
||||
himalaya.overrideAttrs (drv: {
|
||||
version = "1.0.0";
|
||||
|
||||
propagatedBuildInputs = (drv.propagatedBuildInputs or [ ])
|
||||
++ lib.optional hostPlatform.isWindows empty-libgcc_eh;
|
||||
|
||||
src = crossPkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
|
||||
cargoDeps = rustPlatform.importCargoLock {
|
||||
lockFile = ./Cargo.lock;
|
||||
allowBuiltinFetchGit = true;
|
||||
};
|
||||
})
|
||||
buildFeatures = lib.splitString "," features;
|
||||
});
|
||||
} // removeAttrs args [ "pimalaya" ])
|
||||
|
||||
19
flake.lock
generated
19
flake.lock
generated
@@ -36,10 +36,27 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pimalaya": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1732804333,
|
||||
"narHash": "sha256-Umel9Au2eHcr9d9sYV6GjctBhLioEM4BBxkmiJlg/to=",
|
||||
"owner": "pimalaya",
|
||||
"repo": "nix",
|
||||
"rev": "84e4c7c81f390abf54ac103f6f838ed68a832ee9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "pimalaya",
|
||||
"repo": "nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"fenix": "fenix",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pimalaya": "pimalaya"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
|
||||
109
flake.nix
109
flake.nix
@@ -2,108 +2,23 @@
|
||||
description = "CLI to manage emails";
|
||||
|
||||
inputs = {
|
||||
# TODO: nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
# <https://github.com/NixOS/nixpkgs/pull/358989>
|
||||
# TODO: https://github.com/NixOS/nixpkgs/pull/358989
|
||||
# nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
nixpkgs.url = "github:soywod/nixpkgs";
|
||||
fenix = {
|
||||
# TODO: url = "github:nix-community/fenix";
|
||||
# <https://github.com/nix-community/fenix/pull/145>
|
||||
# TODO: https://github.com/nix-community/fenix/pull/145
|
||||
# url = "github:nix-community/fenix";
|
||||
url = "github:soywod/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
pimalaya = {
|
||||
url = "github:pimalaya/nix";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, fenix }:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
|
||||
crossSystems = {
|
||||
aarch64-darwin = [
|
||||
"aarch64-apple-darwin"
|
||||
];
|
||||
aarch64-linux = [
|
||||
"aarch64-unknown-linux-musl"
|
||||
];
|
||||
x86_64-darwin = [
|
||||
"x86_64-apple-darwin"
|
||||
];
|
||||
x86_64-linux = [
|
||||
"aarch64-unknown-linux-musl"
|
||||
"armv6l-unknown-linux-musleabihf"
|
||||
"armv7l-unknown-linux-musleabihf"
|
||||
"i686-unknown-linux-musl"
|
||||
"x86_64-unknown-linux-musl"
|
||||
"x86_64-w64-mingw32"
|
||||
];
|
||||
};
|
||||
|
||||
withGitEnvs = package: package.overrideAttrs (drv: {
|
||||
GIT_REV = drv.GIT_REV or self.rev or self.dirtyRev or "unknown";
|
||||
GIT_DESCRIBE = drv.GIT_DESCRIBE or "nix-flake-" + self.lastModifiedDate;
|
||||
});
|
||||
|
||||
# Dev shells
|
||||
|
||||
mkDevShell = system: {
|
||||
default = import ./shell.nix {
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
fenix = fenix.packages.${system};
|
||||
};
|
||||
};
|
||||
|
||||
# Packages
|
||||
|
||||
mkPackages = system: mkCrossPackages system // {
|
||||
default = withGitEnvs (import ./default.nix ({
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
fenix = fenix.packages.${system};
|
||||
}));
|
||||
};
|
||||
|
||||
mkCrossPackages = system:
|
||||
lib.attrsets.mergeAttrsList (map (mkCrossPackage system) crossSystems.${system});
|
||||
|
||||
mkCrossPackage = system: crossConfig:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
crossSystem = { config = crossConfig; isStatic = true; };
|
||||
crossPkgs = import nixpkgs { inherit system crossSystem; };
|
||||
crossPkg = import ./default.nix { inherit pkgs crossPkgs; fenix = fenix.packages.${system}; };
|
||||
in
|
||||
{ "cross-${crossPkgs.hostPlatform.system}" = withGitEnvs crossPkg; };
|
||||
|
||||
# Apps
|
||||
|
||||
mkApps = system: mkCrossApps system // {
|
||||
default = {
|
||||
type = "app";
|
||||
program = lib.getExe self.packages.${system}.default;
|
||||
};
|
||||
};
|
||||
|
||||
mkCrossApps = system:
|
||||
lib.attrsets.mergeAttrsList (map (mkCrossApp system) crossSystems.${system});
|
||||
|
||||
mkCrossApp = system: crossConfig:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
mktemp = "${lib.getExe pkgs.mktemp} -d";
|
||||
emulator = crossPkgs.hostPlatform.emulator pkgs;
|
||||
crossSystem = { config = crossConfig; isStatic = true; };
|
||||
crossPkgs = import nixpkgs { inherit system crossSystem; };
|
||||
crossPkgName = "cross-${crossPkgs.hostPlatform.system}";
|
||||
crossPkgExe = lib.getExe self.packages.${system}.${crossPkgName};
|
||||
program = lib.getExe (pkgs.writeShellScriptBin "himalaya" ''
|
||||
${lib.optionalString crossPkgs.hostPlatform.isWindows "export WINEPREFIX=$(${mktemp})"}
|
||||
${emulator} ${crossPkgExe} $@
|
||||
'');
|
||||
in
|
||||
{ "${crossPkgName}" = { inherit program; type = "app"; }; };
|
||||
in
|
||||
|
||||
{
|
||||
devShells = lib.genAttrs (lib.attrNames crossSystems) mkDevShell;
|
||||
packages = lib.genAttrs (lib.attrNames crossSystems) mkPackages;
|
||||
apps = lib.genAttrs (lib.attrNames crossSystems) mkApps;
|
||||
};
|
||||
outputs = inputs: (import inputs.pimalaya).mkFlakeOutputs inputs {
|
||||
shell = ./shell.nix;
|
||||
default = ./default.nix;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# TODO: move this to nixpkgs
|
||||
# This file aims to be a replacement for the nixpkgs derivation.
|
||||
|
||||
{ lib
|
||||
, pkg-config
|
||||
, rustPlatform
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
{ lib, fenix }:
|
||||
|
||||
let
|
||||
file = ./rust-toolchain.toml;
|
||||
sha256 = "yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk=";
|
||||
in
|
||||
|
||||
{
|
||||
fromFile =
|
||||
let spec = { inherit file sha256; };
|
||||
in fenix.fromToolchainFile spec;
|
||||
|
||||
fromTarget = target:
|
||||
let
|
||||
name = (lib.importTOML file).toolchain.channel;
|
||||
spec = { inherit name sha256; };
|
||||
toolchain = fenix.fromToolchainName spec;
|
||||
crossToolchain = fenix.targets.${target}.fromToolchainName spec;
|
||||
components = [ toolchain.rustc toolchain.cargo ]
|
||||
++ lib.optional (!isNull target) crossToolchain.rust-std;
|
||||
in
|
||||
|
||||
fenix.combine components;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "1.82.0"
|
||||
profile = "default"
|
||||
components = [ "rust-src", "rust-analyzer" ]
|
||||
components = ["rust-src", "rust-analyzer"]
|
||||
|
||||
30
shell.nix
30
shell.nix
@@ -1,26 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, fenix ? import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { }
|
||||
, withNotmuch ? false
|
||||
, withGpg ? false
|
||||
, withOpenSsl ? false
|
||||
}:
|
||||
{ pimalaya ? import (fetchTarball "https://github.com/pimalaya/nix/archive/master.tar.gz")
|
||||
, ...
|
||||
} @args:
|
||||
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
mkRustToolchain = import ./rust-toolchain.nix { inherit lib fenix; };
|
||||
rust = mkRustToolchain.fromFile;
|
||||
in
|
||||
|
||||
pkgs.mkShell {
|
||||
buildInputs = [ ]
|
||||
# Nix language
|
||||
++ [ pkgs.nixd pkgs.nixpkgs-fmt ]
|
||||
|
||||
# Rust
|
||||
++ [ rust ]
|
||||
|
||||
# Cargo features
|
||||
++ lib.optional withNotmuch pkgs.notmuch
|
||||
++ lib.optional withGpg pkgs.gpgme
|
||||
++ lib.optional withOpenSsl pkgs.openssl;
|
||||
}
|
||||
pimalaya.mkShell ({ rustToolchainFile = ./rust-toolchain.toml; }
|
||||
// removeAttrs args [ "pimalaya" ])
|
||||
|
||||
Reference in New Issue
Block a user