templates/rust-app: update

This commit is contained in:
Gabriel Arazas 2024-10-21 15:25:06 +08:00
parent aa52173af2
commit d704112695
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
5 changed files with 55 additions and 70 deletions

View File

@ -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;
};
}

View File

@ -1,42 +1,20 @@
{ {
inputs = { description = "Basic Rust app development flake";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, ... }@inputs: inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { nixpkgs, ... }:
let let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
forAllSystems = f: lib.genAttrs systems (system: f system); forAllSystems = f: lib.genAttrs systems (system: f system);
in in {
{ devShells = forAllSystems (system:
devShells = forAllSystems let pkgs = import nixpkgs { inherit system; };
(system: in { default = import ./nix/shell.nix { inherit pkgs; }; });
let
pkgs = import nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
];
};
in
{
default = import ./shell.nix { inherit pkgs; };
});
packages = forAllSystems packages = forAllSystems (system:
(system: let pkgs = import nixpkgs { inherit system; };
let in { default = pkgs.callPackage ./nix/package.nix { }; });
pkgs = import nixpkgs {
inherit system;
overlays = [
inputs.rust-overlay.overlays.default
];
};
in
{
default = pkgs.callPackage ./. { };
});
}; };
} }

View File

@ -0,0 +1,3 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.callPackage ./package.nix { }

View File

@ -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; [ ];
};
})

View File

@ -0,0 +1,18 @@
{ pkgs ? import <nixpkgs> { } }:
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.
];
}