diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1da3a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +.direnv \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..aca5a3a --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1741006840, + "narHash": "sha256-/PLl/bBq+fdNR0mLFeIdEgh0O4URobH0R9+InbpdGhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "95eacfb6d1accf8d59a9e570d26d04ad693d2ec3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1735554305, + "narHash": "sha256-zExSA1i/b+1NMRhGGLtNfFGXgLtgo+dcuzHzaWA6w3Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e82ab234249d8eee3e8c91437802b32c74bb3fd", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1739829690, + "narHash": "sha256-mL1szCeIsjh6Khn3nH2cYtwO5YXG6gBiTw1A30iGeDU=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "3d0579f5cc93436052d94b73925b48973a104204", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a904807 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = + { + self, + nixpkgs, + treefmt-nix, + utils, + ... + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + inherit (pkgs) mkShell; + in + rec { + formatter = treefmtEval.config.build.wrapper; + devShell = mkShell { + nativeBuildInputs = with pkgs; [ + tokei + nil + ]; + }; + + packages.lmxg-mu50 = pkgs.callPackage ./package.nix { }; + defaultPackage = packages.lmxg-mu50; + } + ); +} diff --git a/lmxg-mu50 b/lmxg-mu50 new file mode 100644 index 0000000..4e0a28d --- /dev/null +++ b/lmxg-mu50 @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +PACKAGE_DIR="@DIR@/share/mame/assets/mu50" +WORKDIR="$XDG_DATA_HOME/lmxg-mu50" +MAME_BIN=`which mame` +MIDI_PORT="Midi Through Port-0" + +mkdir -p $WORKDIR && cd $WORKDIR + +first_run_check () { + ROMDIR="roms/" + [ -d "$ROMDIR" ] || ( mkdir -p $ROMDIR && cp -r $PACKAGE_DIR $ROMDIR ) +} + +main() { + first_run_check + "$MAME_BIN" mu50 -w -midiin "$MIDI_PORT" +} + +main \ No newline at end of file diff --git a/lmxg-mu50.desktop b/lmxg-mu50.desktop new file mode 100644 index 0000000..6759581 --- /dev/null +++ b/lmxg-mu50.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Terminal=false +Exec=@EXEC +Icon=lmxg-mu50 +Name=LMXG-MU50 +Comment=Run mu50 in mame; +Comment[zh_CN]=在 mame 中运行 mu50; +Categories=Multimedia; \ No newline at end of file diff --git a/lmxg-mu50.png b/lmxg-mu50.png new file mode 100644 index 0000000..4a8b76b Binary files /dev/null and b/lmxg-mu50.png differ diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..81dd328 --- /dev/null +++ b/package.nix @@ -0,0 +1,59 @@ +{ + stdenv, + fetchurl, + + # dependencies + mame, + which, + p7zip, + ... +}: +let + bin = ./lmxg-mu50; + desktop = ./lmxg-mu50.desktop; + icon = ./lmxg-mu50.png; +in +stdenv.mkDerivation rec { + pname = "lmxg-mu50"; + version = "0.1.0"; + + src = fetchurl { + url = "https://mdk.cab/download/nonmerged/mu50"; + sha256 = "sha256-0hzR2EWmamLJrqJ6cXaReEgd8Ha4Sf7LENpIYqcbCgs="; + }; + + nativeBuildInputs = [ + p7zip + ]; + + buildInputs = [ + mame + which + ]; + + phases = [ + "unpackPhase" + "installPhase" + ]; + + unpackPhase = '' + mkdir -p mu50 + cd mu50 + 7z x $src + cd ../ + ''; + + installPhase = '' + mkdir -p $out/bin + cat ${bin} | sed "s|@DIR@|$out|" > $out/bin/${pname} + chmod +x $out/bin/${pname} + mkdir -p $out/share/applications + cat ${desktop} | sed "s|@EXEC@|$out/bin/${pname}|" > $out/share/applications/${pname}.desktop + mkdir -p $out/share/pixmaps + cp ${icon} $out/share/pixmaps/${pname}.png + + mkdir -p $out/share/mame/assets/mu50 + + cp -r /build/mu50 $out/share/mame/assets/ + ''; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..2e3d471 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,4 @@ +{ + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; +}