Add some settings
This commit is contained in:
@@ -7,8 +7,13 @@ Generates a Nix expression to build a Yarn v2 project (not using zero-install).
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
# Install the plugin.
|
||||||
yarn plugin import https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js
|
yarn plugin import https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js
|
||||||
|
|
||||||
|
# Run Yarn as usual.
|
||||||
yarn
|
yarn
|
||||||
|
|
||||||
|
# Build your project with Nix.
|
||||||
nix-build
|
nix-build
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -33,12 +38,7 @@ Some examples of how to customize your build from within `default.nix`:
|
|||||||
let
|
let
|
||||||
|
|
||||||
# Example of providing a different source.
|
# Example of providing a different source.
|
||||||
src = fetchFromGitHub {
|
src = pkgs.lib.cleanSource ./.;
|
||||||
owner = "johndoe";
|
|
||||||
repo = "myproject";
|
|
||||||
rev = "v1.0.0";
|
|
||||||
sha256 = "1hdhafj726g45gh7nj8qv1xls8mps3vhzq3aasdymbdqcb1clhkz";
|
|
||||||
};
|
|
||||||
|
|
||||||
project = pkgs.callPackage ./yarn-project.nix {
|
project = pkgs.callPackage ./yarn-project.nix {
|
||||||
|
|
||||||
@@ -49,9 +49,12 @@ let
|
|||||||
|
|
||||||
in project.overrideAttrs (oldAttrs: {
|
in project.overrideAttrs (oldAttrs: {
|
||||||
|
|
||||||
|
# If your top-level package.json doesn't set a name, you can set one here.
|
||||||
|
name = "myproject";
|
||||||
|
|
||||||
# Example of adding dependencies to the environment.
|
# Example of adding dependencies to the environment.
|
||||||
# Native modules sometimes need these to build.
|
# Native modules sometimes need these to build.
|
||||||
buildInputs = oldAttrs.buildInputs ++ [ python3 ];
|
buildInputs = oldAttrs.buildInputs ++ [ pkgs.python3 ];
|
||||||
|
|
||||||
# Example of invoking a build step in your project.
|
# Example of invoking a build step in your project.
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+8
-4
@@ -103,10 +103,10 @@ export default async (project: Project, cache: Cache, report: Report) => {
|
|||||||
.join(``) +
|
.join(``) +
|
||||||
` ]`
|
` ]`
|
||||||
);
|
);
|
||||||
const projectExprPath = ppath.join(cwd, `yarn-project.nix` as Filename);
|
xfs.writeFileSync(configuration.get(`nixExprPath`), projectExpr);
|
||||||
xfs.writeFileSync(projectExprPath, projectExpr);
|
|
||||||
|
|
||||||
// Create a wrapper if it does not exist yet.
|
// Create a wrapper if it does not exist yet.
|
||||||
|
if (configuration.get(`generateDefaultNix`)) {
|
||||||
const defaultExprPath = ppath.join(cwd, `default.nix` as Filename);
|
const defaultExprPath = ppath.join(cwd, `default.nix` as Filename);
|
||||||
if (!xfs.existsSync(defaultExprPath)) {
|
if (!xfs.existsSync(defaultExprPath)) {
|
||||||
xfs.writeFileSync(defaultExprPath, defaultExprTmpl);
|
xfs.writeFileSync(defaultExprPath, defaultExprTmpl);
|
||||||
@@ -115,10 +115,14 @@ export default async (project: Project, cache: Cache, report: Report) => {
|
|||||||
`A minimal default.nix was created. You may want to customize it.`
|
`A minimal default.nix was created. You may want to customize it.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Preload the cache entries into the Nix store.
|
// Preload the cache entries into the Nix store.
|
||||||
if (xfs.existsSync(npath.toPortablePath(`/nix/store`))) {
|
if (
|
||||||
xfs.mktempPromise(async (tempDir) => {
|
configuration.get(`enableNixPreload`) &&
|
||||||
|
xfs.existsSync(npath.toPortablePath(`/nix/store`))
|
||||||
|
) {
|
||||||
|
await xfs.mktempPromise(async (tempDir) => {
|
||||||
const toPreload: PortablePath[] = [];
|
const toPreload: PortablePath[] = [];
|
||||||
for (const { name, filename, sha512 } of cacheEntries) {
|
for (const { name, filename, sha512 } of cacheEntries) {
|
||||||
// Check to see if the Nix store entry already exists.
|
// Check to see if the Nix store entry already exists.
|
||||||
|
|||||||
+27
-2
@@ -1,17 +1,42 @@
|
|||||||
import FetchOneCommand from "./FetchOneCommand";
|
import FetchOneCommand from "./FetchOneCommand";
|
||||||
import InstallBinCommand from "./InstallBinCommand";
|
import InstallBinCommand from "./InstallBinCommand";
|
||||||
import generate from "./generate";
|
import generate from "./generate";
|
||||||
import { Hooks, Plugin } from "@yarnpkg/core";
|
import { Hooks, Plugin, SettingsType } from "@yarnpkg/core";
|
||||||
|
|
||||||
const plugin: Plugin<Hooks> = {
|
const plugin: Plugin<Hooks> = {
|
||||||
commands: [FetchOneCommand, InstallBinCommand],
|
commands: [FetchOneCommand, InstallBinCommand],
|
||||||
hooks: {
|
hooks: {
|
||||||
afterAllInstalled: async (project, opts) => {
|
afterAllInstalled: async (project, opts) => {
|
||||||
if (opts.persistProject !== false) {
|
if (
|
||||||
|
opts.persistProject !== false &&
|
||||||
|
project.configuration.get(`enableNixify`)
|
||||||
|
) {
|
||||||
await generate(project, opts.cache, opts.report);
|
await generate(project, opts.cache, opts.report);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
configuration: {
|
||||||
|
enableNixify: {
|
||||||
|
description: `If false, disables the Nixify plugin hook that generates Nix expressions`,
|
||||||
|
type: SettingsType.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
nixExprPath: {
|
||||||
|
description: `Path of the file where the project Nix expression will be written to`,
|
||||||
|
type: SettingsType.ABSOLUTE_PATH,
|
||||||
|
default: `./yarn-project.nix`,
|
||||||
|
},
|
||||||
|
generateDefaultNix: {
|
||||||
|
description: `If true, a default.nix will be generated if it does not exist`,
|
||||||
|
type: SettingsType.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
enableNixPreload: {
|
||||||
|
description: `If true, cached packages will be preloaded into the Nix store`,
|
||||||
|
type: SettingsType.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
export default plugin;
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ in stdenv.mkDerivation {
|
|||||||
name = @@PROJECT_NAME@@;
|
name = @@PROJECT_NAME@@;
|
||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
|
# Disable Nixify plugin to save on some unnecessary processing.
|
||||||
|
yarn_enable_nixify = "false";
|
||||||
# Tell node-gyp to use the provided Node.js headers for native code builds.
|
# Tell node-gyp to use the provided Node.js headers for native code builds.
|
||||||
npm_config_nodedir = nodejs;
|
npm_config_nodedir = nodejs;
|
||||||
# Tell node-pre-gyp to never fetch binaries / always build from source.
|
# Tell node-pre-gyp to never fetch binaries / always build from source.
|
||||||
|
|||||||
Reference in New Issue
Block a user