diff --git a/.gitignore b/.gitignore index a0f9dda..cb26143 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ nimcache/ demo.png/ diag.png/ diag.tape + +# Nix +result +result-* \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..dfdfdf9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1776548001, + "narHash": "sha256-ZSK0NL4a1BwVbbTBoSnWgbJy9HeZFXLYQizjb2DPF24=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b12141ef619e0a9c1c84dc8c684040326f27cdcc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7be3e65 --- /dev/null +++ b/flake.nix @@ -0,0 +1,116 @@ +{ + description = "Terminal oscilloscope with CRT phosphor rendering"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + lib = nixpkgs.lib; + + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + forAllSystems = lib.genAttrs systems; + + mkPkgs = system: + import nixpkgs { inherit system; }; + in + { + packages = forAllSystems (system: + let + pkgs = mkPkgs system; + ffmpegForOsc = pkgs.ffmpeg-full; + runtimeLibraryPath = lib.makeLibraryPath [ ffmpegForOsc ]; + in + { + default = pkgs.stdenv.mkDerivation { + pname = "terminal-oscilloscope"; + version = "0.1.0"; + + src = ./.; + + nativeBuildInputs = [ + pkgs.nim + pkgs.makeWrapper + ]; + + buildInputs = [ + ffmpegForOsc + ]; + + buildPhase = '' + runHook preBuild + + nim c -d:release --threads:on --nimcache:$TMPDIR/nimcache-osc_braille -o:osc_braille src/osc_braille.nim + nim c -d:release --threads:on --nimcache:$TMPDIR/nimcache-osc_braille -o:osc src/osc.nim + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -Dm755 osc $out/bin/osc-unwrapped + install -Dm755 osc_braille $out/bin/osc_braille-unwrapped + + makeWrapper $out/bin/osc-unwrapped $out/bin/osc \ + --prefix LD_LIBRARY_PATH : ${runtimeLibraryPath} + + makeWrapper $out/bin/osc_braille-unwrapped $out/bin/osc_braille \ + --prefix LD_LIBRARY_PATH : ${runtimeLibraryPath} + + runHook postInstall + ''; + + meta = { + description = "Terminal oscilloscope with CRT phosphor rendering"; + mainProgram = "osc"; + platforms = lib.platforms.linux; + }; + }; + }); + + apps = forAllSystems (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/osc"; + }; + + osc = { + type = "app"; + program = "${self.packages.${system}.default}/bin/osc"; + }; + + osc_braille = { + type = "app"; + program = "${self.packages.${system}.default}/bin/osc_braille"; + }; + }); + + devShells = forAllSystems (system: + let + pkgs = mkPkgs system; + ffmpegForOsc = pkgs.ffmpeg-full; + runtimeLibraryPath = lib.makeLibraryPath [ ffmpegForOsc ]; + in + { + default = pkgs.mkShell { + packages = [ + pkgs.nim + pkgs.nimble + pkgs.pkg-config + ffmpegForOsc + ]; + + shellHook = '' + export LD_LIBRARY_PATH=${runtimeLibraryPath}:''${LD_LIBRARY_PATH:-} + ''; + }; + }); + }; +} \ No newline at end of file