Skip to content

Commit 4d91f7d

Browse files
committed
新增适配 NixOS
1 parent ba8be87 commit 4d91f7d

File tree

10 files changed

+119
-47
lines changed

10 files changed

+119
-47
lines changed

ChangeMirrors.sh

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
## Author: SuperManito
3-
## Modified: 2025-01-22
3+
## Modified: 2025-02-20
44
## License: MIT
55
## GitHub: https://github.com/SuperManito/LinuxMirrors
66
## Website: https://linuxmirrors.cn
@@ -176,6 +176,7 @@ SYSTEM_OPENSUSE="openSUSE"
176176
SYSTEM_ARCH="Arch"
177177
SYSTEM_ALPINE="Alpine"
178178
SYSTEM_GENTOO="Gentoo"
179+
SYSTEM_NIXOS="NixOS"
179180

180181
## 定义系统版本文件
181182
File_LinuxRelease=/etc/os-release
@@ -213,13 +214,16 @@ File_GentooMakeConf=/etc/portage/make.conf
213214
File_GentooMakeConfBackup=/etc/portage/make.conf.bak
214215
File_GentooReposConf=/etc/portage/repos.conf/gentoo.conf
215216
File_GentooReposConfBackup=/etc/portage/repos.conf/gentoo.conf.bak
217+
File_NixConf=/etc/nix/nix.conf
218+
File_NixConfBackup=/etc/nix/nix.conf.bak
216219
Dir_GentooReposConf=/etc/portage/repos.conf
217220
Dir_DebianExtendSource=/etc/apt/sources.list.d
218221
Dir_DebianExtendSourceBackup=/etc/apt/sources.list.d.bak
219222
Dir_YumRepos=/etc/yum.repos.d
220223
Dir_YumReposBackup=/etc/yum.repos.d.bak
221224
Dir_ZYppRepos=/etc/zypp/repos.d
222225
Dir_ZYppReposBackup=/etc/zypp/repos.d.bak
226+
Dir_NixConfig=/etc/nix
223227

224228
## 定义颜色变量
225229
RED='\033[31m'
@@ -660,6 +664,8 @@ function collect_system_info() {
660664
SYSTEM_FACTIONS="${SYSTEM_GENTOO}"
661665
elif [[ "${SYSTEM_NAME}" == *"openSUSE"* ]]; then
662666
SYSTEM_FACTIONS="${SYSTEM_OPENSUSE}"
667+
elif [[ "${SYSTEM_NAME}" == *"NixOS"* ]]; then
668+
SYSTEM_FACTIONS="${SYSTEM_NIXOS}"
663669
else
664670
output_error "当前操作系统不在本脚本的支持范围内,请前往官网查看支持列表!"
665671
fi
@@ -753,7 +759,7 @@ function collect_system_info() {
753759
;;
754760
esac
755761
;;
756-
"${SYSTEM_KALI}" | "${SYSTEM_DEEPIN}" | "${SYSTEM_ZORIN}" | "${SYSTEM_ARCH}" | "${SYSTEM_ALPINE}" | "${SYSTEM_GENTOO}" | "${SYSTEM_OPENKYLIN}")
762+
"${SYSTEM_KALI}" | "${SYSTEM_DEEPIN}" | "${SYSTEM_ZORIN}" | "${SYSTEM_ARCH}" | "${SYSTEM_ALPINE}" | "${SYSTEM_GENTOO}" | "${SYSTEM_OPENKYLIN}" | "${SYSTEM_NIXOS}")
757763
# 理论全部支持或不作判断
758764
;;
759765
*)
@@ -860,6 +866,9 @@ function collect_system_info() {
860866
SOURCE_BRANCH="${SOURCE_BRANCH// /-}"
861867
fi
862868
;;
869+
"${SYSTEM_NIXOS}")
870+
SOURCE_BRANCH="nix-channels"
871+
;;
863872
esac
864873
fi
865874
## 定义软件源更新文字
@@ -876,6 +885,9 @@ function collect_system_info() {
876885
"${SYSTEM_ARCH}" | "${SYSTEM_GENTOO}")
877886
SYNC_MIRROR_TEXT="同步软件源"
878887
;;
888+
"${SYSTEM_NIXOS}")
889+
SYNC_MIRROR_TEXT="更新二进制缓存与频道源"
890+
;;
879891
esac
880892
## 判断是否可以使用高级交互式选择器
881893
CAN_USE_ADVANCED_INTERACTIVE_SELECTION="false"
@@ -1326,6 +1338,11 @@ function backup_original_mirrors() {
13261338
[ -d "${Dir_GentooReposConf}" ] || mkdir -p "${Dir_GentooReposConf}"
13271339
backup_file $File_GentooReposConf $File_GentooReposConfBackup "gentoo.conf"
13281340
;;
1341+
"${SYSTEM_NIXOS}")
1342+
[ ! -d $Dir_NixConfig ] && mkdir -p $Dir_NixConfig
1343+
# /etc/nix/nix.conf
1344+
backup_file $File_NixConf $File_NixConfBackup "nix.conf"
1345+
;;
13291346
esac
13301347
fi
13311348
}
@@ -1523,6 +1540,9 @@ function change_mirrors_main() {
15231540
diff_file $File_GentooMakeConfBackup $File_GentooMakeConf
15241541
diff_file $File_GentooReposConfBackup $File_GentooReposConf
15251542
;;
1543+
"${SYSTEM_NIXOS}")
1544+
diff_file $File_NixConfBackup $File_NixConf
1545+
;;
15261546
esac
15271547
fi
15281548
}
@@ -1559,6 +1579,9 @@ function change_mirrors_main() {
15591579
"${SYSTEM_OPENKYLIN}")
15601580
change_mirrors_openKylin
15611581
;;
1582+
"${SYSTEM_NIXOS}")
1583+
change_mirrors_NixOS
1584+
;;
15621585
esac
15631586
## 比较差异
15641587
if [[ "${PRINT_DIFF}" == "true" ]]; then
@@ -1586,6 +1609,10 @@ function change_mirrors_main() {
15861609
"${SYSTEM_GENTOO}")
15871610
emerge --sync --quiet
15881611
;;
1612+
"${SYSTEM_NIXOS}")
1613+
nix-store --verify
1614+
nix-channel --update
1615+
;;
15891616
esac
15901617
if [ $? -eq 0 ]; then
15911618
echo -e "\n$SUCCESS 软件源更换完毕"
@@ -1679,6 +1706,9 @@ function upgrade_software() {
16791706
"${SYSTEM_GENTOO}")
16801707
emerge --update --deep --with-bdeps=y --ask=n @world
16811708
;;
1709+
"${SYSTEM_NIXOS}")
1710+
nixos-rebuild switch
1711+
;;
16821712
esac
16831713
if [[ "${CLEAN_CACHE}" == "false" ]]; then
16841714
return
@@ -1703,6 +1733,9 @@ function upgrade_software() {
17031733
eclean-dist --deep >/dev/null 2>&1
17041734
eclean-packages --deep >/dev/null 2>&1
17051735
;;
1736+
"${SYSTEM_NIXOS}")
1737+
nix-collect-garbage -d >/dev/null 2>&1
1738+
;;
17061739
esac
17071740
}
17081741
@@ -2301,6 +2334,23 @@ deb ${1} ${2}-updates ${3}
23012334
$(gen_source "${base_url}" "${SYSTEM_VERSION_CODENAME}" "${repository_sections}")" >>$File_DebianSourceList
23022335
}
23032336
2337+
## 更换 NixOS 发行版软件源
2338+
function change_mirrors_NixOS() {
2339+
local binary_cache_source channel_source
2340+
if [[ "${USE_OFFICIAL_SOURCE}" == "true" ]]; then
2341+
binary_cache_source="https://cache.nixos.org/"
2342+
channel_source="https://nixos.org/channels"
2343+
else
2344+
binary_cache_source="${WEB_PROTOCOL}://${SOURCE}/${SOURCE_BRANCH}/store https://cache.nixos.org/"
2345+
channel_source="${WEB_PROTOCOL}://${SOURCE}/${SOURCE_BRANCH}"
2346+
fi
2347+
# binary cache
2348+
sed -i "s|^substituters.*|substituters = ${binary_cache_source}|g" $File_NixConf
2349+
# channel
2350+
nix-channel --add "${channel_source}/nixos-${SYSTEM_VERSION_NUMBER}" nixos
2351+
nix-channel --update >/dev/null 2>&1
2352+
}
2353+
23042354
## EPEL (Extra Packages for Enterprise Linux) 附加软件包 - 安装或更换软件源
23052355
function change_mirrors_or_install_EPEL() {
23062356
if [[ "${INSTALL_EPEL}" != "true" ]]; then

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 SuperManito
3+
Copyright (c) 2025 SuperManito
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@
9999
<td align="center">v3 / edge</td>
100100
</tr>
101101
<tr>
102-
<td><a href="https://www.gentoo.org" target="_blank"><img src="./docs/assets/images/icon/gentoo.svg" width="16" height="16" style="vertical-align: -0.25em"/></a>&nbsp;Gentoo</td>
102+
<td><a href="https://www.gentoo.org" target="_blank"><img src="./docs/assets/images/icon/gentoo.svg" width="16" height="16" style="vertical-align: -0.2em"/></a>&nbsp;Gentoo</td>
103+
<td align="center">all</td>
104+
</tr>
105+
<tr>
106+
<td><a href="https://nixos.org" target="_blank"><img src="./docs/assets/images/icon/nixos.svg" width="16" height="16" style="vertical-align: -0.15em"/></a>&nbsp;NixOS</td>
103107
<td align="center">all</td>
104108
</tr>
105109
</table>
@@ -116,7 +120,7 @@
116120

117121
### LICENSE
118122

119-
Copyright © 2024, [SuperManito](https://github.com/SuperManito). Released under the [MIT](https://github.com/SuperManito/LinuxMirrors/blob/main/LICENSE).
123+
Copyright © 2025, [SuperManito](https://github.com/SuperManito). Released under the [MIT](https://github.com/SuperManito/LinuxMirrors/blob/main/LICENSE).
120124

121125
<a href="https://star-history.com/#SuperManito/LinuxMirrors&Date">
122126
<picture>

docs/assets/images/icon/nixos.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ hide:
118118
| <a href="https://archlinux.org" target="_blank"><img src="/assets/images/icon/arch-linux.ico" width="16" height="16" style="vertical-align: -0.15em"></a> Arch Linux | _all_ |
119119
| <a href="https://www.alpinelinux.org" target="_blank"><img src="/assets/images/icon/alpine.png" width="16" height="16" style="vertical-align: -0.15em"></a> Alpine Linux | _v3 / edge_ |
120120
| <a href="https://www.gentoo.org" target="_blank"><img src="/assets/images/icon/gentoo.svg" width="16" height="16" style="vertical-align: -0.2em"></a> Gentoo | _all_ |
121+
| <a href="https://nixos.org" target="_blank"><img src="/assets/images/icon/nixos.svg" width="16" height="16" style="vertical-align: -0.15em"></a> NixOS | _19 ~ 24_ |
121122

122123
</div>
123124

0 commit comments

Comments
 (0)