Skip to content

Commit

Permalink
Merge 'Full flake overhaul' from Levy A.
Browse files Browse the repository at this point in the history
Improvements:
- Use [rust-overlay](https://github.com/oxalica/rust-overlay), better
maintained than fenix and allows for:
- Use `rust-toolchain.toml` as the source of truth for the current rust
version, instead of tracking with stable. Preventing conflicting
versions with non-nix users.
- Add flake checks, could be useful for CI in the future, together with
crane and cachix.
- Add package, allow people to add limbo as a regular nix package. Now
we can `nix build .#`, `nix run .#` and `nix shell .#` (this one adds
`limbo` to the current `PATH`)
- Use [new `apple-sdk` pattern](https://discourse.nixos.org/t/the-
darwin-sdks-have-been-updated/55295), no need to declare each framework
now.

Closes #835
  • Loading branch information
penberg committed Feb 1, 2025
2 parents a450b5c + 04c4cbe commit 51f0c9e
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 66 deletions.
87 changes: 60 additions & 27 deletions flake.lock

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

103 changes: 64 additions & 39 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,48 +1,73 @@
{
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
nixpkgs,
fenix,
...
}: let
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs systems;
in {
devShells = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
rustStable = fenix.packages.${system}.stable.toolchain;
wasmTarget = fenix.packages.${system}.targets.wasm32-wasi.latest.rust-std;
extraDarwinInputs =
if pkgs.stdenv.isDarwin
then [pkgs.darwin.apple_sdk.frameworks.CoreFoundation]
else [];
in {
default = with pkgs;
mkShell {
buildInputs =
[
clang
libiconv
sqlite
gnumake
rustup # not used to install the toolchain, but the makefile uses it
rustStable
wasmTarget
tcl
]
++ extraDarwinInputs;
};
outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};

toolchain = break ((pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-analyzer" "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
});

lib = pkgs.lib;

cargoArtifacts = craneLib.buildDepsOnly {
src = ./.;
pname = "limbo";
stritcDeps = true;
nativeBuildInputs = with pkgs; [ python3 ];
};

commonArgs = {
inherit cargoArtifacts;
pname = "limbo";
src = ./.;
nativeBuildInputs = with pkgs; [ python3 ];
strictDeps = true;
};

craneLib = ((crane.mkLib pkgs).overrideToolchain toolchain);
in
rec {
formatter = pkgs.nixpkgs-fmt;
checks = {
doc = craneLib.cargoDoc commonArgs;
fmt = craneLib.cargoFmt commonArgs;
clippy = craneLib.cargoClippy (commonArgs // {
# TODO: maybe add `-- --deny warnings`
cargoClippyExtraArgs = "--all-targets";
});
};
packages.limbo = craneLib.buildPackage (commonArgs // {
cargoExtraArgs = "--bin limbo";
});
packages.default = packages.limbo;
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [
clang
sqlite
gnumake
tcl
python3
nodejs
toolchain
] ++ lib.optionals pkgs.stdenv.isDarwin [
apple-sdk
];
};
}
);
};
}

0 comments on commit 51f0c9e

Please sign in to comment.