From 435d7a04074251773de072d552f3d2ca3315b5f8 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 12 Sep 2024 01:13:32 -0700 Subject: [PATCH] nix: switch to naersk rust infrastructure --- flake.lock | 37 ++++++++++++++++++++++++++++++++++--- flake.nix | 33 ++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/flake.lock b/flake.lock index 0ae0c90..5c029dc 100644 --- a/flake.lock +++ b/flake.lock @@ -18,7 +18,37 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=", + "path": "/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1725634671, "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=", @@ -34,7 +64,7 @@ "type": "github" } }, - "nixpkgs_2": { + "nixpkgs_3": { "locked": { "lastModified": 1718428119, "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", @@ -53,13 +83,14 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1726021481, diff --git a/flake.nix b/flake.nix index 208129f..f60dfa6 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay.url = "github:oxalica/rust-overlay"; + naersk.url = "github:nix-community/naersk"; }; outputs = @@ -12,6 +13,7 @@ nixpkgs, flake-utils, rust-overlay, + naersk, ... }: flake-utils.lib.eachDefaultSystem ( @@ -19,6 +21,18 @@ let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; + naersk' = pkgs.callPackage naersk { }; + defaultBuildOpts = { + cargo = pkgs.rust-bin.stable.latest.default; + rustc = pkgs.rust-bin.stable.latest.default; + + src = ./.; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ openssl ]; + + mode = "build"; + }; in { devShells.default = pkgs.mkShell { @@ -30,17 +44,14 @@ rust-bin.stable.latest.rustfmt ]; }; - packages.default = pkgs.rustPlatform.buildRustPackage { - pname = "cartographer"; - version = "0.1.0"; - - src = ./.; - cargoHash = "sha256-6nqR5x34o8zCpNVp8NUC7+7j48rOkbHKJF9AU3bBs+c="; - # cargoHash = pkgs.lib.fakeHash; - - nativeBuildInputs = with pkgs; [ pkg-config ]; - buildInputs = with pkgs; [ openssl ]; - + packages = { + default = naersk'.buildPackage defaultBuildOpts; + test = naersk'.buildPackage ( + defaultBuildOpts + // { + mode = "test"; + } + ); }; } );