From c8a66c643afe2d0a2da55eac537b13a466c242c2 Mon Sep 17 00:00:00 2001 From: tzlil Date: Tue, 21 Mar 2023 12:56:39 +0200 Subject: reading section names --- flake.nix | 91 ++++++++++++++++++++++++++------------------------------------- 1 file changed, 37 insertions(+), 54 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index fafb6ca..b8230de 100644 --- a/flake.nix +++ b/flake.nix @@ -1,64 +1,47 @@ - { - # XXX: Change project description - description = "Rust project"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; - outputs = { self, nixpkgs, fenix, flake-utils }: - flake-utils.lib.eachDefaultSystem - (system: - let - pkgs = nixpkgs.legacyPackages."${system}"; + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" ]; + imports = [ inputs.treefmt-nix.flakeModule ]; - # XXX: Change target platform - rust-target = "x86_64-unknown-linux-gnu"; - rust-toolchain = with fenix.packages."${system}"; let - rust-toolchain-spec = { - # XXX: Change compiler version - # see `toolchainOf` https://github.com/nix-community/fenix - # for supported options - channel = "nightly"; - sha256 = "sha256-xdqN1O2O9GJ+Jg/Gsdj2Hra1KFQIQpAu4vGczSBsLDo="; - }; - # Toolchain for the builder - host-toolchain = toolchainOf rust-toolchain-spec; - # Toolchain for the platform where the binary will run - # target-toolchain = targets."${rust-target}".toolchainOf rust-toolchain-spec; - in - combine [ - # Build tools are taken from the host - host-toolchain.rustc - host-toolchain.cargo - host-toolchain.clippy - host-toolchain.rust-docs - # Standard library is taken from the target - host-toolchain.rust-std - host-toolchain.rust-src - ]; + perSystem = { pkgs, lib, config, ... }: + let + src = lib.sourceFilesBySuffices inputs.self [ ".rs" ".toml" "Cargo.lock" ]; + inherit (lib.importTOML (src + "/Cargo.toml")) package; in { - devShells.default = pkgs.mkShell { - # XXX: Change to project name - name = "rust-project"; + packages = { + ${package.name} = pkgs.rustPlatform.buildRustPackage { + pname = package.name; + inherit (package) version; + inherit src; + cargoLock.lockFile = (src + "/Cargo.lock"); + }; + default = config.packages.${package.name}; + }; - # Build tools - nativeBuildInputs = with pkgs; [ - rust-toolchain - rust-analyzer - rustfmt - ]; + devShells = { + ${package.name} = pkgs.mkShell { + inherit (package) name; + inputsFrom = [ config.packages.${package.name} ]; + packages = with pkgs; [ + rust-analyzer + ]; + }; + default = config.devShells.${package.name}; + }; - RUST_BACKTRACE = 1; - # CARGO_BUILD_TARGET = rust-target; + treefmt = { + projectRootFile = "flake.nix"; + programs.nixpkgs-fmt.enable = true; + programs.rustfmt.enable = true; }; - devShell = self.devShells."${system}".default; - }); -} \ No newline at end of file + }; + }; +} -- cgit 1.4.1