Skip to content

Commit

Permalink
chore: wip nix
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Apr 4, 2024
1 parent 686db18 commit cd3652f
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
description = "pygls: The Generic Language Server Framework";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils }:

utils.lib.eachDefaultSystem(system:
let
pkgs = import nixpkgs { inherit system; };
python-wasi = pkgs.callPackage ./nix/python-wasi.nix {};
# TODO: Perhaps an overlay would allow callPackage to know what python-wasi is.
mkPythonWASIShell = pkgs.callPackage ./nix/python.nix { python-wasi = python-wasi; };
in {

devShells.default = mkPythonWASIShell {
pyPackages = with pkgs.python311Packages; [
lsprotocol
];
};
}
);
}
17 changes: 17 additions & 0 deletions nix/python-wasi.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ fetchzip, stdenv }:

stdenv.mkDerivation {
pname = "python-wasi";
version = "3.11.4";

src = fetchzip {
url = "https://github.com/brettcannon/cpython-wasi-build/releases/download/v3.11.4/python-3.11.4-wasi_sdk-16.zip";
stripRoot = false;
sha256 = "sha256-AZGdgpRvHcu6FY/a7capldjDhTpkfhGkqYnm127nAN8=";
};

buildCommand = ''
mkdir $out
cp -r $src/* $out
'';
}
32 changes: 32 additions & 0 deletions nix/python.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ lib
, python-wasi
, mkShell
, stdenv
, wasmtime
, writeShellScriptBin
}:

{ pyPackages ? []
}:

let

pyDeps = lib.concatMap (pkg: lib.remove pkg.pythonModule pkg.requiredPythonModules) pyPackages;
allPackages = lib.unique (pyPackages ++ pyDeps);

pythonPath = lib.concatMapStringsSep ":" (pkg: "${pkg}/lib/python3.11/site-packages") allPackages;

python = writeShellScriptBin "python-wasi" ''
exec ${wasmtime}/bin/wasmtime run ${python-wasi}/python.wasm \
--env PYTHONHOME=${python-wasi} \
--env PYTHONPATH='.:${pythonPath}' \
--dir ${python-wasi} \
${lib.concatMapStringsSep "\\\n " (pkg: "--dir '${pkg}/lib/python3.11/site-packages' ") allPackages} \
--dir . \
-- "$@"
'';

in mkShell {
name = "python-wasi";
packages = [ python ];
}

0 comments on commit cd3652f

Please sign in to comment.