mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-25 19:51:04 +01:00
nushell: add settings option
This commit is contained in:
parent
a1df6c4c76
commit
46c83c07b9
4 changed files with 65 additions and 16 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
{ lib }: rec {
|
{ lib }: rec {
|
||||||
mkNushellInline = expr: lib.setType "nushell-inline" { inherit expr; };
|
mkNushellInline = expr: lib.setType "nushell-inline" { inherit expr; };
|
||||||
|
|
||||||
toNushell = { indent ? "", multiline ? true, asBindings ? false }@args:
|
isNushellInline = lib.isType "nushell-inline";
|
||||||
|
|
||||||
|
toNushell = { indent ? "", multiline ? true, asBindings ? false, }@args:
|
||||||
v:
|
v:
|
||||||
let
|
let
|
||||||
innerIndent = "${indent} ";
|
innerIndent = "${indent} ";
|
||||||
|
|
@ -18,7 +20,6 @@
|
||||||
asBindings = false;
|
asBindings = false;
|
||||||
};
|
};
|
||||||
concatItems = lib.concatStringsSep introSpace;
|
concatItems = lib.concatStringsSep introSpace;
|
||||||
isNushellInline = lib.isType "nushell-inline";
|
|
||||||
|
|
||||||
generatedBindings = assert lib.assertMsg (badVarNames == [ ])
|
generatedBindings = assert lib.assertMsg (badVarNames == [ ])
|
||||||
"Bad Nushell variable names: ${
|
"Bad Nushell variable names: ${
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
inherit (lib.hm.nushell) toNushell;
|
inherit (lib.hm.nushell) isNushellInline toNushell;
|
||||||
cfg = config.programs.nushell;
|
cfg = config.programs.nushell;
|
||||||
|
|
||||||
configDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
configDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
||||||
|
|
@ -43,16 +43,6 @@ in {
|
||||||
aidalgol
|
aidalgol
|
||||||
];
|
];
|
||||||
|
|
||||||
imports = [
|
|
||||||
(lib.mkRemovedOptionModule [ "programs" "nushell" "settings" ] ''
|
|
||||||
Please use
|
|
||||||
|
|
||||||
'programs.nushell.configFile' and 'programs.nushell.envFile'
|
|
||||||
|
|
||||||
instead.
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
|
|
||||||
options.programs.nushell = {
|
options.programs.nushell = {
|
||||||
enable = lib.mkEnableOption "nushell";
|
enable = lib.mkEnableOption "nushell";
|
||||||
|
|
||||||
|
|
@ -142,6 +132,35 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
settings = lib.mkOption {
|
||||||
|
type = types.attrsOf lib.hm.types.nushellValue;
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
show_banner = false;
|
||||||
|
history.format = "sqlite";
|
||||||
|
};
|
||||||
|
description = ''
|
||||||
|
Nushell settings. These will be flattened and assigned one by one to `$env.config` to avoid overwriting the default or existing options.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
show_banner = false;
|
||||||
|
completions.external = {
|
||||||
|
enable = true;
|
||||||
|
max_results = 200;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
becomes:
|
||||||
|
```nushell
|
||||||
|
$env.config.completions.external.enable = true
|
||||||
|
$env.config.completions.external.max_results = 200
|
||||||
|
$env.config.show_banner = false
|
||||||
|
```
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
shellAliases = lib.mkOption {
|
shellAliases = lib.mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
default = { };
|
default = { };
|
||||||
|
|
@ -180,12 +199,28 @@ in {
|
||||||
home.file = lib.mkMerge [
|
home.file = lib.mkMerge [
|
||||||
(let
|
(let
|
||||||
writeConfig = cfg.configFile != null || cfg.extraConfig != ""
|
writeConfig = cfg.configFile != null || cfg.extraConfig != ""
|
||||||
|| aliasesStr != "";
|
|| aliasesStr != "" || cfg.settings != { };
|
||||||
|
|
||||||
aliasesStr = lib.concatLines
|
aliasesStr = lib.concatLines
|
||||||
(lib.mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases);
|
(lib.mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases);
|
||||||
in lib.mkIf writeConfig {
|
in lib.mkIf writeConfig {
|
||||||
"${configDir}/config.nu".text = lib.mkMerge [
|
"${configDir}/config.nu".text = lib.mkMerge [
|
||||||
|
(let
|
||||||
|
flattenSettings = let
|
||||||
|
joinDot = a: b: "${if a == "" then "" else "${a}."}${b}";
|
||||||
|
unravel = prefix: value:
|
||||||
|
if lib.isAttrs value && !isNushellInline value then
|
||||||
|
lib.concatMap (key: unravel (joinDot prefix key) value.${key})
|
||||||
|
(builtins.attrNames value)
|
||||||
|
else
|
||||||
|
[ (lib.nameValuePair prefix value) ];
|
||||||
|
in unravel "";
|
||||||
|
mkLine = { name, value }: ''
|
||||||
|
$env.config.${name} = ${toNushell { } value}
|
||||||
|
'';
|
||||||
|
settingsLines =
|
||||||
|
lib.concatMapStrings mkLine (flattenSettings cfg.settings);
|
||||||
|
in lib.mkIf (cfg.settings != { }) settingsLines)
|
||||||
(lib.mkIf (cfg.configFile != null) cfg.configFile.text)
|
(lib.mkIf (cfg.configFile != null) cfg.configFile.text)
|
||||||
cfg.extraConfig
|
cfg.extraConfig
|
||||||
aliasesStr
|
aliasesStr
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
let $config = {
|
$env.config.display_errors.exit_code = false
|
||||||
|
$env.config.hooks.pre_execution = [
|
||||||
|
({|| "pre_execution hook"})
|
||||||
|
]
|
||||||
|
$env.config.show_banner = false
|
||||||
|
|
||||||
|
let config = {
|
||||||
filesize_metric: false
|
filesize_metric: false
|
||||||
table_mode: rounded
|
table_mode: rounded
|
||||||
use_ls_colors: true
|
use_ls_colors: true
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
configFile.text = ''
|
configFile.text = ''
|
||||||
let $config = {
|
let config = {
|
||||||
filesize_metric: false
|
filesize_metric: false
|
||||||
table_mode: rounded
|
table_mode: rounded
|
||||||
use_ls_colors: true
|
use_ls_colors: true
|
||||||
|
|
@ -30,6 +30,13 @@
|
||||||
"ll" = "ls -a";
|
"ll" = "ls -a";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
show_banner = false;
|
||||||
|
display_errors.exit_code = false;
|
||||||
|
hooks.pre_execution =
|
||||||
|
[ (lib.hm.nushell.mkNushellInline ''{|| "pre_execution hook"}'') ];
|
||||||
|
};
|
||||||
|
|
||||||
environmentVariables = {
|
environmentVariables = {
|
||||||
FOO = "BAR";
|
FOO = "BAR";
|
||||||
LIST_VALUE = [ "foo" "bar" ];
|
LIST_VALUE = [ "foo" "bar" ];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue