mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
nixos/cross-seed: add 'useGenConfigDefaults'
This to me is the cleanest way of setting the default value and track changes to the values from `cross-seed gen-config` with low churn.
This commit is contained in:
parent
0e9535409d
commit
9cc26fef84
1 changed files with 35 additions and 1 deletions
|
@ -14,6 +14,15 @@ let
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
settingsFormat = pkgs.formats.json { };
|
settingsFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
|
generatedConfig =
|
||||||
|
pkgs.runCommand "cross-seed-gen-config" { nativeBuildInputs = [ pkgs.cross-seed ]; }
|
||||||
|
''
|
||||||
|
export HOME=$(mktemp -d)
|
||||||
|
cross-seed gen-config
|
||||||
|
mkdir $out
|
||||||
|
cp -r $HOME/.cross-seed/config.js $out/
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.cross-seed = {
|
options.services.cross-seed = {
|
||||||
|
@ -40,6 +49,22 @@ in
|
||||||
description = "Cross-seed config directory";
|
description = "Cross-seed config directory";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useGenConfigDefaults = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to use the option defaults from the configuration generated by
|
||||||
|
{command}`cross-seed gen-config`.
|
||||||
|
|
||||||
|
Those are the settings recommended by the project, and can be inspected
|
||||||
|
from their [template file](https://github.com/cross-seed/cross-seed/blob/master/src/config.template.cjs).
|
||||||
|
|
||||||
|
Settings set in {option}`services.cross-seed.settings` and
|
||||||
|
{option}`services.cross-seed.settingsFile` will override the ones from
|
||||||
|
this option.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
|
@ -120,6 +145,13 @@ in
|
||||||
let
|
let
|
||||||
jsonSettingsFile = settingsFormat.generate "settings.json" cfg.settings;
|
jsonSettingsFile = settingsFormat.generate "settings.json" cfg.settings;
|
||||||
|
|
||||||
|
genConfigSegment =
|
||||||
|
lib.optionalString cfg.useGenConfigDefaults # js
|
||||||
|
''
|
||||||
|
const gen_config_js = "${generatedConfig}/config.js";
|
||||||
|
Object.assign(loaded_settings, require(gen_config_js));
|
||||||
|
'';
|
||||||
|
|
||||||
# Since cross-seed uses a javascript config file, we can use node's
|
# Since cross-seed uses a javascript config file, we can use node's
|
||||||
# ability to parse JSON directly to avoid having to do any conversion.
|
# ability to parse JSON directly to avoid having to do any conversion.
|
||||||
# This also means we don't need to use any external programs to merge the
|
# This also means we don't need to use any external programs to merge the
|
||||||
|
@ -138,7 +170,9 @@ in
|
||||||
"use strict";
|
"use strict";
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const settings_json = "${jsonSettingsFile}";
|
const settings_json = "${jsonSettingsFile}";
|
||||||
let loaded_settings = JSON.parse(fs.readFileSync(settings_json, "utf8"));
|
let loaded_settings = {};
|
||||||
|
${genConfigSegment}
|
||||||
|
Object.assign(loaded_settings, JSON.parse(fs.readFileSync(settings_json, "utf8")));
|
||||||
${secretSettingsSegment}
|
${secretSettingsSegment}
|
||||||
module.exports = loaded_settings;
|
module.exports = loaded_settings;
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue