From 413d8a9925e70c89902fc55d76890637b2bcf95c Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 20 Oct 2022 13:22:58 +0300 Subject: [PATCH] rust: change default rust flake --- flakes/rust/flake.nix | 59 +++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/flakes/rust/flake.nix b/flakes/rust/flake.nix index d477620..216c050 100644 --- a/flakes/rust/flake.nix +++ b/flakes/rust/flake.nix @@ -1,31 +1,58 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - utils.url = "github:numtide/flake-utils"; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, utils }: - utils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flake-utils }: + let + inherit (builtins) fromTOML readFile substring; + + cargoToml = fromTOML (readFile ./Cargo.toml); + version = "${cargoToml.package.version}+${substring 0 8 self.lastModifiedDate}_${self.shortRev or "dirty"}"; + + # FIXME: rename mkHello + mkHello = { lib, rustPlatform, ... }: + rustPlatform.buildRustPackage { + pname = cargoToml.package.name; + inherit version; + + src = lib.cleanSource ./.; + cargoLock.lockFile = ./Cargo.lock; + + doCheck = true; + }; + in + { + # FIXME: rename hello overlay with package name + overlays.hello = final: prev: { + hello = prev.callPackage mkHello; + }; + overlays.default = self.overlays.hello; + } + // + flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - cargoToml = with builtins; (fromTOML (readFile ./Cargo.toml)); + # FIXME: rename hello + hello = pkgs.callPackage mkHello { }; in - rec { - packages.default = pkgs.rustPlatform.buildRustPackage { - inherit (cargoToml.package) name version; - src = nixpkgs.lib.cleanSource ./.; - doCheck = true; - cargoLock.lockFile = ./Cargo.lock; + { + packages = { + inherit hello; + default = hello; }; - apps.default = utils.lib.mkApp { - inherit (cargoToml.package) name; - drv = packages.default; + # FIXME: rename hello app with program path + apps.hello = { + type = "app"; + program = "${hello}/bin/hello"; }; + apps.default = self.apps.${system}.hello; - devShell = with pkgs; mkShell { - packages = [ cargo rustc rustfmt clippy rust-analyzer ]; - RUST_SRC_PATH = rustPlatform.rustLibSrc; + devShell = pkgs.mkShell { + packages = with pkgs; [ cargo rustc rustfmt clippy rust-analyzer ]; + RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; }; }); }