Add some settings

This commit is contained in:
Stéphan Kochen
2020-08-26 09:10:07 +02:00
parent ccfc83af5d
commit a1fe6181f1
5 changed files with 55 additions and 21 deletions
+10 -7
View File
@@ -7,8 +7,13 @@ Generates a Nix expression to build a Yarn v2 project (not using zero-install).
## Usage
```sh
# Install the plugin.
yarn plugin import https://raw.githubusercontent.com/stephank/yarn-plugin-nixify/main/dist/yarn-plugin-nixify.js
# Run Yarn as usual.
yarn
# Build your project with Nix.
nix-build
```
@@ -33,12 +38,7 @@ Some examples of how to customize your build from within `default.nix`:
let
# Example of providing a different source.
src = fetchFromGitHub {
owner = "johndoe";
repo = "myproject";
rev = "v1.0.0";
sha256 = "1hdhafj726g45gh7nj8qv1xls8mps3vhzq3aasdymbdqcb1clhkz";
};
src = pkgs.lib.cleanSource ./.;
project = pkgs.callPackage ./yarn-project.nix {
@@ -49,9 +49,12 @@ let
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.
# 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.
buildPhase = ''
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -11
View File
@@ -103,22 +103,26 @@ export default async (project: Project, cache: Cache, report: Report) => {
.join(``) +
` ]`
);
const projectExprPath = ppath.join(cwd, `yarn-project.nix` as Filename);
xfs.writeFileSync(projectExprPath, projectExpr);
xfs.writeFileSync(configuration.get(`nixExprPath`), projectExpr);
// Create a wrapper if it does not exist yet.
const defaultExprPath = ppath.join(cwd, `default.nix` as Filename);
if (!xfs.existsSync(defaultExprPath)) {
xfs.writeFileSync(defaultExprPath, defaultExprTmpl);
report.reportInfo(
0,
`A minimal default.nix was created. You may want to customize it.`
);
if (configuration.get(`generateDefaultNix`)) {
const defaultExprPath = ppath.join(cwd, `default.nix` as Filename);
if (!xfs.existsSync(defaultExprPath)) {
xfs.writeFileSync(defaultExprPath, defaultExprTmpl);
report.reportInfo(
0,
`A minimal default.nix was created. You may want to customize it.`
);
}
}
// Preload the cache entries into the Nix store.
if (xfs.existsSync(npath.toPortablePath(`/nix/store`))) {
xfs.mktempPromise(async (tempDir) => {
if (
configuration.get(`enableNixPreload`) &&
xfs.existsSync(npath.toPortablePath(`/nix/store`))
) {
await xfs.mktempPromise(async (tempDir) => {
const toPreload: PortablePath[] = [];
for (const { name, filename, sha512 } of cacheEntries) {
// Check to see if the Nix store entry already exists.
+27 -2
View File
@@ -1,17 +1,42 @@
import FetchOneCommand from "./FetchOneCommand";
import InstallBinCommand from "./InstallBinCommand";
import generate from "./generate";
import { Hooks, Plugin } from "@yarnpkg/core";
import { Hooks, Plugin, SettingsType } from "@yarnpkg/core";
const plugin: Plugin<Hooks> = {
commands: [FetchOneCommand, InstallBinCommand],
hooks: {
afterAllInstalled: async (project, opts) => {
if (opts.persistProject !== false) {
if (
opts.persistProject !== false &&
project.configuration.get(`enableNixify`)
) {
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;
+2
View File
@@ -36,6 +36,8 @@ in stdenv.mkDerivation {
name = @@PROJECT_NAME@@;
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.
npm_config_nodedir = nodejs;
# Tell node-pre-gyp to never fetch binaries / always build from source.