packages.nushell: init

This commit is contained in:
2024-08-29 22:26:24 +08:00
parent a4126c2a22
commit c6609aacfa
4 changed files with 82 additions and 1 deletions

32
lib.nix
View File

@@ -54,4 +54,36 @@ lib: rec
else null
else null)
(attrsToList (builtins.readDir path))));
# replace the value in a nested attrset. example:
# deepReplace
# [ { path = [ "a" "b" 1 ]; value = "new value"; } ]
# { a = { b = [ "old value" "old value" ]; }; }
# => { a = { b = [ "old value" "new value" ]; }; }
deepReplace = pattern: origin:
let replace = { path, value, content }:
if path == [] then
if (builtins.typeOf value) == "lambda" then value content
else value
else let currentPath = builtins.head path; nextPath = builtins.tail path; in
if (builtins.typeOf currentPath) == "string" then
if (builtins.typeOf content) != "set" then builtins.throw "content should be a set"
else builtins.mapAttrs
(n: v: if n == currentPath then replace { path = nextPath; inherit value; content = v; } else v) content
else if (builtins.typeOf currentPath) == "int" then
if (builtins.typeOf content) != "list" then builtins.throw "content should be a list"
else lib.imap0
(i: v: if i == currentPath then replace { path = nextPath; inherit value; content = v; } else v) content
else if (builtins.typeOf currentPath) != "lambda" then throw "path should be a lambda"
else
if (builtins.typeOf content) == "list" then builtins.map
(v: if currentPath v then replace { path = nextPath; inherit value; content = v; } else v) content
else if (builtins.typeOf content) == "set" then builtins.listToAttrs (builtins.map
(v: if currentPath v then replace { path = nextPath; inherit value; content = v; } else v)
(attrsToList content))
else throw "content should be a list or a set.";
in
if (builtins.typeOf pattern) != "list" then throw "pattern should be a list"
else if pattern == [] then origin
else deepReplace (builtins.tail pattern) (replace ((builtins.head pattern) // { content = origin; }));
}

View File

@@ -0,0 +1,48 @@
inputs:
{
options.nixos.packages.nushell = let inherit (inputs.lib) mkOption types; in mkOption
{
type = types.nullOr (types.submodule {});
default = {};
};
config = let inherit (inputs.config.nixos.packages) nushell; in inputs.lib.mkIf (nushell != null)
{
nixos =
{
packages.packages._packages = [ inputs.pkgs.nushell ];
user.sharedModules =
[{
config.programs =
{
nushell =
{
enable = true;
# configFile.source = ./.../config.nu;
# extraConfig = "";
# shellAliases.vi = "hx";
};
carapace.enable = true;
oh-my-posh =
{
enable = true;
enableZshIntegration = false;
settings = inputs.localLib.deepReplace
[
{
path = [ "blocks" 0 "segments" (v: v.type or "" == "path") "properties" "style" ];
value = "powerlevel";
}
{
path = [ "blocks" 0 "segments" (v: v.type or "" == "executiontime") "template" ];
value = v: builtins.replaceStrings [ "\u2800" ] [ "\u0020" ] v;
}
]
(builtins.fromJSON (builtins.readFile
"${inputs.pkgs.oh-my-posh}/share/oh-my-posh/themes/atomic.omp.json"));
};
direnv.enable = true;
};
}];
};
};
}

View File

@@ -10,7 +10,7 @@ inputs:
[
# basic tools
beep dos2unix gnugrep pv tmux screen parallel tldr cowsay jq zellij ipfetch localPackages.pslist
fastfetch reptyr nushell duc ncdu progress libva-utils ksh neofetch
fastfetch reptyr duc ncdu progress libva-utils ksh neofetch
# lsxx
pciutils usbutils lshw util-linux lsof dmidecode lm_sensors
# top

View File

@@ -10,6 +10,7 @@ inputs:
(builtins.attrNames inputs.config.users.groups);
autoSubUidGidRange = true;
hashedPassword = "$y$j9T$xJwVBoGENJEDSesJ0LfkU1$VEExaw7UZtFyB4VY1yirJvl7qS7oiF49KbEBrV0.hhC";
shell = inputs.lib.mkForce inputs.pkgs.nushell;
};
home-manager.users.chn =
{