diff --git a/flake.lock b/flake.lock index 75786d1f8..020e0ac4f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,61 +1,94 @@ { "nodes": { - "fenix": { + "crane": { + "locked": { + "lastModified": 1737689766, + "narHash": "sha256-ivVXYaYlShxYoKfSo5+y5930qMKKJ8CLcAoIBPQfJ6s=", + "owner": "ipetkov", + "repo": "crane", + "rev": "6fe74265bbb6d016d663b1091f015e2976c4a527", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" + "systems": "systems" }, "locked": { - "lastModified": 1721111394, - "narHash": "sha256-hCN0NCmqPdosiyGt2thVRqg9ltctTROzGAoMq57QXPs=", - "owner": "nix-community", - "repo": "fenix", - "rev": "e63599e3186cfb3284933bc815d33a509addd00e", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "fenix", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1720910238, - "narHash": "sha256-J/IAXi62ICt+K4UTM9l/IGe2HtepKL46rot4NnQBpg8=", + "lastModified": 1737885589, + "narHash": "sha256-Zf0hSrtzaM1DEz8//+Xs51k/wdSajticVrATqDrfQjg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "76069dafc9c020a9bead5e6858f0fe791e04d068", + "rev": "852ff1d9e153d8875a83602e03fdef8a63f0ecf8", "type": "github" }, "original": { "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "fenix": "fenix", - "nixpkgs": "nixpkgs" + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737944843, + "narHash": "sha256-ZSXR/po/slqpsk3JLVjXbE04Vqrb4k7yCGHjyMj3tOk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "27bb917a41480b6ceee8e42d32dfcc9ecc6fa6c6", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, - "rust-analyzer-src": { - "flake": false, + "systems": { "locked": { - "lastModified": 1721048109, - "narHash": "sha256-X3tDuTPGKrAzTeQ9mkaGZL6srpsVEbZGW9PVdOLgfJo=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "0c95aaa08e5f870d269f0ca13010eda9a4dc3402", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", + "owner": "nix-systems", + "repo": "default", "type": "github" } } diff --git a/flake.nix b/flake.nix index ce9dca12d..b5b0ee572 100644 --- a/flake.nix +++ b/flake.nix @@ -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 + ]; + }; } ); - }; }