Files
MusicFS/devenv.nix
T
2026-07-25 12:44:06 +02:00

140 lines
3.6 KiB
Nix

{
pkgs,
lib,
config,
inputs,
...
}:
let
# devenv's `languages.rust.import` only builds single root-package crates
# (it hardcodes `cargoNix.rootCrate.build`). musicfs is a virtual workspace with
# no root package, so we drive crate2nix directly and select the `musicfs-client`
# member out of `workspaceMembers`. src = ./. gives crate2nix the whole workspace,
# so the member's path-dependencies (musicfs-core, musicfs-proto) resolve.
crate2nixTools = pkgs.callPackage "${inputs.crate2nix}/tools.nix" { };
cargoNix =
pkgs.callPackage
(crate2nixTools.generatedCargoNix {
name = "musicfs";
src = ./.;
})
{
# Build with the toolchain configured for this dev environment,
# matching what languages.rust.import does internally.
buildRustCrateForPkgs =
_:
pkgs.buildRustCrate.override {
rustc = config.languages.rust.toolchainPackage;
cargo = config.languages.rust.toolchainPackage;
};
};
# musicfs-client's binary is named `musicfs` (see [[bin]] in its Cargo.toml).
musicfs = cargoNix.workspaceMembers."musicfs-client".build;
in
{
languages.rust.enable = true;
git-hooks.hooks = {
clippy = {
enable = true;
settings.allFeatures = true;
};
treefmt.enable = true;
};
treefmt = {
enable = true;
config.programs = {
nixfmt.enable = true;
rustfmt.enable = true;
};
};
packages = with pkgs; [
git
just
flac
ffmpeg
id3v2
mpv
protobuf
buf
grpcurl
opencode
inputs.pinix.packages.${pkgs.system}.default
];
processes.musicfs = {
after = [ "devenv:processes:postgres" ];
exec = lib.mkDefault ''
${musicfs}/bin/musicfs \
--source /home/fujin/Music \
--mountpoint /tmp/rust-fuse \
--database "postgresql://fujin@localhost/musicfs?host=$PGHOST"
'';
# Probes the standard gRPC Health Checking Protocol exposed on the
# musicfs-client status server (default --listen 127.0.0.1:50052).
# SERVING implies the FUSE mount succeeded and, for NetworkOrigin, the
# upstream musicfs-server is reachable (health.rs toggles not_serving on
# upstream loss). Inherited by profiles.* since they only override `exec`.
ready.exec = "grpcurl -plaintext -max-time 2 127.0.0.1:50052 grpc.health.v1.Health/Check | grep -q SERVING";
};
profiles.local.module = {
processes.musicfs = {
after = [ "devenv:processes:postgres" ];
exec = ''
${musicfs}/bin/musicfs \
--source /home/fujin/Music \
--mountpoint /tmp/rust-fuse \
--database "postgresql://fujin@localhost/musicfs?host=$PGHOST"
'';
};
};
profiles.remote.module = {
processes.musicfs = {
after = [ "devenv:processes:postgres" ];
exec = ''
${musicfs}/bin/musicfs \
--source http://10.185.226.145:50051 \
--mountpoint /tmp/rust-fuse \
--database "postgresql://fujin@localhost/musicfs?host=$PGHOST"
'';
};
};
profiles.e2e.module = {
processes.musicfs = {
after = [ "devenv:processes:postgres" ];
exec = ''
${musicfs}/bin/musicfs \
--source http://127.0.0.1:50061 \
--mountpoint ./target/e2e/mnt \
--database "postgresql://fujin@localhost/musicfs_e2e?host=$PGHOST" \
--log-dir ./logs/e2e
'';
};
};
services.postgres = {
enable = true;
initialDatabases = [
{
name = "musicfs";
schema = ./db/schema.sql;
}
{
name = "musicfs_e2e";
schema = ./db/schema.sql;
}
];
};
outputs = {
musicfs = musicfs;
};
}