Skip to content

Commit

Permalink
make use of pimalaya/nix
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Nov 28, 2024
1 parent 86baf1c commit f92b6a6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 202 deletions.
71 changes: 17 additions & 54 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 12 additions & 97 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
3 changes: 3 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO: move this to nixpkgs
# This file aims to be a replacement for the nixpkgs derivation.

{ lib
, pkg-config
, rustPlatform
Expand Down
24 changes: 0 additions & 24 deletions rust-toolchain.nix

This file was deleted.

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.82.0"
profile = "default"
components = [ "rust-src", "rust-analyzer" ]
components = ["rust-src", "rust-analyzer"]
30 changes: 5 additions & 25 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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" ])

0 comments on commit f92b6a6

Please sign in to comment.