Skip to content

Commit

Permalink
chore(nix): install correct nextls binary (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
goofansu committed Oct 16, 2023
1 parent d1f3876 commit 1112525
Showing 1 changed file with 68 additions and 68 deletions.
136 changes: 68 additions & 68 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; };

outputs = { self, nixpkgs }:
let
lib = nixpkgs.lib;

# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
Expand All @@ -18,20 +18,19 @@
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;
});
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
Expand All @@ -44,80 +43,81 @@
"linux_arm64"
else
"";
in
{
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;
build = type:
beamPackages.mixRelease {
inherit pname version src;
erlang = beamPackages.erlang;
elixir = beamPackages.elixir_1_15;

nativeBuildInputs = [ pkgs.xz pkgs.zig_0_11 pkgs._7zz ];
nativeBuildInputs = [ pkgs.xz pkgs.zig_0_11 pkgs._7zz ];

mixFodDeps = beamPackages.fetchMixDeps {
inherit src version;
pname = "${pname}-deps";
hash = "sha256-ekB71eDfcFqC3JojFMnlGRQ/XiPwbUqFVor7ndpUd90=";
};

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;
pname = "${pname}-deps";
hash = "sha256-ekB71eDfcFqC3JojFMnlGRQ/XiPwbUqFVor7ndpUd90=";
};

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 =
if system == "x86_64-linux" then ''
chmod +x ./burrito_out/*
cp -r ./burrito_out "$out"
preInstall = if type == "local" then ''
export BURRITO_TARGET="${burritoExe (system)}"
'' else
"";

patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 "$out/burrito_out/next_ls_linux_amd64"
'' else ''
chmod +x ./burrito_out/*
cp -r ./burrito_out "$out"
'';
};
in
{
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");
});

apps = forAllSystems ({ pkgs, system, ... }: {
default = {
type = "app";
program = "${self.packages.${system}.default}/burrito_out/next_ls_${burritoExe(system)}";
program = "${self.packages.${system}.default}/burrito_out/next_ls_${
burritoExe (system)
}";
};
});

devShells = forAllSystems ({ pkgs, ... }:
let
beamPackages = pkgs.beam.packages.erlang_26;
in
{
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
];
packages = [ beamPackages.erlang beamPackages.elixir_1_15 ];
};
});
};
Expand Down

0 comments on commit 1112525

Please sign in to comment.