diff --git a/templates/rust-app/default.nix b/templates/rust-app/default.nix deleted file mode 100644 index c715365b..00000000 --- a/templates/rust-app/default.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ lib -, rustPlatform -, meson -, ninja -, pkg-config -}: - -rustPlatform.buildRustPackage { - pname = "app"; - version = "VERSION"; - - src = lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.unions [ - ./Cargo.lock - ./Cargo.toml - ./LICENSE - ./meson.build - ./meson_options.txt - ./src - ]; - }; - - cargoLock.lockFile = ./Cargo.lock; - - nativeBuildInputs = [ - meson - ninja - pkg-config - ]; - - meta = with lib; { - description = "Rust app"; - mainProgram = "app"; - platforms = platforms.unix; - }; -} diff --git a/templates/rust-app/flake.nix b/templates/rust-app/flake.nix index 4a2d0bc8..9f38696c 100644 --- a/templates/rust-app/flake.nix +++ b/templates/rust-app/flake.nix @@ -1,42 +1,20 @@ { - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rust-overlay.url = "github:oxalica/rust-overlay"; - }; + description = "Basic Rust app development flake"; - outputs = { self, nixpkgs, ... }@inputs: + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { nixpkgs, ... }: let inherit (nixpkgs) lib; systems = [ "x86_64-linux" ]; forAllSystems = f: lib.genAttrs systems (system: f system); - in - { - devShells = forAllSystems - (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - inputs.rust-overlay.overlays.default - ]; - }; - in - { - default = import ./shell.nix { inherit pkgs; }; - }); + in { + devShells = forAllSystems (system: + let pkgs = import nixpkgs { inherit system; }; + in { default = import ./nix/shell.nix { inherit pkgs; }; }); - packages = forAllSystems - (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - inputs.rust-overlay.overlays.default - ]; - }; - in - { - default = pkgs.callPackage ./. { }; - }); + packages = forAllSystems (system: + let pkgs = import nixpkgs { inherit system; }; + in { default = pkgs.callPackage ./nix/package.nix { }; }); }; } diff --git a/templates/rust-app/nix/default.nix b/templates/rust-app/nix/default.nix new file mode 100644 index 00000000..7e97d101 --- /dev/null +++ b/templates/rust-app/nix/default.nix @@ -0,0 +1,3 @@ +{ pkgs ? import { } }: + +pkgs.callPackage ./package.nix { } diff --git a/templates/rust-app/nix/package.nix b/templates/rust-app/nix/package.nix new file mode 100644 index 00000000..bd6bdda1 --- /dev/null +++ b/templates/rust-app/nix/package.nix @@ -0,0 +1,23 @@ +{ lib, stdenv, rustPlatform, cargo, rustc, meson, ninja, pkg-config }: + +let metadata = lib.importTOML ../Cargo.toml; +in stdenv.mkDerivation (finalAttrs: { + pname = metadata.package.name; + version = metadata.package.version; + + src = lib.fileset.toSource { + root = ../.; + fileset = + lib.fileset.unions [ ../Cargo.lock ../Cargo.toml ../src ../meson.build ]; + }; + + nativeBuildInputs = + [ meson ninja pkg-config rustPlatform.cargoSetupHook cargo rustc ]; + + meta = with lib; { + description = metadata.package.description; + mainProgram = metadata.package.name; + platforms = platforms.unix; + license = with licenses; [ ]; + }; +}) diff --git a/templates/rust-app/nix/shell.nix b/templates/rust-app/nix/shell.nix new file mode 100644 index 00000000..a0aef9cf --- /dev/null +++ b/templates/rust-app/nix/shell.nix @@ -0,0 +1,18 @@ +{ pkgs ? import { } }: + +let app = pkgs.callPackage ./package.nix { }; +in pkgs.mkShell { + inputsFrom = [ app ]; + + # The rest of the development-related packages should be here. + packages = with pkgs; [ + direnv + clippy + rust-analyzer + + # The formatters used in this project. + treefmt # The universal formatter (if configured nicely). + nixfmt # The universal Nix formatter. + rustfmt # The universal Rust formatter. + ]; +}