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
+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.