diff --git a/include/source.h b/include/source.h index e74407f..c870ebc 100644 --- a/include/source.h +++ b/include/source.h @@ -166,20 +166,6 @@ wr_flathub_sources[] = { -/** - * @time 2023-09-22 更新 - * @note { - * 1. 目前只有一个源 - * 2. 这些链接将会在setsrc函数中补充完整 - * } - */ -wr_nix_sources[] = { - {&Upstream, NULL}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/nix-channels/"} -}, - - - /** * @time 2023-09-11 更新 * @note 目前只有一个源 @@ -228,6 +214,6 @@ def_sources_n(pl_clojure); def_sources_n(pl_dotnet); def_sources_n(wr_flathub); -def_sources_n(wr_nix); def_sources_n(wr_guix); +def_sources_n(wr_guix); def_sources_n(wr_tex); def_sources_n(wr_anaconda); diff --git a/src/chsrc.c b/src/chsrc.c index 48ef3bc..e57f570 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -180,7 +180,7 @@ wr_tex_setsrc (char *option) #include "recipe/ware/WinGet.c" #include "recipe/ware/Homebrew.c" #include "recipe/ware/CocoaPods.c" - +#include "recipe/ware/Nix.c" /** * 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/guix @@ -203,46 +203,6 @@ wr_guix_setsrc (char *option) -void -wr_nix_check_cmd () -{ - chsrc_ensure_program ("nix-channel"); -} - -/** - * 参考: - * 1. https://mirrors.bfsu.edu.cn/help/nix-channels/ - * 2. https://gitee.com/RubyMetric/chsrc/issues/I83894 - */ -void -wr_nix_setsrc (char *option) -{ - wr_nix_check_cmd (); - - SourceInfo source; - chsrc_yield_source (wr_nix); - chsrc_confirm_source (&source); - - char *cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs"); - chsrc_run (cmd, RunOpt_Default); - - char *towrite = xy_strjoin (3, "substituters = ", source.url, "store https://cache.nixos.org/"); - chsrc_append_to_file (towrite , "~/.config/nix/nix.conf"); - - chsrc_run ("nix-channel --update", RunOpt_Default); - - chsrc_note2 ("若您使用的是NixOS,请确认您的系统版本(如22.11),并手动运行:"); - cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs- nixpkgs"); - puts (cmd); - - cmd = xy_strjoin (3, "nix.settings.substituters = [ \"", source.url, "store\" ];"); - chsrc_note2 ("若您使用的是NixOS,请额外添加下述内容至 configuration.nix 中"); - puts (cmd); - - chsrc_say_lastly (&source, ChsrcTypeSemiAuto); -} - - #include "recipe/ware/docker.c" diff --git a/src/recipe/catalog.c b/src/recipe/catalog.c index 9699fde..c935d59 100644 --- a/src/recipe/catalog.c +++ b/src/recipe/catalog.c @@ -93,7 +93,6 @@ static const char def_target_noget (wr_flathub); -def_target_noget (wr_nix); def_target_noget (wr_guix); def_target_noget (wr_anaconda); def_target(wr_tex); diff --git a/src/recipe/ware/Nix.c b/src/recipe/ware/Nix.c new file mode 100644 index 0000000..3c53a98 --- /dev/null +++ b/src/recipe/ware/Nix.c @@ -0,0 +1,64 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-26> + * Last Modified : <2024-08-15> + * ------------------------------------------------------------*/ + +/** + * @time 2023-09-22 更新 + * @note { + * 1. 目前只有一个源 + * 2. 这些链接将会在setsrc函数中补充完整 + * } + */ +static SourceInfo +wr_nix_sources[] = { + {&Upstream, NULL}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/nix-channels/"} +}; +def_sources_n(wr_nix); + + +void +wr_nix_check_cmd () +{ + chsrc_ensure_program ("nix-channel"); +} + +/** + * 参考: + * 1. https://mirrors.bfsu.edu.cn/help/nix-channels/ + * 2. https://gitee.com/RubyMetric/chsrc/issues/I83894 + */ +void +wr_nix_setsrc (char *option) +{ + wr_nix_check_cmd (); + + SourceInfo source; + chsrc_yield_source (wr_nix); + chsrc_confirm_source (&source); + + char *cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs"); + chsrc_run (cmd, RunOpt_Default); + + char *towrite = xy_strjoin (3, "substituters = ", source.url, "store https://cache.nixos.org/"); + chsrc_append_to_file (towrite , "~/.config/nix/nix.conf"); + + chsrc_run ("nix-channel --update", RunOpt_Default); + + chsrc_note2 ("若您使用的是NixOS,请确认您的系统版本(如22.11),并手动运行:"); + cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs- nixpkgs"); + puts (cmd); + + cmd = xy_strjoin (3, "nix.settings.substituters = [ \"", source.url, "store\" ];"); + chsrc_note2 ("若您使用的是NixOS,请额外添加下述内容至 configuration.nix 中"); + puts (cmd); + + chsrc_say_lastly (&source, ChsrcTypeSemiAuto); +} + +def_target_noget (wr_nix);