diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index aabbe8e7..3336c2bb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,6 +22,8 @@ jobs: with: release-type: elixir package-name: next_ls + extra-files: | + flake.nix # - uses: actions/checkout@v3 # if: ${{ steps.release.outputs.release_created }} diff --git a/.gitignore b/.gitignore index 658e3e00..548a7b33 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ next_ls-*.tar # Temporary files, for example, from tests. /tmp/ burrito_out +result # Ignore dialyzer plt files /priv/plts/*.plt diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..da22fe18 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1693362724, + "narHash": "sha256-4lxHe2ohW4CFa9rNHr9aRKkM6afEC3aqDxmOvnw+Oz4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "020300a756e75ea9ce86a8ab5ee259c31e28ed43", + "type": "github" + }, + "original": { + "owner": "NixOS", + "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 00000000..64861d89 --- /dev/null +++ b/flake.nix @@ -0,0 +1,102 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + }; + + outputs = { self, nixpkgs }: + let + # Systems supported + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + + pname = "next-ls"; + version = "0.10.4"; # x-release-please-version + src = ./.; + + # Helper to provide system-specific attributes + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + system = system; + }); + + burritoExe = system: + if system == "aarch64-darwin" then + "darwin_arm64" + else if system == "x86_64-darwin" then + "darwin_amd64" + else if system == "x86_64-linux" then + "linux_amd64" + else if system == "aarch64-linux" then + "linux_arm64" + else + ""; + in + { + packages = forAllSystems ({ pkgs, system }: + let + beamPackages = pkgs.beam.packages.erlang_26; + build = type: beamPackages.mixRelease { + inherit pname version src; + erlang = beamPackages.erlang; + elixir = beamPackages.elixir_1_15; + + nativeBuildInputs = [ pkgs.xz pkgs.zig_0_10 pkgs._7zz ]; + + mixFodDeps = beamPackages.fetchMixDeps { + inherit src version; + pname = "${pname}-deps"; + hash = "sha256-wweJ9+YuI+2ZdrWDgnMplAE7e538m1YoYRu8wKEPltQ="; + }; + + preConfigure = '' + bindir="$(pwd)/bin" + mkdir -p "$bindir" + echo '#!/usr/bin/env bash + 7zz "$@"' > "$bindir/7z" + chmod +x "$bindir/7z" + + export HOME="$(pwd)" + export PATH="$bindir:$PATH" + ''; + + preInstall = if type == "local" then '' + export BURRITO_TARGET="${burritoExe(system)}" + '' + else ""; + + postInstall = '' + cp -r ./burrito_out "$out" + ''; + }; + in + { + default = build("local"); + ci = build("ci"); + }); + + apps = forAllSystems ({ pkgs, system }: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/burrito_out/next_ls_${burritoExe(system)}"; + }; + }); + + devShells = forAllSystems ({ pkgs, ... }: + let + beamPackages = pkgs.beam.packages.erlang_26; + in + { + default = pkgs.mkShell { + # The Nix packages provided in the environment + packages = [ + beamPackages.erlang + beamPackages.elixir_1_15 + ]; + }; + }); + }; +}