Skip to content

Commit

Permalink
refactor: remove cranix from nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Oct 22, 2024
1 parent 17ae3cd commit a9efac9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 120 deletions.
78 changes: 4 additions & 74 deletions flake.lock

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

46 changes: 18 additions & 28 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,41 @@
description = "Standar cross compile flake for Rust Lang Projects";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
cranix.url = "github:Lemin-n/cranix/2af6b2e71577bb8836b10e28f3267f2c5342a8fd";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs:
# Iterate over Arm, x86 for MacOs 🍎 and Linux 🐧
flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems) (
system: let
pkgs = nixpkgs.legacyPackages.${system};
crane = inputs.crane.mkLib pkgs;
fenix = inputs.fenix.packages;
sssBundle = import ./nix {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
crane = inputs.crane.lib;
cranix = inputs.cranix.lib;
fenix = inputs.fenix.packages;
inherit system pkgs crane fenix;
};
in {
inherit (sssBundle) apps packages devShells;
}
)
// {
# Overlays
overlays.default = import ./nix/overlay.nix {
crane = inputs.crane.lib;
cranix = inputs.cranix.lib;
fenix = inputs.fenix.packages;
};
# nixosModules
nixosModules = {
default = import ./nix/nixos-module.nix {
crane = inputs.crane.lib;
cranix = inputs.cranix.lib;
fenix = inputs.fenix.packages;

# Overlays
overlays = import ./nix/overlay.nix {
inherit crane fenix;
};
home-manager = import ./nix/hm-module.nix {
crane = inputs.crane.lib;
cranix = inputs.cranix.lib;
fenix = inputs.fenix.packages;
# nixosModules
nixosModules = {
default = import ./nix/nixos-module.nix {
inherit crane fenix;
};
home-manager = import ./nix/hm-module.nix {
inherit crane fenix;
};
};
};
};
}
);
}
31 changes: 15 additions & 16 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ in
pkgs ? import (getFlake "nixpkgs") {localSystem = {inherit system;};},
lib ? pkgs.lib,
crane,
cranix,
fenix,
stdenv ? pkgs.stdenv,
...
Expand All @@ -30,9 +29,7 @@ in
sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk=";
};
# crane: cargo and artifacts manager
craneLib = crane.${system}.overrideToolchain toolchain;
# cranix: extends crane building system with workspace bin building and Mold + Cranelift integrations
cranixLib = craneLib.overrideScope (cranix.${system}.craneOverride);
craneLib = crane.overrideToolchain toolchain;

# buildInputs for SSS
buildInputs = with pkgs; [
Expand All @@ -46,30 +43,34 @@ in
src = ./..;
doCheck = false;
nativeBuildInputs =
[pkgs.pkg-config]
[ pkgs.pkg-config ]
++ lib.optionals stdenv.buildPlatform.isDarwin [
pkgs.libiconv
];
inherit buildInputs;
};

# sss artifacts
sssDeps = cranixLib.buildCranixDepsOnly commonArgs;
sssDeps = craneLib.buildDepsOnly commonArgs;

# Lambda for build packages with cached artifacts
packageArgs = targetName:
commonArgs
// {
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64";
HOST_CC = "${stdenv.cc.nativePrefix}cc";
cargoArtifacts = sssDeps;
workspaceTargetName = targetName;
};

genBuild = name: rec {
pkg = craneLib.buildPackage (packageArgs name);
app = {
type = "app";
program = "${pkg}${pkg.passthru.exePath or "/bin/${pkg.pname or pkg.name}"}";
};
};
# Build packages and `nix run` apps
sss = cranixLib.buildCranixBundle (packageArgs "sss");
sssCode = cranixLib.buildCranixBundle (packageArgs "sss_code");
sss = genBuild "sss";
sssCode = genBuild "sss_code";
in {
# `nix run`
apps = rec {
Expand All @@ -84,16 +85,14 @@ in
default = cli;
};
# `nix develop`
devShells.default = cranixLib.devShell {
packages = with pkgs;
[
devShells.default = craneLib.devShell {
packages = with pkgs; [
toolchain
pkg-config
oranda
cargo-dist
cargo-release
]
++ buildInputs;
] ++ buildInputs;
PKG_CONFIG_PATH = "${pkgs.fontconfig.dev}/lib/pkgconfig";
};
}
3 changes: 1 addition & 2 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
crane,
cranix,
fenix,
}: final: prev: let
sss = prev.callPackage ./. {inherit crane cranix fenix;};
sss = prev.callPackage ./. {inherit crane fenix;};
in {
sss = sss.packages.default;
sssCode = sss.packages.code;
Expand Down

0 comments on commit a9efac9

Please sign in to comment.