-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(nix): improve flake and build in CI (#312)
* style(nix): centralise the specification of Erlang and Elixir versions * chore(nix): switch to nixos-unstable channel The master branch is where PRs are merged into. Binary cache is more likely available on stable and unstable branches, so switch to unstable to use latest packages. * chore(nix): downgrade to Erlang R25 to prevent rebuild of rebar3 In NixOS/nixpkgs, the latest version of BEAM packages may not have all packages built on Hydra. In fact, rebar3 is not available from binary cache, which requires the package user to rebuild the package. Downgrading to the previous version of Erlang VM solves this issue. * fix(nix): fix hash mismatch of mixFodDeps * fix(nix)!: remove the broken flake app The path points to a location which apparently no longer exists. * chore(nix): add meta data of the Nix package Setting meta.mainProgram is recommended now so `nix run` consistently works. * style(nix): Use a map to manage the platform mappings * style(nix): tidy preInstall and postInstall hooks * style(nix): tidy * feat(nix): make the Erlang and Elixir versions overridable The user may want to use the same versions as his/her project under development, so it makes sense to allow overriding of beamPackages and elixir. * fix(nix): fix installation on ARM64 Linux * fix(nix): Revert to Erlang R26 as it is a requirement * style(nix): apply alejandra formatter * ci: add nix builds * fix(nix): Use the same version of Elixir for fetchMixDeps * update hash * fix ci --------- Co-authored-by: Mitchell Hanberg <[email protected]>
- Loading branch information
Showing
3 changed files
with
116 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,116 @@ | ||
{ | ||
inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; }; | ||
inputs = {nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";}; | ||
|
||
outputs = { self, nixpkgs }: | ||
let | ||
lib = nixpkgs.lib; | ||
outputs = { | ||
self, | ||
nixpkgs, | ||
}: let | ||
inherit (nixpkgs) lib; | ||
|
||
# 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.14.2"; # x-release-please-version | ||
src = ./.; | ||
|
||
# Helper to provide system-specific attributes | ||
forAllSystems = f: | ||
nixpkgs.lib.genAttrs allSystems (system: | ||
let pkgs = import nixpkgs { inherit system; }; | ||
in f { | ||
inherit pkgs; | ||
# src = pkgs.fetchFromGitHub { | ||
# owner = "elixir-tools"; | ||
# repo = "next-ls"; | ||
# rev = "v${version}"; | ||
# sha256 = "sha256-jpOInsr7Le0fjJZToNNrlNyXNF1MtF1kQONXdC2VsV0="; | ||
# }; | ||
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 | ||
# Helper to provide system-specific attributes | ||
forAllSystems = f: | ||
nixpkgs.lib.genAttrs (builtins.attrNames burritoExe) (system: | ||
f rec { | ||
inherit system; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
beamPackages = pkgs.beam.packages.erlang_26; | ||
build = type: | ||
beamPackages.mixRelease { | ||
inherit pname version src; | ||
erlang = beamPackages.erlang; | ||
elixir = beamPackages.elixir_1_15; | ||
elixir = beamPackages.elixir_1_15; | ||
}); | ||
|
||
nativeBuildInputs = [ pkgs.xz pkgs.zig_0_11 pkgs._7zz ]; | ||
burritoExe = { | ||
"aarch64-darwin" = "darwin_arm64"; | ||
"x86_64-darwin" = "darwin_amd64"; | ||
"x86_64-linux" = "linux_amd64"; | ||
"aarch64-linux" = "linux_arm64"; | ||
}; | ||
in { | ||
packages = forAllSystems ({ | ||
pkgs, | ||
system, | ||
beamPackages, | ||
elixir, | ||
}: rec { | ||
default = lib.makeOverridable ({ | ||
localBuild, | ||
beamPackages, | ||
elixir, | ||
}: | ||
beamPackages.mixRelease rec { | ||
pname = "next-ls"; | ||
version = "0.14.2"; # x-release-please-version | ||
src = self.outPath; | ||
inherit (beamPackages) erlang; | ||
inherit elixir; | ||
|
||
mixFodDeps = beamPackages.fetchMixDeps { | ||
inherit src version; | ||
pname = "${pname}-deps"; | ||
hash = "sha256-ekB71eDfcFqC3JojFMnlGRQ/XiPwbUqFVor7ndpUd90="; | ||
}; | ||
nativeBuildInputs = [pkgs.xz pkgs.zig_0_11 pkgs._7zz]; | ||
|
||
preConfigure = '' | ||
bindir="$(pwd)/bin" | ||
mkdir -p "$bindir" | ||
echo '#!/usr/bin/env bash | ||
7zz "$@"' > "$bindir/7z" | ||
chmod +x "$bindir/7z" | ||
mixFodDeps = beamPackages.fetchMixDeps { | ||
inherit src version elixir; | ||
pname = "${pname}-deps"; | ||
hash = "sha256-LV1DYmWi0Mcz1S5k77/jexXYqay7OpysCwOtUcafqGE="; | ||
}; | ||
|
||
export HOME="$(pwd)" | ||
export PATH="$bindir:$PATH" | ||
''; | ||
preConfigure = '' | ||
bindir="$(pwd)/bin" | ||
mkdir -p "$bindir" | ||
echo '#!/usr/bin/env bash | ||
7zz "$@"' > "$bindir/7z" | ||
chmod +x "$bindir/7z" | ||
preBuild = '' | ||
export BURRITO_ERTS_PATH=${beamPackages.erlang}/lib/erlang | ||
''; | ||
export HOME="$(pwd)" | ||
export PATH="$bindir:$PATH" | ||
''; | ||
|
||
preInstall = if type == "local" then '' | ||
export BURRITO_TARGET="${burritoExe (system)}" | ||
'' else | ||
""; | ||
preBuild = '' | ||
export BURRITO_ERTS_PATH=${beamPackages.erlang}/lib/erlang | ||
''; | ||
|
||
postInstall = let | ||
beforeCommand = '' | ||
chmod +x ./burrito_out/* | ||
cp -r ./burrito_out "$out" | ||
''; | ||
patchCommand = '' | ||
patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 "$out/burrito_out/next_ls_linux_amd64" | ||
''; | ||
afterCommand = '' | ||
rm -rf "$out/bin" | ||
mv "$out/burrito_out" "$out/bin" | ||
mv "$out/bin/next_ls_${burritoExe (system)}" "$out/bin/nextls" | ||
''; | ||
in beforeCommand | ||
+ lib.optionalString (system == "x86_64-linux") patchCommand | ||
+ afterCommand; | ||
}; | ||
in { | ||
default = build ("local"); | ||
ci = build ("ci"); | ||
}); | ||
preInstall = lib.optionalString localBuild '' | ||
export BURRITO_TARGET="${burritoExe.${system}}" | ||
''; | ||
|
||
apps = forAllSystems ({ pkgs, system, ... }: { | ||
default = { | ||
type = "app"; | ||
program = "${self.packages.${system}.default}/burrito_out/next_ls_${ | ||
burritoExe (system) | ||
}"; | ||
}; | ||
}); | ||
postInstall = '' | ||
chmod +x ./burrito_out/* | ||
cp -r ./burrito_out "$out" | ||
${lib.optionalString pkgs.stdenv.isLinux '' | ||
patchelf --set-interpreter ${pkgs.stdenv.cc.libc}/lib/${ | ||
if system == "x86_64-linux" | ||
then "ld-linux-x86-64.so.2" | ||
else if system == "aarch64-linux" | ||
then "ld-linux-aarch64.so.1" | ||
else throw "unsupported Linux system" | ||
} \ | ||
"$out/burrito_out/next_ls_${burritoExe.${system}}" | ||
''} | ||
rm -rf "$out/bin" | ||
mv "$out/burrito_out" "$out/bin" | ||
mv "$out/bin/next_ls_${burritoExe.${system}}" "$out/bin/nextls" | ||
''; | ||
|
||
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 ]; | ||
meta = with lib; { | ||
license = licenses.mit; | ||
homepage = "https://www.elixir-tools.dev/next-ls/"; | ||
description = "The language server for Elixir that just works"; | ||
mainProgram = "nextls"; | ||
}; | ||
}); | ||
}; | ||
}) { | ||
inherit beamPackages elixir; | ||
localBuild = true; | ||
}; | ||
|
||
ci = default.override {localBuild = false;}; | ||
}); | ||
|
||
devShells = forAllSystems ({ | ||
pkgs, | ||
beamPackages, | ||
elixir, | ||
... | ||
}: { | ||
default = pkgs.mkShell { | ||
# The Nix packages provided in the environment | ||
packages = [beamPackages.erlang elixir]; | ||
}; | ||
}); | ||
}; | ||
} |