add basic deno flake
This commit is contained in:
parent
d35bd34a70
commit
701e5d138a
5 changed files with 162 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.deno*
|
||||
.emacs*
|
||||
result
|
||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1753939845,
|
||||
"narHash": "sha256-K2ViRJfdVGE8tpJejs8Qpvvejks1+A4GQej/lBk5y7I=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "94def634a20494ee057c76998843c015909d6311",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
56
flake.nix
Normal file
56
flake.nix
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
description = "Deno development environment";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
toDenoTarget = system:
|
||||
let
|
||||
arch = builtins.head (builtins.split "-" system);
|
||||
os = builtins.elemAt (builtins.split "-" system) 1;
|
||||
vendor = if os == "darwin" then "apple" else "unknown";
|
||||
sys = if os == "darwin" then "darwin" else "linux-gnu";
|
||||
in "${arch}-${vendor}-${sys}";
|
||||
|
||||
target = toDenoTarget system;
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
deno
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "🦕 Deno development environment loaded!"
|
||||
echo "Deno version: $(deno --version | head -n1)"
|
||||
'';
|
||||
|
||||
DENO_DIR = "./.deno_cache";
|
||||
};
|
||||
|
||||
# unfortunately this derivation is impure because
|
||||
# managing deno's deps is HARD, so
|
||||
# nix build --option sanbox relaxed
|
||||
packages.default = import ./package.nix {
|
||||
inherit pkgs;
|
||||
inherit target;
|
||||
|
||||
name = "test-grimu-r-deno-app";
|
||||
};
|
||||
|
||||
apps.default = {
|
||||
type = "app";
|
||||
program = toString (pkgs.writeShellScript "run-deno-app" ''
|
||||
export DENO_DIR="./.deno_cache"
|
||||
exec ${pkgs.deno}/bin/deno run main.ts "$@"
|
||||
'');
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
2
main.ts
Normal file
2
main.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import jqModule from "npm:jq-web";
|
||||
console.log("I'M ALIVE");
|
||||
40
package.nix
Normal file
40
package.nix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{ pkgs, target, name }:
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pname = name;
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
|
||||
__noChroot = true;
|
||||
|
||||
dontStrip = true;
|
||||
|
||||
denort = pkgs.fetchurl {
|
||||
url = "https://dl.deno.land/release/v${pkgs.deno.version}/denort-${target}.zip";
|
||||
hash = "sha256-J2LfvHPbJvcOpbQOd6EmGxHDciez7tG10etK4bqQhLI=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = with pkgs; [ deno unzip ];
|
||||
|
||||
configurePhase = ''
|
||||
export DENO_DIR=./.deno_cache;
|
||||
mkdir -p $TMPDIR/denort
|
||||
pushd $TMPDIR/denort
|
||||
unzip ${denort}
|
||||
chmod +x denort
|
||||
popd
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
export DENORT_BIN="$TMPDIR/denort/denort"
|
||||
|
||||
deno compile --output app main.ts --target=${target}
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp app $out/bin/${name}
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue