diff --git a/chsrc.c b/chsrc.c index 1c6f861..5a1f1e7 100644 --- a/chsrc.c +++ b/chsrc.c @@ -1695,7 +1695,7 @@ wr_brew_setsrc(char* option) * 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/guix */ void -wr_guix_setsrc(char* option) +wr_guix_setsrc (char* option) { int index = 0; if (NULL!=option) { @@ -1712,12 +1712,52 @@ wr_guix_setsrc(char* option) " (inherit (car %default-channels))\n" " (url \"", source.url, "\")))"); - xy_warn ("chsrc: 请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中"); + xy_warn ("chsrc: 为防止扰乱配置文件,请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中"); puts(file); chsrc_say_thanks(&source); } +void +pl_nix_check_cmd_() +{ + char* check_cmd = xy_str_to_quietcmd("nix-channel --version"); + bool exist = does_the_program_exist (check_cmd, "nix-channel"); + + if (!exist) { + xy_error ("chsrc: 未找到 nix-channel 命令,请检查是否存在"); + exit(1); + } +} + +/** + * 参考: https://mirrors.bfsu.edu.cn/help/nix-channels/ + */ +void +wr_nix_setsrc (char* option) +{ + pl_nix_check_cmd_(); + + int index = 0; + if (NULL!=option) { + index = lets_find_mirror(wr_nix, option); + } else { + index = lets_test_speed(wr_nix); + } + + source_info source = wr_nix_sources[index]; + chsrc_say_selection (&source); + + char* cmd = xy_strjoin(3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs"); + chsrc_runcmd(cmd); + + cmd = "nix-channel --update"; + chsrc_runcmd(cmd); + + chsrc_say_thanks(&source); +} + + /** * 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/flathub @@ -1903,6 +1943,7 @@ def_target_info(wr_tex); target_info wr_flathub_target = {wr_flathub_setsrc, NULL, wr_flathub_sources, wr_flathub_sources_n}, + wr_nix_target = {wr_nix_setsrc, NULL, wr_nix_sources, wr_nix_sources_n}, wr_guix_target = {wr_guix_setsrc, NULL, wr_guix_sources, wr_guix_sources_n}, wr_emacs_target = {wr_emacs_setsrc, NULL, wr_emacs_sources, wr_emacs_sources_n}, wr_anaconda_target = {wr_anaconda_setsrc, NULL, wr_anaconda_sources, wr_anaconda_sources_n}; @@ -1910,13 +1951,14 @@ target_info static const char *wr_brew [] = {"brew", "homebrew", NULL, targetinfo(&wr_brew_target)}, *wr_flathub [] = {"flathub", NULL, targetinfo(&wr_flathub_target)}, +*wr_nix [] = {"nix", NULL, targetinfo(&wr_nix_target)}, *wr_guix [] = {"guix", NULL, targetinfo(&wr_guix_target)}, *wr_emacs [] = {"emacs", "elpa", NULL, targetinfo(&wr_emacs_target)}, *wr_tex [] = {"latex", "ctan", "tex", "texlive", "miktex", "tlmgr", "mpm", NULL, targetinfo(&wr_tex_target)}, *wr_anaconda[] = {"conda", "anaconda", NULL, targetinfo(&wr_anaconda_target)}, **wr_softwares[] = { - wr_brew, wr_flathub, wr_guix, wr_emacs, wr_tex, wr_anaconda + wr_brew, wr_flathub, wr_nix, wr_guix, wr_emacs, wr_tex, wr_anaconda }; #undef targetinfo /************************************** End Target Matrix ****************************************/ diff --git a/sources.h b/sources.h index c80d385..434082c 100644 --- a/sources.h +++ b/sources.h @@ -3,7 +3,7 @@ * License : GPLv3 * Authors : Aoran Zeng * Created on : <2023-08-29> - * Last modified : <2023-09-15> + * Last modified : <2023-09-22> * * sources: * @@ -625,6 +625,19 @@ wr_flathub_sources[] = { }, + +/** + * 2023-09-22 更新 + * + * @note 1. 目前只有一个源 + * 2. 这些链接将会在setsrc函数中补充完整 + */ +wr_nix_sources[] = { + {&Bfsu, "https://mirrors.bfsu.edu.cn/nix-channels/"} +}, + + + /** * 2023-09-11 更新 * @@ -635,10 +648,11 @@ wr_guix_sources[] = { }, + /** * 2023-09-10 更新 * - * @note 1. 这些链接将会在setsrc函数中补充完整 + * @note 这些链接将会在setsrc函数中补充完整 */ wr_anaconda_sources[] = { {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/anaconda/"}, @@ -648,21 +662,23 @@ wr_anaconda_sources[] = { }; + #define def_target_sources_n(t) const size_t t##_sources_n = xy_arylen(t##_sources) -def_target_sources_n(pl_ruby); def_target_sources_n(pl_python); def_target_sources_n(pl_nodejs); -def_target_sources_n(pl_perl); def_target_sources_n(pl_php); def_target_sources_n(pl_go); -def_target_sources_n(pl_rust); def_target_sources_n(pl_java); def_target_sources_n(pl_clojure); -def_target_sources_n(pl_dotnet); def_target_sources_n(pl_dart); def_target_sources_n(pl_haskell); +def_target_sources_n(pl_ruby); def_target_sources_n(pl_python); def_target_sources_n(pl_nodejs); +def_target_sources_n(pl_perl); def_target_sources_n(pl_php); def_target_sources_n(pl_go); +def_target_sources_n(pl_rust); def_target_sources_n(pl_java); def_target_sources_n(pl_clojure); +def_target_sources_n(pl_dotnet); def_target_sources_n(pl_dart); def_target_sources_n(pl_haskell); def_target_sources_n(pl_ocaml); -def_target_sources_n(pl_r); def_target_sources_n(pl_julia); +def_target_sources_n(pl_r); def_target_sources_n(pl_julia); -def_target_sources_n(os_ubuntu); def_target_sources_n(os_debian); def_target_sources_n(os_fedora); -def_target_sources_n(os_kali); def_target_sources_n(os_openbsd); def_target_sources_n(os_msys2); -def_target_sources_n(os_arch); def_target_sources_n(os_gentoo); def_target_sources_n(os_netbsd); -def_target_sources_n(os_deepin); def_target_sources_n(os_openeuler); def_target_sources_n(os_openkylin); -def_target_sources_n(os_freebsd); def_target_sources_n(os_opensuse); +def_target_sources_n(os_ubuntu); def_target_sources_n(os_debian); def_target_sources_n(os_fedora); +def_target_sources_n(os_kali); def_target_sources_n(os_openbsd); def_target_sources_n(os_msys2); +def_target_sources_n(os_arch); def_target_sources_n(os_gentoo); def_target_sources_n(os_netbsd); +def_target_sources_n(os_deepin); def_target_sources_n(os_openeuler); def_target_sources_n(os_openkylin); +def_target_sources_n(os_freebsd); def_target_sources_n(os_opensuse); -def_target_sources_n(wr_brew); def_target_sources_n(wr_guix); def_target_sources_n(wr_flathub); -def_target_sources_n(wr_tex); def_target_sources_n(wr_emacs); +def_target_sources_n(wr_brew); def_target_sources_n(wr_flathub); +def_target_sources_n(wr_nix); def_target_sources_n(wr_guix); +def_target_sources_n(wr_tex); def_target_sources_n(wr_emacs); def_target_sources_n(wr_anaconda);