diff --git a/flake.lock b/flake.lock index c53a6d12..5efc81c3 100644 --- a/flake.lock +++ b/flake.lock @@ -18,18 +18,23 @@ "type": "github" } }, - "import-cargo": { + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1594305518, - "narHash": "sha256-frtArgN42rSaEcEOYWg8sVPMUK+Zgch3c+wejcpX3DY=", - "owner": "edolstra", - "repo": "import-cargo", - "rev": "25d40be4a73d40a2572e0cc233b83253554f06c5", + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "import-cargo", + "owner": "nix-community", + "repo": "naersk", "type": "github" } }, @@ -52,32 +57,8 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "import-cargo": "import-cargo", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "flake-utils": [ - "flake-utils" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1715652909, - "narHash": "sha256-aCLEDvzL1j51Rf2mCFOqK1mieMO3pAn5ItCIdr5h2LA=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "1d8fcbbfcfd3476c2665384a46ee9d07ef2b4dd9", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" + "naersk": "naersk", + "nixpkgs": "nixpkgs" } }, "systems": { diff --git a/flake.nix b/flake.nix index 5f0507e6..5c4eb96e 100644 --- a/flake.nix +++ b/flake.nix @@ -6,50 +6,20 @@ flake-utils.url = "github:numtide/flake-utils"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "flake-utils"; - }; - import-cargo.url = "github:edolstra/import-cargo"; + naersk.url = "github:nix-community/naersk"; + naersk.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils, rust-overlay, import-cargo, ... }: + outputs = { self, nixpkgs, flake-utils, naersk, ... }: flake-utils.lib.eachDefaultSystem (system: let - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { inherit system overlays; }; - rustVersion = pkgs.rust-bin.stable.latest.default.override { - targets = [ "x86_64-unknown-linux-musl" ]; - }; - inherit (import-cargo.builders) importCargo; - - nativeBuildInputs = with pkgs; [ pkg-config rustVersion ]; - - buildInputs = with pkgs; [ ]; - - fastside = pkgs.stdenv.mkDerivation { - pname = "fastside"; - version = "0.2.0"; - - src = self; - - inherit buildInputs; + pkgs = import nixpkgs { inherit system; }; + naersk' = pkgs.callPackage naersk { }; - nativeBuildInputs = [ - (importCargo { - lockFile = ./Cargo.lock; - inherit pkgs; - }).cargoHome - ] ++ nativeBuildInputs; - - buildPhase = '' - cargo build --release --offline --target x86_64-unknown-linux-musl - ''; - - installPhase = '' - install -Dm775 ./target/x86_64-unknown-linux-musl/release/fastside $out/bin/fastside - ''; + fastside = naersk'.buildPackage { + src = ./.; + nativeBuildInputs = with pkgs; [ mold ]; + NIX_CFLAGS_LINK = " -fuse-ld=mold"; }; fastside-docker = pkgs.dockerTools.buildLayeredImage { @@ -63,14 +33,11 @@ default = fastside; fastside = fastside; fastside-docker = fastside-docker; - services = pkgs.runCommand "generate-services" {} '' + services = pkgs.runCommand "generate-services" { } '' cat '${./services.json}' > $out ''; }; - devShells.default = pkgs.mkShell { - buildInputs = (with pkgs; [ nixfmt ]) ++ nativeBuildInputs - ++ buildInputs; - }; + devShells.default = import ./shell.nix { inherit pkgs; }; }); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..11e64574 --- /dev/null +++ b/shell.nix @@ -0,0 +1,17 @@ +{ channel ? "stable", profile ? "default", pkgs ? import }: +let + pkgs' = pkgs.extend (import (builtins.fetchTarball { + url = + "https://github.com/oxalica/rust-overlay/archive/9803f6e04ca37a2c072783e8297d2080f8d0e739.tar.gz"; + sha256 = "1b566msx04y4s0hvwsza9gcv4djmni4fa6ik7q2m33b6x4vrb92w"; + })); +in pkgs'.mkShell { + nativeBuildInputs = with pkgs'; [ + nixfmt-classic + # Rust + (if channel == "nightly" then + rust-bin.selectLatestNightlyWith (toolchain: toolchain.${profile}) + else + rust-bin.${channel}.latest.${profile}) + ]; +}