diff --git a/README.md b/README.md index 48f6893..a1e3462 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,14 @@ A native and a cross platform guide for BQN array programming language. > cargo run --release ``` +Alternatively, a nix flake is provided: + +``` console +$ git clone https://github.com/x86y/beacon +$ cd beacon +$ nix run # Alternatively: nix develop -c cargo run --release +``` + ## Windows instructions ```sh > git clone https://github.com/x86y/beacon diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..25a19de --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1701220101, + "narHash": "sha256-EBuCZ/Vjp3ovx8ZvfALfuUk4/76Ey/6cJmzmeXBRmDk=", + "owner": "ipetkov", + "repo": "crane", + "rev": "514cd663e5af505a244e55ad013733638574aff9", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701068326, + "narHash": "sha256-vmMceA+q6hG1yrjb+MP8T0YFDQIrW3bl45e7z24IEts=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8cfef6986adfb599ba379ae53c9f5631ecd2fd9c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..52f554b --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, flake-utils, crane, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + + buildInputs = with pkgs; [ + cbqn + xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr + ]; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + + beacon = crane.lib.${system}.buildPackage { + inherit buildInputs; + src = pkgs.lib.cleanSourceWith { + src = ./.; + filter = path: type: + (pkgs.lib.hasInfix "/src/" path) + || (crane.lib.${system}.filterCargoSources path type); + }; + }; + in + with pkgs; { + + # nix build, nix run, … + packages = { + inherit beacon; + default = pkgs.symlinkJoin { + name = "beacon"; + paths = [ beacon ]; + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/beacon \ + --prefix LD_LIBRARY_PATH : "${LD_LIBRARY_PATH}" + ''; + cargoExtraArgs = "--release"; + }; + }; + + # nix develop + devShells.default = mkShell { + inherit LD_LIBRARY_PATH; + buildInputs = buildInputs ++ [ cargo rustc rust-analyzer ]; + }; + } + ); +}