Giter Site home page Giter Site logo

deno2nix's Introduction

deno2nix

Nix support for Deno

Usage

There is a sample project.

{
  inputs.deno2nix.url = "github:SnO2WMaN/deno2nix";
  inputs.devshell.url = "github:numtide/devshell";
 
  outputs = {
    self,
    nixpkgs,
    flake-utils,
    ...
  } @ inputs:
    flake-utils.lib.eachDefaultSystem (system: let
      inherit (pkgs) deno2nix;
      pkgs = import nixpkgs {
        inherit system;
        overlays = with inputs; [
          devshell.overlay
          deno2nix.overlays.default
        ];
      };
    in {
      packages.executable = deno2nix.mkExecutable {
        pname = "simple-executable";
        version = "0.1.0";
      
        src = ./.;
        bin = "simple";
      
        entrypoint = "./mod.ts";
        lockfile = "./deno.lock";
        config = "./deno.jsonc";
      
        allow = {
          all = true;
        };
      });
    };
}

Thanks

deno2nix's People

Contributors

dependabot[bot] avatar jcpsimmons avatar sno2wman avatar xe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

deno2nix's Issues

pretty store paths for metadata.json files

this is purely cosmetic ...

actual

all meta files have basename metadata.json

1ddfac632016b935a9574d3e7789699caab77e9602acbd00da7c07ffef4fd9fb
  /nix/store/s6vr495pcm6fap2v6f0gp3q9x82rk9q4-os.ts
  /nix/store/4974pc3w95nq1wsbbszgfrkj7cn767cn-metadata.json

230bdccb49d1692e3a623baf7d9d59183f15e928dcb446574ecf9bedc6f84246
  /nix/store/s0hlm9zlkh2fkqacp9l3lnma7p8pjkaf-mod.ts
  /nix/store/vgxsvkmc745vrcx3xmywjrzj3558kqap-metadata.json
