87 lines
2.3 KiB
Nix
87 lines
2.3 KiB
Nix
{
|
|
description = "A Nix flake for the rate_music Rust project";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
crane.url = "github:ipetkov/crane";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
rust-overlay,
|
|
crane,
|
|
flake-utils,
|
|
...
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
overlays = [ (import rust-overlay) ];
|
|
pkgs = import nixpkgs { inherit system overlays; };
|
|
|
|
# 1. Define the Rust toolchain
|
|
rustToolchain = pkgs.rust-bin.stable.latest.default;
|
|
|
|
# 2. Configure crane to use our specific toolchain
|
|
craneLib = (crane.legal.lib.${system}).overrideToolchain rustToolchain;
|
|
|
|
# 3. Define common build inputs (system libraries)
|
|
# mpris and sqlx often need pkg-config and specific C libraries
|
|
nativeBuildInputs = with pkgs; [
|
|
pkg-config
|
|
rustToolchain
|
|
];
|
|
|
|
buildInputs =
|
|
with pkgs;
|
|
[
|
|
sqlite
|
|
openssl
|
|
dbus # Required by many mpris implementations
|
|
]
|
|
++ lib.optionals stdenv.isDarwin [
|
|
darwin.apple_sdk.frameworks.Security
|
|
darwin.apple_sdk.frameworks.SystemConfiguration
|
|
];
|
|
|
|
# 4. Build the project
|
|
# This splits the build into "deps" and "project" for better caching
|
|
commonArgs = {
|
|
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
|
strictDeps = true;
|
|
inherit buildInputs nativeBuildInputs;
|
|
};
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
rate_music = craneLib.buildPackage (
|
|
commonArgs
|
|
// {
|
|
inherit cargoArtifacts;
|
|
}
|
|
);
|
|
|
|
in
|
|
{
|
|
packages.default = rate_music;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
inputsFrom = [ rate_music ];
|
|
# Extra tools for development
|
|
nativeBuildInputs = with pkgs; [
|
|
rust-analyzer
|
|
sqlx-cli
|
|
];
|
|
|
|
# SQLX environment variable if you're using offline mode or a specific DB path
|
|
shellHook = ''
|
|
export DATABASE_URL="sqlite:./rate_music.db"
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
}
|