Compare commits

...

10 commits

Author SHA1 Message Date
Benjamin Bädorf 0b54d6ce44
add buildInputs option to mkExecutable 2023-02-08 16:20:40 +01:00
SnO₂WMaN 15b4c19f42
Create LICENSE (#22) 2022-12-14 13:02:27 +09:00
SnO₂WMaN 21efd7ac82
feat: Update for deno2nix v2 (#21)
* move simple script to `examples/simple`

* rm vscode settings.json

* example npm

* wip

* refactoring

* Update mkExecutable

* rm custom formatter  from vscode extensions

* Add .gitignore

* Update flake.nix

* bundled/executable wip

* Update flake

* importMap

* bundled wrapper

* somerefactoring

* no more overlay(default)

* add todo

* Update README.md
2022-12-14 13:00:56 +09:00
SnO₂WMaN 9f8afeffb2
ci: Not triggered on pull request (#20)
* ci: not triggered on pull request

* fmt

* nomore flake-compat

* Revert "nomore flake-compat"

This reverts commit f3c85c80d2e2b9d56bd675661c9e35a0b99c656c.
2022-12-09 16:51:41 +09:00
dependabot[bot] 296c4234db
Bump cachix/cachix-action from 11 to 12 (#17)
Bumps [cachix/cachix-action](https://github.com/cachix/cachix-action) from 11 to 12.
- [Release notes](https://github.com/cachix/cachix-action/releases)
- [Commits](https://github.com/cachix/cachix-action/compare/v11...v12)

---
updated-dependencies:
- dependency-name: cachix/cachix-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-09 16:26:30 +09:00
SnO₂WMaN 9586378845
Merge pull request #19 from Xe/main
flake: support other systems
2022-12-09 16:26:11 +09:00
Xe db3563f20f nix/make-bundled: add minification option
Signed-off-by: Xe <me@christine.website>
2022-12-09 00:12:21 -05:00
Xe 89969955be nix/make-bundled: parameterize output paths
Signed-off-by: Xe <me@christine.website>
2022-12-09 00:06:15 -05:00
Xe 0b6f2c800a update nixpkgs and devshell
Signed-off-by: Xe <me@christine.website>
2022-12-08 23:52:45 -05:00
Xe c37c8e4e15 nix/internal: work with v2 lock files
Signed-off-by: Xe <me@christine.website>
2022-12-08 23:52:36 -05:00
36 changed files with 440 additions and 298 deletions

View file

@ -2,6 +2,9 @@ name: CI
on:
push:
branches:
- main
pull_request:
jobs:
flake-check:
@ -10,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v11
- uses: cachix/cachix-action@v12
with:
name: sno2wman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
@ -22,7 +25,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v11
- uses: cachix/cachix-action@v12
with:
name: sno2wman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

3
.gitignore vendored
View file

@ -2,3 +2,6 @@
result
dist
# VSCode
**/.vscode/settings.json

View file

@ -3,7 +3,6 @@
"jnoortheen.nix-ide",
"arrterian.nix-env-selector",
"tamasfe.even-better-toml",
"jkillian.custom-local-formatters",
"denoland.vscode-deno"
]
}

59
.vscode/settings.json vendored
View file

@ -1,59 +0,0 @@
{
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix",
"deno.enable": true,
"deno.lint": true,
"deno.importMap": "./import_map.json",
"deno.config": "./deno.jsonc",
"json.schemas": [
{
"fileMatch": ["deno.jsonc"],
"url": "https://deno.land/x/deno/cli/schemas/config-file.v1.json"
}
],
"customLocalFormatters.formatters": [
{
"command": "treefmt -q --stdin ${file}",
"languages": [
"json",
"jsonc",
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"markdown",
"nix",
"toml"
]
}
],
"[toml]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[nix]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[markdown]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[json]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[jsonc]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[javascript]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[javascriptreact]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[typescript]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[typescriptreact]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
}
}

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 SnO₂WMaN
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -4,17 +4,7 @@
## Usage
- lockfile -> `./lock.json`
- import map -> `./import_map.json`
- entrypoint -> `./mod.ts`
### Update `lock.json` for caching
```bash
deno cache --import-map=./import_map.json --lock lock.json --lock-write ./mod.ts
```
### Setup for nix flake (example)
There is a [sample project](/examples/simple).
```nix
{
@ -33,42 +23,28 @@ deno cache --import-map=./import_map.json --lock lock.json --lock-write ./mod.ts
inherit system;
overlays = with inputs; [
devshell.overlay
deno2nix.overlay
deno2nix.overlays.default
];
};
in {
packages.executable = deno2nix.mkExecutable {
pname = "example-executable";
version = "0.1.2";
pname = "simple-executable";
version = "0.1.0";
src = ./.;
lockfile = ./lock.json;
bin = "simple";
output = "example";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
lockfile = "./deno.lock";
config = "./deno.jsonc";
allow = {
all = true;
};
});
}
```
### `deno2nix.mkExecutable`
#### Args
```nix
{
pname,
version,
src,
lockfile,
output ? pname, # generate binary name
entrypoint,
importMap ? null, # ex. "./import_map.json" to $src/${importMap}
additionalDenoFlags ? "", # ex. "--allow-net"
}
```
## Thanks
- [esselius/nix-deno](https://github.com/esselius/nix-deno)

View file

@ -1,8 +1,8 @@
{
"importMap": "./import_map.json",
"tasks": {
"run": "deno run --import-map=./import_map.json ./mod.ts",
"compile": "deno compile --import-map=./import_map.json ./mod.ts",
"cache": "deno cache --import-map=./import_map.json --lock lock.json --lock-write ./mod.ts"
"run": "deno run -A ./mod.ts",
"compile": "deno compile -A ./mod.ts"
},
"fmt": {
"options": {

15
examples/npm/deno.lock Normal file
View file

@ -0,0 +1,15 @@
{
"version": "2",
"remote": {
"https://deno.land/std@0.118.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621"
},
"npm": {
"specifiers": { "chalk": "chalk@5.2.0" },
"packages": {
"chalk@5.2.0": {
"integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==",
"dependencies": {}
}
}
}
}

View file

@ -0,0 +1,5 @@
{
"imports": {
"chalk": "npm:chalk"
}
}

36
examples/npm/mod.ts Normal file
View file

@ -0,0 +1,36 @@
import chalk from "chalk";
console.log(`Hello!`);
console.log(
`This script was written for ${chalk.bgBlack(chalk.white("deno"))}${chalk.black("2")}${
chalk.rgb(126, 126, 255)("Nix")
} with npm ${chalk.italic("chalk")} module.`,
);
// https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L8976-L8998
const c1 = (t: string) => chalk.rgb(71, 111, 182)(t);
const c2 = (t: string) => chalk.rgb(126, 182, 225)(t);
console.log(
[
c1(" ▗▄▄▄ ") + c2("▗▄▄▄▄ ▄▄▄▖"),
c1(" ▜███▙ ") + c2("▜███▙ ▟███▛"),
c1(" ▜███▙ ") + c2("▜███▙▟███▛"),
c1(" ▜███▙ ") + c2("▜██████▛"),
c1(" ▟█████████████████▙ ") + c2("▜████▛ ") + c1("▟▙"),
c1(" ▟███████████████████▙ ") + c2("▜███▙ ") + c1("▟██▙"),
c2(" ▄▄▄▄▖ ") + c2("▜███▙ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜██▛ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜▛ ") + c1("▟███▛"),
c2("▟███████████▛ ") + c1("▟██████████▙"),
c2("▜██████████▛ ") + c1("▟███████████▛"),
c2(" ▟███▛") + c1(" ▟▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▟██▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▜███▙ ") + c1("▝▀▀▀▀"),
c2(" ▜██▛") + c1(" ▜███▙ ") + c2("▜██████████████████▛"),
c2(" ▜▛") + c1(" ▟████▙ ") + c2("▜████████████████▛"),
c1(" ▟██████▙ ") + c2("▜███▙"),
c1(" ▟███▛▜███▙ ") + c2("▜███▙"),
c1(" ▟███▛ ▜███▙ ") + c2("▜███▙"),
c1(" ▝▀▀▀ ▀▀▀▀▘ ") + c2("▀▀▀▘"),
].join("\n"),
);

1
examples/simple/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
simple

View file

@ -0,0 +1,11 @@
{deno2nix}:
deno2nix.mkBundledWrapper {
pname = "simple-bundled";
version = "0.1.0";
src = ./.;
bin = "simple";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
}

View file

@ -0,0 +1,11 @@
{deno2nix}:
deno2nix.mkBundled {
pname = "simple-bundled";
version = "0.1.0";
src = ./.;
output = "bundled.js";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
}

View file

@ -0,0 +1,20 @@
{
"importMap": "./import_map.json",
"tasks": {
"run": "deno run ./mod.ts",
"compile": "deno compile ./mod.ts"
},
"fmt": {
"options": {
"lineWidth": 120,
"indentWidth": 2,
"singleQuote": false,
"useTabs": false
},
"files": {
"exclude": [
"./lock.json"
]
}
}
}

View file

@ -0,0 +1,6 @@
{
"version": "2",
"remote": {
"https://deno.land/std@0.167.0/fmt/colors.ts": "03ad95e543d2808bc43c17a3dd29d25b43d0f16287fe562a0be89bf632454a12"
}
}

View file

@ -0,0 +1 @@
{deno2nix}: deno2nix.internal.mkDepsLink ./deno.lock

View file

@ -0,0 +1,16 @@
{deno2nix}:
deno2nix.mkExecutable {
pname = "simple-executable";
version = "0.1.0";
src = ./.;
bin = "simple";
entrypoint = "./mod.ts";
lockfile = "./deno.lock";
config = "./deno.jsonc";
allow = {
all = true;
};
}

View file

@ -0,0 +1,5 @@
{
"imports": {
"std/": "https://deno.land/std@0.167.0/"
}
}

32
examples/simple/mod.ts Normal file
View file

@ -0,0 +1,32 @@
import { bgBlack, black, rgb24, white } from "std/fmt/colors.ts";
console.log(`Hello!`);
console.log(`This script was written for ${bgBlack(white("deno"))}${black("2")}${rgb24("Nix", 0x7E7EFF)}.`);
// https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L8976-L8998
const c1 = (t: string) => rgb24(t, 0x4D6FB6);
const c2 = (t: string) => rgb24(t, 0x7EB6E1);
console.log(
[
c1(" ▗▄▄▄ ") + c2("▗▄▄▄▄ ▄▄▄▖"),
c1(" ▜███▙ ") + c2("▜███▙ ▟███▛"),
c1(" ▜███▙ ") + c2("▜███▙▟███▛"),
c1(" ▜███▙ ") + c2("▜██████▛"),
c1(" ▟█████████████████▙ ") + c2("▜████▛ ") + c1("▟▙"),
c1(" ▟███████████████████▙ ") + c2("▜███▙ ") + c1("▟██▙"),
c2(" ▄▄▄▄▖ ") + c2("▜███▙ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜██▛ ") + c1("▟███▛"),
c2(" ▟███▛ ") + c2("▜▛ ") + c1("▟███▛"),
c2("▟███████████▛ ") + c1("▟██████████▙"),
c2("▜██████████▛ ") + c1("▟███████████▛"),
c2(" ▟███▛") + c1(" ▟▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▟██▙ ") + c1("▟███▛"),
c2(" ▟███▛") + c1(" ▜███▙ ") + c1("▝▀▀▀▀"),
c2(" ▜██▛") + c1(" ▜███▙ ") + c2("▜██████████████████▛"),
c2(" ▜▛") + c1(" ▟████▙ ") + c2("▜████████████████▛"),
c1(" ▟██████▙ ") + c2("▜███▙"),
c1(" ▟███▛▜███▙ ") + c2("▜███▙"),
c1(" ▟███▛ ▜███▙ ") + c2("▜███▙"),
c1(" ▝▀▀▀ ▀▀▀▀▘ ") + c2("▀▀▀▘"),
].join("\n"),
);

View file

@ -10,11 +10,11 @@
]
},
"locked": {
"lastModified": 1654858401,
"narHash": "sha256-53bw34DtVJ2bnF6WEwy6Tym+qY0pNEiEwARUlvmTZjs=",
"lastModified": 1667210711,
"narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
"owner": "numtide",
"repo": "devshell",
"rev": "f55e05c6d3bbe9acc7363bc8fc739518b2f02976",
"rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
"type": "github"
},
"original": {
@ -26,11 +26,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"type": "github"
},
"original": {
@ -41,11 +41,11 @@
},
"flake-utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
@ -56,11 +56,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1655400192,
"narHash": "sha256-49OBVVRgb9H/PSmNT9W61+NRdDbuSJVuDDflwXlaUKU=",
"lastModified": 1670332253,
"narHash": "sha256-O5SmhlIUt1s+vK4NXeGYqwcBIMwbBPAEZ3GHE3XT28c=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "3d7435c638baffaa826b85459df0fff47f12317d",
"rev": "1c9ffcf70786f0966982ce0fc76ec05df2e1dec2",
"type": "github"
},
"original": {

View file

@ -26,7 +26,6 @@
} @ inputs:
{
overlays.default = import ./nix/overlay.nix;
overlay = self.overlays.default;
}
// flake-utils.lib.eachSystem [
"x86_64-linux"
@ -45,49 +44,33 @@
];
};
in {
packages.depslink = deno2nix.internal.mkDepsLink ./lock.json;
packages.bundled = deno2nix.mkBundled {
pname = "example-bundled";
version = "0.1.0";
src = ./.;
lockfile = ./lock.json;
output = "bundled.js";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
/*
TODO: It can't but I don't why
packages = flake-utils.lib.flattenTree {
simple = {
deps-link = pkgs.callPackage ./examples/simple/deps-link.nix {};
executable = pkgs.callPackage ./examples/simple/executable.nix {};
};
packages.bundled-wrapper = deno2nix.mkBundledWrapper {
pname = "example-bundled-wrapper";
version = "0.1.0";
src = ./.;
lockfile = ./lock.json;
output = "bundled.js";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
};
packages.executable = deno2nix.mkExecutable {
pname = "example-executable";
version = "0.1.2";
src = ./.;
lockfile = ./lock.json;
output = "example";
entrypoint = "./mod.ts";
importMap = "./import_map.json";
*/
packages = {
"simple/deps-link" = pkgs.callPackage ./examples/simple/deps-link.nix {};
"simple/bundled" = pkgs.callPackage ./examples/simple/bundled.nix {};
"simple/bundled-wrapper" = pkgs.callPackage ./examples/simple/bundled-wrapper.nix {};
"simple/executable" = pkgs.callPackage ./examples/simple/executable.nix {};
};
apps = {
"simple/executable" = flake-utils.lib.mkApp {
drv = self.packages.${system}."simple/executable";
name = "simple";
};
"simple/bundled-wrapper" = flake-utils.lib.mkApp {
drv = self.packages.${system}."simple/bundled-wrapper";
name = "simple";
};
};
packages.default = self.packages.${system}.executable;
defaultPackage = self.packages.${system}.default;
apps.bundled-wrapper = flake-utils.lib.mkApp {drv = self.packages.${system}.bundled-wrapper;};
apps.executable = flake-utils.lib.mkApp {drv = self.packages.${system}.executable;};
apps.default = self.apps.${system}.executable;
checks = self.packages.${system};
devShells.default = pkgs.devshell.mkShell {
packages = with pkgs; [
alejandra
@ -95,12 +78,6 @@
treefmt
taplo-cli
];
commands = [
{
package = "treefmt";
category = "formatters";
}
];
};
}
);

View file

@ -1,5 +0,0 @@
{
"imports": {
"std/": "https://deno.land/std@0.118.0/"
}
}

View file

@ -1,3 +0,0 @@
{
"https://deno.land/std@0.118.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621"
}

3
mod.ts
View file

@ -1,3 +0,0 @@
import { green, italic } from "std/fmt/colors.ts";
console.log(`Hello ${italic(green("World"))}!`);

View file

@ -0,0 +1,14 @@
{
lib,
deno2nix,
...
}: let
inherit (builtins) hashString;
inherit (deno2nix.internal) urlPart;
in
# input: https://deno.land/std@0.118.0/fmt/colors.ts
#
# output: https/deno.land/<sha256 "/std@0.118.0/fmt/colors.ts">
url: let
up = urlPart url;
in "${up 0}/${up 1}/${hashString "sha256" (up 2)}"

7
nix/internal/default.nix Normal file
View file

@ -0,0 +1,7 @@
{pkgs, ...}: {
urlPart = pkgs.callPackage ./url-part.nix {};
artifactPath = pkgs.callPackage ./artifact-path.nix {};
mkDepsLink = pkgs.callPackage ./mk-deps-link.nix {};
findImportMap =
pkgs.callPackage ./find-import-map.nix {};
}

View file

@ -0,0 +1,10 @@
{lib, ...}: let
inherit (lib) importJSON;
in
{
src,
config,
importMap,
}:
# TODO: if importMap is exists, fallback
((importJSON (src + "/${config}")).importMap)

View file

@ -1,27 +1,16 @@
{
pkgs,
lib,
linkFarm,
writeText,
deno2nix,
...
}: let
inherit (builtins) split elemAt fetchurl toJSON hashString baseNameOf;
inherit (lib) flatten mapAttrsToList importJSON;
inherit (lib.strings) sanitizeDerivationName;
# https://deno.land/std@0.118.0/fmt/colors.ts
#
# 0. "https"
# 1. "deno.land"
# 2. "/std@0.118.0/fmt/colors.ts"
urlPart = url: elemAt (flatten (split "://([a-z0-9\.]*)" url));
# https://deno.land/std@0.118.0/fmt/colors.ts
#
# https/deno.land/<sha256 "/std@0.118.0/fmt/colors.ts">
artifactPath = url: let up = urlPart url; in "${up 0}/${up 1}/${hashString "sha256" (up 2)}";
in {
mkDepsLink = lockfile: (
inherit (deno2nix.internal) artifactPath;
in
lockfile: (
linkFarm "deps" (flatten (
mapAttrsToList
(
@ -43,7 +32,6 @@ in {
}
]
)
(importJSON lockfile)
(importJSON lockfile).remote
))
);
}
)

11
nix/internal/url-part.nix Normal file
View file

@ -0,0 +1,11 @@
{lib, ...}: let
inherit (builtins) split elemAt;
inherit (lib) flatten;
in
# input: https://deno.land/std@0.118.0/fmt/colors.ts
#
# output:
# 0. "https"
# 1. "deno.land"
# 2. "/std@0.118.0/fmt/colors.ts"
url: elemAt (flatten (split "://([a-z0-9\.]*)" url))

View file

@ -1,17 +0,0 @@
{
pkgs,
deno,
deno2nix,
writeShellScriptBin,
...
}: {
pname,
bin ? pname,
output ? "bundled.js",
...
} @ args: let
bundled = deno2nix.mkBundled args;
in
writeShellScriptBin
bin
"${deno}/bin/deno run ${bundled}/dist/${output}"

View file

@ -1,43 +0,0 @@
{
pkgs,
stdenv,
deno2nix,
lib,
...
}: {
pname,
version,
src,
lockfile,
output ? "bundled.js",
entrypoint,
importMap ? null,
additionalDenoFlags ? "",
}: let
inherit (deno2nix.internal) mkDepsLink;
in
stdenv.mkDerivation {
inherit pname version entrypoint src;
buildInputs = with pkgs; [deno jq];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
deno bundle \
--lock="${lockfile}" \
${
if importMap != null
then "--import-map=\"$src/${importMap}\""
else ""
} \
${additionalDenoFlags} \
"$src/${entrypoint}" \
"${output}"
'';
installPhase = ''
mkdir -p $out/dist
install -t $out/dist "${output}"
'';
}

View file

@ -1,45 +0,0 @@
{
pkgs,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
lockfile,
output ? pname,
entrypoint,
importMap ? null,
additionalDenoFlags ? "",
}: let
inherit (deno2nix.internal) mkDepsLink;
in
stdenv.mkDerivation {
inherit pname version src;
dontFixup = true;
buildInputs = with pkgs; [deno jq];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
deno compile \
--cached-only \
--lock="${lockfile}" \
--output="${output}" \
${
if importMap != null
then "--import-map=\"$src/${importMap}\""
else ""
} \
${additionalDenoFlags} \
"$src/${entrypoint}"
'';
installPhase = ''
mkdir -p $out/bin
cp "${output}" "$out/bin/"
'';
}

View file

@ -0,0 +1,19 @@
{
lib,
deno,
deno2nix,
writeShellScriptBin,
...
}: {
pname,
bin ? pname,
output ? "${pname}.bundled.js",
outPath ? "dist",
...
} @ args: let
inherit (lib) filterAttrs;
bundled = deno2nix.mkBundled (filterAttrs (n: v: n != "bin") args);
in
writeShellScriptBin
bin
"${deno}/bin/deno run ${bundled}/${outPath}/${output}"

57
nix/mk-bundled.nix Normal file
View file

@ -0,0 +1,57 @@
{
pkgs,
lib,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
output ? "${pname}.bundled.js",
outPath ? "dist",
entrypoint,
lockfile,
minify ? false,
additionalDenoFlags ? "",
}: let
inherit (builtins) isString;
inherit (lib.strings) concatStringsSep;
inherit (deno2nix.internal) mkDepsLink;
bundleCmd = concatStringsSep " " (
[
"deno bundle"
"--lock=${lockfile}"
# "--config=${config}"
]
++ [additionalDenoFlags]
++ [
"${entrypoint}"
"${output}"
]
);
in
stdenv.mkDerivation {
inherit pname version entrypoint src;
buildInputs = with pkgs; [deno jq nodePackages.uglify-js];
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
${bundleCmd}
${
if minify
then ''
mv ${output} ${output}-non-min
uglifyjs ${output}-non-min -c -m > ${output}
''
else ""
}
'';
installPhase = ''
mkdir -p $out/${outPath}
install -t $out/${outPath} "${output}"
'';
}

73
nix/mk-executable.nix Normal file
View file

@ -0,0 +1,73 @@
{
pkgs,
lib,
stdenv,
deno2nix,
...
}: {
pname,
version,
src,
bin ? pname,
buildInputs ? [],
entrypoint,
lockfile,
config,
allow ? {},
additionalDenoFlags ? "",
} @ inputs: let
inherit (builtins) isString;
inherit (lib) importJSON concatStringsSep;
inherit (deno2nix.internal) mkDepsLink findImportMap;
allowflag = flag: (
if (allow ? flag) && allow."${flag}"
then ["--allow-${flag}"]
else []
);
importMap = findImportMap {
inherit (inputs) src config importMap;
};
compileCmd = concatStringsSep " " (
[
"deno compile --cached-only"
"--lock=${lockfile}"
"--output=${bin}"
# "--config=${config}"
]
++ (
if (isString importMap)
then ["--import-map=${importMap}"]
else []
)
++ (allowflag "all")
++ (allowflag "env")
++ (allowflag "ffi")
++ (allowflag "hrtime")
++ (allowflag "net")
++ (allowflag "read")
++ (allowflag "run")
++ (allowflag "sys")
++ (allowflag "write")
++ [additionalDenoFlags]
++ ["${entrypoint}"]
);
in
stdenv.mkDerivation {
inherit pname version src;
dontFixup = true;
buildInputs = with pkgs; [deno jq] ++ buildInputs;
buildPhase = ''
export DENO_DIR="/tmp/deno2nix"
mkdir -p $DENO_DIR
ln -s "${mkDepsLink (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
${compileCmd}
'';
installPhase = ''
mkdir -p $out/bin
cp "${bin}" "$out/bin/"
'';
}

View file

@ -1,9 +1,9 @@
final: prev: {
deno2nix = {
mkBundled = final.callPackage ./make-bundled.nix {};
mkBundledWrapper = final.callPackage ./make-bundled-wrapper.nix {};
mkExecutable = final.callPackage ./make-executable.nix {};
mkBundled = final.callPackage ./mk-bundled.nix {};
mkBundledWrapper = final.callPackage ./mk-bundled-wrapper.nix {};
mkExecutable = final.callPackage ./mk-executable.nix {};
internal = final.callPackage ./internal.nix {};
internal = final.callPackage ./internal {};
};
}