Skip to content

Commit

Permalink
feat(cross): fluidattacks#1043 use node2nix
Browse files Browse the repository at this point in the history
- Use node2nix for building node modules
- Update documentation
- Update locks to include name as it is now required by node2nix
- Adapt ruby lock to latest versions

Signed-off-by: Daniel Salazar <[email protected]>
  • Loading branch information
dsalaza4 committed Dec 26, 2023
1 parent bab198e commit e7f837b
Show file tree
Hide file tree
Showing 15 changed files with 1,989 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
.vscode
node_modules
48 changes: 30 additions & 18 deletions docs/src/api/extensions/node.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Get a specific Node.js version interpreter.
Types:

- makeNodeJsVersion (`function str -> package`):
- (`enum [ "14" "16" "18" ]`):
- (`enum [ "18" "20" "21" ]`):
Node.js version to use.

Example:
Expand All @@ -25,7 +25,7 @@ Example:
'';
name = "example";
searchPaths = {
bin = [ (makeNodeJsVersion "16") ];
bin = [ (makeNodeJsVersion "18") ];
};
}
```
Expand All @@ -41,25 +41,24 @@ Example:
## makeNodeJsModules

Cook the `node_modules` directory
for the given Node.js project.
for the given Node.js project
using [node2nix](https://github.com/svanderburg/node2nix).

Types:

- makeNodeJsModules (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- nodeJsVersion (`enum [ "14" "16" "18" ]`):
- nodeJsVersion (`enum [ "18" ]`):
Node.js version to use.
- packageJson (`package`):
Path to the `package.json` of your project.
- packageLockJson (`package`):
Path to the `package-lock.json` of your project.
- searchPaths (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`.
Defaults to `makeSearchPaths`'s defaults.
- shouldIgnoreScripts (`bool`): Optional.
Enable to propagate the `--ignore-scripts true` flag to npm.
Defaults to `false`.
- packageOverrides (`Attrs`): Optional.
Override behaviors when building `node_modules`.
See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568)
for more.

Example:

Expand Down Expand Up @@ -96,6 +95,7 @@ Example:
```nix
# /path/to/my/project/makes/example/main.nix
{
inputs,
makeNodeJsModules,
makeScript,
projectPath,
Expand All @@ -109,6 +109,12 @@ Example:
projectPath "/path/to/my/project/makes/example/package.json";
packageLockJson =
projectPath "/path/to/my/project/makes/example/package-lock.json";
packageOverrides = {
# Ignore post-install scripts
npmFlags = "--ignore-scripts true";
# Provide patchelf when building node_modules
buildInputs = [inputs.nixpkgs.patchelf];
};
};
in
makeScript {
Expand All @@ -117,6 +123,7 @@ Example:
};
entrypoint = ''
ls __argHello__
ls __argHello__/lib
'';
name = "example";
}
Expand All @@ -127,7 +134,8 @@ Example:
```bash
$ m . /example

hello-world-npm
/bin /lib
/node_modules
```

## makeNodeJsEnvironment
Expand All @@ -148,18 +156,16 @@ Types:
- makeNodeJsEnvironment (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- nodeJsVersion (`enum [ "14" "16" "18" ]`):
- nodeJsVersion (`enum [ "18" ]`):
Node.js version to use.
- packageJson (`package`):
Path to the `package.json` of your project.
- packageLockJson (`package`):
Path to the `package-lock.json` of your project.
- searchPaths (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`.
Defaults to `makeSearchPaths`'s defaults.
- shouldIgnoreScripts (`bool`): Optional.
Enable to propagate the `--ignore-scripts true` flag to npm.
Defaults to `false`.
- packageOverrides (`Attrs`): Optional.
Override behaviors when building `node_modules`.
See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568)
for more.

Example:

Expand Down Expand Up @@ -208,6 +214,12 @@ Example:
projectPath "/path/to/my/project/makes/example/package.json";
packageLockJson =
projectPath "/path/to/my/project/makes/example/package-lock.json";
packageOverrides = {
# Ignore post-install scripts
npmFlags = "--ignore-scripts true";
# Provide patchelf when building node_modules
buildInputs = [inputs.nixpkgs.patchelf];
};
};
in
makeScript {
Expand Down
12 changes: 6 additions & 6 deletions docs/src/api/extensions/ruby.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Get a specific Ruby interpreter.
Types:

- makeRubyVersion (`function str -> package`):
- (`enum [ "2.7" "3.0" "3.1" ]`):
- (`enum [ "3.1" "3.2" "3.3" ]`):
Version of the Ruby interpreter.

Example:
Expand All @@ -25,7 +25,7 @@ Example:
'';
name = "example";
searchPaths = {
bin = [ (makeRubyVersion "2.7") ];
bin = [ (makeRubyVersion "3.1") ];
};
}
```
Expand All @@ -48,7 +48,7 @@ Types:
- makeRubyGemsInstall (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- ruby (`enum [ "2.7" "3.0" ]`):
- ruby (`enum [ "3.1" "3.2" "3.3" ]`):
Version of the Ruby interpreter.
- searchPaths (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`.
Expand All @@ -69,7 +69,7 @@ Example:
}:
makeRubyGemsInstall {
name = "example";
ruby = "3.0";
ruby = "3.1";
sourcesYaml = projectPath "/makes/example/sources.yaml";
}
```
Expand All @@ -90,7 +90,7 @@ Types:
- makeRubyGemsEnvironment (`function { ... } -> package`):
- name (`str`):
Custom name to assign to the build step, be creative, it helps in debugging.
- ruby (`enum [ "2.7" "3.0" ]`):
- ruby (`enum [ "3.1" "3.2" "3.3" ]`):
Version of the Ruby interpreter.
- searchPathsBuild (`asIn makeSearchPaths`): Optional.
Arguments here will be passed as-is to `makeSearchPaths`
Expand Down Expand Up @@ -119,7 +119,7 @@ Example:
let
env = makeRubyGemsEnvironment {
name = "example";
ruby = "3.0";
ruby = "3.1";
searchPathsBuild.bin = [ inputs.nixpkgs.gcc ];
searchPathsRuntime.rpath = [ inputs.nixpkgs.gcc.cc.lib ];
sourcesYaml = projectPath "/makes/example/sources.yaml";
Expand Down
15 changes: 7 additions & 8 deletions makes/utils/makeRubyLock/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ function main {
local ruby_version="${1}"
local deps_path="${2}"
local lock_path="${3}"
local ruby
local ruby_path

: \
&& case "${ruby_version}" in
3.1) ruby=__argRuby31__/bin/ruby ;;
3.2) ruby=__argRuby32__/bin/ruby ;;
3.3) ruby=__argRuby33__/bin/ruby ;;
: && case "${ruby_version}" in
3.1) ruby_path=__argRuby31__ ;;
3.2) ruby_path=__argRuby32__ ;;
3.3) ruby_path=__argRuby33__ ;;
*) critical Ruby version not supported: "${ruby_version}" ;;
esac \
&& info "Generating manifest:" \
&& pushd "$(mktemp -d)" \
&& "${ruby}" \
&& "${ruby_path}/bin/ruby" \
"__argParser__" \
"${ruby_version}" \
"${ruby}" \
"${ruby_path}" \
"${deps_path}" \
> sources.json \
&& yj -yy < sources.json > "${lock_path}" \
Expand Down
Loading

0 comments on commit e7f837b

Please sign in to comment.