Skip to content

Commit

Permalink
Add tsx in flake
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Oct 23, 2024
1 parent 7943b6d commit 896b000
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 65 deletions.
84 changes: 25 additions & 59 deletions flake.lock

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

53 changes: 47 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
inputs.nixpkgs.follows = "nixpkgs";
};
poetry2nix = {
url = "github:nix-community/poetry2nix?ref=refs/tags/2024.5.939250";
url = "github:nix-community/poetry2nix?ref=refs/tags/2024.10.2267247";
inputs.nixpkgs.follows = "nixpkgs";
};
};
Expand Down Expand Up @@ -45,6 +45,47 @@

nodejs_base = pkgs.nodejs_22;

tsx = pkgs.stdenvNoCC.mkDerivation rec {
pname = "tsx";
version = "4.19.1";

src = pkgs.fetchFromGitHub {
owner = "privatenumber";
repo = pname;
rev = "v${version}";
hash = "sha256-3fEH1KiQqsw3NOtyvbx0DCWwWz+n8YFHUJAw8/8mMR8=";
};

nativeBuildInputs = [
nodejs_base
pkgs.pnpm.configHook
pkgs.makeWrapper
];

pnpmDeps = pkgs.pnpm.fetchDeps {
inherit pname version src;
hash = "sha256-wOw7kHP6ajFwOefvl4vphxSmm1jhJXTQ+2knqSjyuek=";
};

buildPhase = ''
runHook preBuild
pnpm build
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p "$out/bin" "$out/lib/tsx"
cp -r dist node_modules "$out/lib/tsx"
makeWrapper "${pkgs.lib.getExe nodejs_base}" "$out/bin/tsx" --add-flags "$out/lib/tsx/dist/cli.mjs"
runHook postInstall
'';
};

# This one isn't in Nix, so do it manually.
ast = pkgs.buildNpmPackage rec {
pname = "abstract-syntax-tree";
Expand Down Expand Up @@ -75,7 +116,7 @@
(pkgs.haskell.packages.ghc96.ghcWithPackages (p: [ p.aeson ]))
pkgs.hlint
];
ts-deps = [ nodejs_base pkgs.typescript pkgs.nodePackages.ts-node ];
ts-deps = [ nodejs_base pkgs.typescript tsx ];
node-deps = [ nodejs_base pkgs.nodePackages.eslint ast ];
bash-deps = [ pkgs.shellcheck ];
c-deps = [ pkgs.cppcheck pkgs.gcc13 ];
Expand Down Expand Up @@ -111,7 +152,7 @@
doCheck = false;
postInstall = ''
wrapProgram "$out/bin/tested" \
--prefix NODE_PATH : ${ast}/lib/node_modules:/nix/store/1vkwbqyd02jfmgyaxq3bly78rlx5mqx9-TESTed-dir/bin/ts-node
--prefix NODE_PATH : ${ast}/lib/node_modules
'';
};
devShell = self.outputs.devShells.${system}.default;
Expand All @@ -124,7 +165,7 @@
DOTNET_CLI_HOME="$(mktemp -d)"
export DOTNET_CLI_HOME
TS_NODE_PROJECT=./tsconfig.json
NODE_PATH=${ast}/lib/node_modules:/nix/store/1vkwbqyd02jfmgyaxq3bly78rlx5mqx9-TESTed-dir/bin/ts-node
NODE_PATH=${ast}/lib/node_modules
export NODE_PATH
export TS_NODE_PROJECT
poetry run pytest -n auto --cov=tested --cov-report=xml tests/
Expand All @@ -141,7 +182,7 @@
tested = pkgs.devshell.mkShell {
name = "TESTed";

packages = [ python-dev-env pkgs.nodePackages.pyright poetry-package ]
packages = [ python-dev-env pkgs.pyright poetry-package ]
++ all-other-dependencies;

devshell.startup.link.text = ''
Expand All @@ -156,7 +197,7 @@
}
{
name = "NODE_PATH";
prefix = "${ast}/lib/node_modules:/nix/store/1vkwbqyd02jfmgyaxq3bly78rlx5mqx9-TESTed-dir/bin/ts-node";
prefix = "${ast}/lib/node_modules";
}
{
name = "TS_NODE_PROJECT";
Expand Down

0 comments on commit 896b000

Please sign in to comment.