fork/home-manager
git clone https://git.julia.blue/fork/home-manager
8c731978
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . nushell ; 8 9configDir = if pkgs . stdenv . isDarwin then 10"Library/Application Support/nushell" 11else 12" ${ config . xdg . configHome } /nushell" ; 13 14linesOrSource = name : 15types . submodule ({ config , ...} :{ 16options = { 17text = mkOption { 18type = types . lines ; 19default = if config . source != null then 20builtins . readFile config . source 21else 22"" ; 23defaultText = literalExpression 24"if source is defined, the content of source, otherwise empty" ; 25description = '' 26Text of the nushell {file}` ${ name } ` file. 27If unset then the source option will be preferred. 28'' ; 29}; 30 31source = mkOption { 32type = types . nullOr types . path ; 33default = null ; 34description = '' 35Path of the nushell {file}` ${ name } ` file to use. 36If the text option is set, it will be preferred. 37'' ; 38}; 39}; 40}); 41in { 42meta . maintainers = [ maintainers . Philipp-M ]; 43 44imports = [ 45( mkRemovedOptionModule [ "programs" "nushell" "settings" ] '' 46Please use 47 48'programs.nushell.configFile' and 'programs.nushell.envFile' 49 50instead. 51'' ) 52]; 53 54options . programs . nushell = { 55enable = mkEnableOption "nushell" ; 56 57package = mkOption { 58type = types . package ; 59default = pkgs . nushell ; 60defaultText = literalExpression "pkgs.nushell" ; 61description = "The package to use for nushell." ; 62}; 63 64configFile = mkOption { 65type = types . nullOr ( linesOrSource "config.nu" ); 66default = null ; 67example = literalExpression '' 68{ text = ''' 69let $config = { 70filesize_metric: false 71table_mode: rounded 72use_ls_colors: true 73} 74'''; 75} 76'' ; 77description = '' 78The configuration file to be used for nushell. 79 80See <https://www.nushell.sh/book/configuration.html#configuration> for more information. 81'' ; 82}; 83 84envFile = mkOption { 85type = types . nullOr ( linesOrSource "env.nu" ); 86default = null ; 87example = '' 88$env.FOO = 'BAR' 89'' ; 90description = '' 91The environment variables file to be used for nushell. 92 93See <https://www.nushell.sh/book/configuration.html#configuration> for more information. 94'' ; 95}; 96 97loginFile = mkOption { 98type = types . nullOr ( linesOrSource "login.nu" ); 99default = null ; 100example = '' 101# Prints "Hello, World" upon logging into tty1 102if (tty) == "/dev/tty1" { 103echo "Hello, World" 104} 105'' ; 106description = '' 107The login file to be used for nushell upon logging in. 108 109See <https://www.nushell.sh/book/configuration.html#configuring-nu-as-a-login-shell> for more information. 110'' ; 111}; 112 113extraConfig = mkOption { 114type = types . lines ; 115default = "" ; 116description = '' 117Additional configuration to add to the nushell configuration file. 118'' ; 119}; 120 121extraEnv = mkOption { 122type = types . lines ; 123default = "" ; 124description = '' 125Additional configuration to add to the nushell environment variables file. 126'' ; 127}; 128 129extraLogin = mkOption { 130type = types . lines ; 131default = "" ; 132description = '' 133Additional configuration to add to the nushell login file. 134'' ; 135}; 136 137shellAliases = mkOption { 138type = types . attrsOf types . str ; 139default = { }; 140example = { ll = "ls -l" ; }; 141description = '' 142An attribute set that maps aliases (the top level attribute names in 143this option) to command strings or directly to build outputs. 144'' ; 145}; 146 147environmentVariables = mkOption { 148type = types . attrsOf types . str ; 149default = { }; 150example = { FOO = "BAR" ; }; 151description = '' 152An attribute set that maps an environment variable to a shell interpreted string. 153'' ; 154}; 155}; 156 157config = mkIf cfg . enable { 158home . packages = [ cfg . package ]; 159 160home . file = mkMerge [ 161( let 162writeConfig = cfg . configFile != null || cfg . extraConfig != "" 163|| aliasesStr != "" ; 164 165aliasesStr = concatStringsSep "\n" 166( mapAttrsToList ( k :v :"alias ${ k } = ${ v } " ) cfg . shellAliases ); 167in mkIf writeConfig { 168" ${ configDir } /config.nu" . text = mkMerge [ 169( mkIf ( cfg . configFile != null ) cfg . configFile . text ) 170cfg . extraConfig 171aliasesStr 172]; 173}) 174 175( let 176envVarsStr = concatStringsSep "\n" 177( mapAttrsToList ( k :v :"$env. ${ k } = ${ v } " ) cfg . environmentVariables ); 178in mkIf ( cfg . envFile != null || cfg . extraEnv != "" || envVarsStr != "" ) { 179" ${ configDir } /env.nu" . text = mkMerge [ 180( mkIf ( cfg . envFile != null ) cfg . envFile . text ) 181cfg . extraEnv 182envVarsStr 183]; 184}) 185( mkIf ( cfg . loginFile != null || cfg . extraLogin != "" ) { 186" ${ configDir } /login.nu" . text = mkMerge [ 187( mkIf ( cfg . loginFile != null ) cfg . loginFile . text ) 188cfg . extraLogin 189]; 190}) 191]; 192}; 193}