ls /nix/store/4b4f3bm8a1n4hrygwm8aa7k7sgbfqdd5-udd-0.8.0/share/deno/deps/https/deno.land/*.json  |
while read j
do
  b=${j%.*.*}
  echo $(basename $b)
  echo " " $(readlink -f $b)
  echo " " $(readlink -f $j)
  echo
done |
head -n $((4*2))

expected 1: same basename

minus: limited filename length

1ddfac632016b935a9574d3e7789699caab77e9602acbd00da7c07ffef4fd9fb
  /nix/store/s6vr495pcm6fap2v6f0gp3q9x82rk9q4-os.ts
  /nix/store/4974pc3w95nq1wsbbszgfrkj7cn767cn-os.ts.meta

230bdccb49d1692e3a623baf7d9d59183f15e928dcb446574ecf9bedc6f84246
  /nix/store/s0hlm9zlkh2fkqacp9l3lnma7p8pjkaf-mod.ts
  /nix/store/vgxsvkmc745vrcx3xmywjrzj3558kqap-mod.ts.meta

expected 2: same folder

plus: less files in nix store
minus: *.ts files are not stored as files in nix store = *.ts files are not content-addressed

1ddfac632016b935a9574d3e7789699caab77e9602acbd00da7c07ffef4fd9fb
  /nix/store/s6vr495pcm6fap2v6f0gp3q9x82rk9q4-os.ts/os.ts
  /nix/store/s6vr495pcm6fap2v6f0gp3q9x82rk9q4-os.ts/os.ts.meta

230bdccb49d1692e3a623baf7d9d59183f15e928dcb446574ecf9bedc6f84246
  /nix/store/s0hlm9zlkh2fkqacp9l3lnma7p8pjkaf-mod.ts/mod.ts
  /nix/store/s0hlm9zlkh2fkqacp9l3lnma7p8pjkaf-mod.ts/mod.ts.meta

SHA256 hash mismatches (`deno cache` and `curl | sha256sum` disagree)

This is kind of a weird problem. When nix building one of my projects with deno2nix, I get errors like:

$ nix build '.#executable'
warning: Git tree '/Users/amos/bearcove/keysmash2' is dirty
error: hash mismatch in file downloaded from 'https://esm.sh/[email protected]/hooks':
         specified: sha256:0dpp3ypl1j86v8whp3yqlx7i3aam3pzsqx7hccb511wbxdaw33ib
         got:       sha256:049xy78c6l4i6c6cwppgpgyrilcz2n78ydvjppv8rr8gifklzz4n
(use '--show-trace' to show detailed location information)

I'm not sure how those hashes are formatted (they don't look like hex, there's w in there), but out of curiosity, I checked what was in deno.lock and compared it with curl url | gsha256sum, and they disagree:

The deno.lock file has 2b8ec155eb8b87501663f074acff1d55a9114fa7d88f0b39da06c940af1ff736, but:

$ curl -s https://esm.sh/[email protected]/hooks | gsha256sum
96fc4fa78b0fe58cf6bd72378f8e159fd198fdbbef5ece0c339150c3d0f13d11  -

This might be a bug in deno cache (1.30.3), or esm.sh might be serving something different for different user-agents (and in this case it can be fixed in deno2nix?). All I know right now is that it's weird and I'm wondering if you have any idea where this could come from.

(My best idea of a workaround right now is to write a tool that updates deno.lock with the proper SHA256 sums before calling nix build, but that's not great).

remove flake stuff from default.nix

im struggling to "just use" this in a "legacy" nix project (from default.nix or shell.nix)

please make default.nix more like npmlock2nix/default.nix

example use: webview_deno-nix/default.nix

webview_deno/default.nix
# webview_deno/default.nix

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let

  # TODO simpler
  # expected API:
  #deno2nix = callPackage ${deno2nix-src} {};
  inherit (import (deno2nix-src + "/nix/overlay.nix") pkgs {}) deno2nix;

  deno2nix-src = fetchFromGitHub {
    # https://github.com/SnO2WMaN/deno2nix
    owner = "SnO2WMaN";
    repo = "deno2nix";
    rev = "a2092563c48cb71adc397f496f05049d4f20647a";
    sha256 = "sha256-P82KyZVr/hnBUcNOTNVeWV73FnXjMTjo9emF5rjiG2Y=";
  };

  webview_deno = stdenv.mkDerivation rec {

    pname = "webview_deno";
    version = "0.7.4-2022-09-30";

    src = fetchFromGitHub {
      # https://github.com/webview/webview_deno
      owner = "webview";
      repo = pname;
      rev = "9c3bff67c0b6ba2b5dc6066c15b3117da6ad7c68";
      sha256 = "sha256-4iWOoZ5ToH5hMfDP7mDgN52F/RR9WoiLxbyfPRzu+Y0=";
      fetchSubmodules = true;
    };

    lockfileHash = "sha256-6cwa8WXp3X5zEiys79TbVr506HRbhDwsirRcbSTa4WA=";

    buildInputs = [ deno pkg-config webkitgtk ];

    patches = [
      # https://github.com/webview/webview_deno/pull/144
      # print command before running
      #./pull-144.diff
    ];

    # TODO list
    mainScript = "script/build.ts";

    lockfile = stdenv.mkDerivation {
      inherit (webview_deno) version buildInputs src patches;
      # fixed output drv
      outputHash = lockfileHash;
      outputHashMode = "flat";
      outputHashAlgo = "sha256";
      pname = "${pname}-lockfile";
      buildPhase = ''
        ${setDenoDir}
        deno cache --lock=lock.json --lock-write ${mainScript}
      '';
      installPhase = ''
        cp lock.json $out
      '';
    };

    # not working. "deno task" does not take --lock
    #deno task --lock=${lockfile} build

    buildPhase = ''
      ${setDenoDir}

      echo "deno version:"
      deno --version

      mkdir -p $DENO_DIR
      ln -s ${deno2nix.internal.mkDepsLink lockfile} $DENO_DIR/deps

      deno run -A --unstable --lock=${lockfile} --cached-only ${mainScript}
    '';

    # produce $out/libwebview.so
    installPhase = ''
      cp -r build/ $out
    '';
  };

  setDenoDir = ''
    export DENO_DIR=/tmp/deno
  '';

in

webview_deno

/*
PLUGIN_URL=$(readlink result-webview_deno) deno run -Ar --unstable --allow-read="$PLUGIN_URL" main.ts
*/

Hash mismatch for esm.sh dependencies?

Revision: 53adb67

Flake snippet:

        packages.uploader = pkgs.deno2nix.mkExecutable {
          pname = "uploader";
          version = self.rev;

          src = ./.;
          bin = "uploader";
          lockfile = "./deno.lock";
          config = "./deno.json";
          entrypoint = "./uploader.ts";

          allow = {
            all = true;
          };
        };

Imports in the code:

// @deno-types="./dcmjs.d.ts"
import dcmjs from "https://esm.sh/[email protected]";

Output:

error:
       … while calling the 'derivationStrict' builtin

         at //builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'uploader-a396ad10ace1db0742491a00c09e2ebf0492990e'
         whose name attribute is located at /nix/store/2ja7y9nhrck3ydp9bj2234hcid0sx7qg-source/pkgs/stdenv/generic/make-derivation.nix:303:7

       … while evaluating attribute 'buildPhase' of derivation 'uploader-a396ad10ace1db0742491a00c09e2ebf0492990e'

         at /nix/store/n5qyjg02vv11842wg394andkips3b6dp-source/nix/mk-executable.nix:62:5:

           61|     buildInputs = with pkgs; [deno jq];
           62|     buildPhase = ''
             |     ^
           63|       export DENO_DIR="/tmp/deno2nix"

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: hash mismatch in file downloaded from 'https://esm.sh/[email protected]':
         specified: sha256:0w14lnwghk2mlmxqr3ph48wxd9igy9ri0ychqxj0bmzjd207bz8q
         got:       sha256:1ccgp70zn7id4x5j37n1hwlx5hvjr1w22i33wmgr2camcsb709lf

fails due to deno runtime being downloaded from website in compile step

rt. It gives a domain resolution error as it can't contact the network

error: builder for '/nix/store/ffhq33v63bqqs5lkqxkzfwdi6z3a66zc-ags-uno-compiler-0.1.0.drv' failed with exit code 1;
       last 10 log lines:
       > Check file:///build/ags/createUnoFile.js
       > Compile file:///build/ags/createUnoFile.js to uno-comp
       > Download https://dl.deno.land/release/v1.40.5/denort-x86_64-unknown-linux-gnu.zip
       > error: Writing uno-comp
       >
       > Caused by:
       >     0: error sending request for url (https://dl.deno.land/release/v1.40.5/denort-x86_64-unknown-linux-gnu.zip): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
       >     1: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
       >     2: dns error: failed to lookup address information: Temporary failure in name resolution
       >     3: failed to lookup address information: Temporary failure in name resolution
       For full logs, run 'nix log /nix/store/ffhq33v63bqqs5lkqxkzfwdi6z3a66zc-ags-uno-compiler-0.1.0.drv'

"mktemp -d" is not deterministic

export DENO_DIR=`mktemp -d`

for i in $(seq 0 10); do mktemp -d; done

/tmp/tmp.OL2aCX9RNz
/tmp/tmp.yzb7ahjMfW
/tmp/tmp.jM4JXcUhtu
/tmp/tmp.PoMUU32cCA
/tmp/tmp.HErON1bTsI
/tmp/tmp.LtkXQZhVMD
/tmp/tmp.nWTxVtlLIq
/tmp/tmp.BpmeMaAxys
/tmp/tmp.vSIwLSXUA3
/tmp/tmp.TxOK7zh5vU
/tmp/tmp.ibLXTSvb3m

better use /tmp or /tmp/deno

ln: failed to create symbolic link '/tmp/deno2nix/deps/vnzi3brp4c4ijh9nqycny3qqi0a54ps0-deps': Permission denied

After updated to the latest version, I got the following error:

error: builder for '/nix/store/raja60p7wha15j43wwrrv0g6gbzkgi7s-deno-api-dynamic-form-0.0.0.drv' failed with exit code 1;
       last 9 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/l7wipfdmphpcm3wr7ssngffzy943j212-yxfrmmd1zfafymmwb1pbhbklcfrhrixx-source
       > source root is yxfrmmd1zfafymmwb1pbhbklcfrhrixx-source
       > patching sources
       > updateAutotoolsGnuConfigScriptsPhase
       > configuring
       > no configure script, doing nothing
       > building
       > ln: failed to create symbolic link '/tmp/deno2nix/deps/vnzi3brp4c4ijh9nqycny3qqi0a54ps0-deps': Permission denied

And I am able to resolve it for now like this:

main...winston0410:deno2nix:hotfix/avoid-tmp

deno2nix not working with newer nixpkgs

Hello,
first of all thank you for creating this flake.
I bumped into an error saying

error: getting status of '/nix/store/345q8dyv6mx38bkj25rmykzq34p3x426-source/nix': No such file or directory

with newer versions of nixpkgs.
It seems like the src variable is somehow concatenated twice.

store path '[email protected]' contains illegal character '@'

Hi thank you for this awesome module. I have tried to build a program with it, but I got the following error:

store path '[email protected]' contains illegal character '@'

This is my lock.json

{
  "https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/sinon.js": "2f76d4108a756f812f8378005cffeddc118036986f45bf5ecf61cdd7a5662e28",
  "https://cdn.skypack.dev/[email protected]": "648d7680e355050c96c3324e900830048390d349070e90be4fc9eb9d347b5e67",
  "https://deno.land/[email protected]/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
  "https://deno.land/[email protected]/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49"
}

And my derivation:

          deno-api-dynamic-form = pkgs.deno2nix.mkExecutable {
            name = "deno-api-dynamic-form";
            version = "0.0.0";
            src = ./.;
            denoFlags = ["--allow-net" "--allow-env" "--allow-read" "--import-map=./import_map.json"];
            lockfile = ./apps/deno/api-dynamic-form/lock.json;
            entrypoint = ./apps/deno/api-dynamic-form/src/index.ts;
          };

I believe this is a critical issue, as @ is used everywhere in the URL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.