Skip to content

Commit

Permalink
新增适配 NixOS
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperManito committed Feb 20, 2025
1 parent ba8be87 commit 4d91f7d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 47 deletions.
54 changes: 52 additions & 2 deletions ChangeMirrors.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
## Author: SuperManito
## Modified: 2025-01-22
## Modified: 2025-02-20
## License: MIT
## GitHub: https://github.com/SuperManito/LinuxMirrors
## Website: https://linuxmirrors.cn
Expand Down Expand Up @@ -176,6 +176,7 @@ SYSTEM_OPENSUSE="openSUSE"
SYSTEM_ARCH="Arch"
SYSTEM_ALPINE="Alpine"
SYSTEM_GENTOO="Gentoo"
SYSTEM_NIXOS="NixOS"

## 定义系统版本文件
File_LinuxRelease=/etc/os-release
Expand Down Expand Up @@ -213,13 +214,16 @@ File_GentooMakeConf=/etc/portage/make.conf
File_GentooMakeConfBackup=/etc/portage/make.conf.bak
File_GentooReposConf=/etc/portage/repos.conf/gentoo.conf
File_GentooReposConfBackup=/etc/portage/repos.conf/gentoo.conf.bak
File_NixConf=/etc/nix/nix.conf
File_NixConfBackup=/etc/nix/nix.conf.bak
Dir_GentooReposConf=/etc/portage/repos.conf
Dir_DebianExtendSource=/etc/apt/sources.list.d
Dir_DebianExtendSourceBackup=/etc/apt/sources.list.d.bak
Dir_YumRepos=/etc/yum.repos.d
Dir_YumReposBackup=/etc/yum.repos.d.bak
Dir_ZYppRepos=/etc/zypp/repos.d
Dir_ZYppReposBackup=/etc/zypp/repos.d.bak
Dir_NixConfig=/etc/nix

## 定义颜色变量
RED='\033[31m'
Expand Down Expand Up @@ -660,6 +664,8 @@ function collect_system_info() {
SYSTEM_FACTIONS="${SYSTEM_GENTOO}"
elif [[ "${SYSTEM_NAME}" == *"openSUSE"* ]]; then
SYSTEM_FACTIONS="${SYSTEM_OPENSUSE}"
elif [[ "${SYSTEM_NAME}" == *"NixOS"* ]]; then
SYSTEM_FACTIONS="${SYSTEM_NIXOS}"
else
output_error "当前操作系统不在本脚本的支持范围内,请前往官网查看支持列表!"
fi
Expand Down Expand Up @@ -753,7 +759,7 @@ function collect_system_info() {
;;
esac
;;
"${SYSTEM_KALI}" | "${SYSTEM_DEEPIN}" | "${SYSTEM_ZORIN}" | "${SYSTEM_ARCH}" | "${SYSTEM_ALPINE}" | "${SYSTEM_GENTOO}" | "${SYSTEM_OPENKYLIN}")
"${SYSTEM_KALI}" | "${SYSTEM_DEEPIN}" | "${SYSTEM_ZORIN}" | "${SYSTEM_ARCH}" | "${SYSTEM_ALPINE}" | "${SYSTEM_GENTOO}" | "${SYSTEM_OPENKYLIN}" | "${SYSTEM_NIXOS}")
# 理论全部支持或不作判断
;;
*)
Expand Down Expand Up @@ -860,6 +866,9 @@ function collect_system_info() {
SOURCE_BRANCH="${SOURCE_BRANCH// /-}"
fi
;;
"${SYSTEM_NIXOS}")
SOURCE_BRANCH="nix-channels"
;;
esac
fi
## 定义软件源更新文字
Expand All @@ -876,6 +885,9 @@ function collect_system_info() {
"${SYSTEM_ARCH}" | "${SYSTEM_GENTOO}")
SYNC_MIRROR_TEXT="同步软件源"
;;
"${SYSTEM_NIXOS}")
SYNC_MIRROR_TEXT="更新二进制缓存与频道源"
;;
esac
## 判断是否可以使用高级交互式选择器
CAN_USE_ADVANCED_INTERACTIVE_SELECTION="false"
Expand Down Expand Up @@ -1326,6 +1338,11 @@ function backup_original_mirrors() {
[ -d "${Dir_GentooReposConf}" ] || mkdir -p "${Dir_GentooReposConf}"
backup_file $File_GentooReposConf $File_GentooReposConfBackup "gentoo.conf"
;;
"${SYSTEM_NIXOS}")
[ ! -d $Dir_NixConfig ] && mkdir -p $Dir_NixConfig
# /etc/nix/nix.conf
backup_file $File_NixConf $File_NixConfBackup "nix.conf"
;;
esac
fi
}
Expand Down Expand Up @@ -1523,6 +1540,9 @@ function change_mirrors_main() {
diff_file $File_GentooMakeConfBackup $File_GentooMakeConf
diff_file $File_GentooReposConfBackup $File_GentooReposConf
;;
"${SYSTEM_NIXOS}")
diff_file $File_NixConfBackup $File_NixConf
;;
esac
fi
}
Expand Down Expand Up @@ -1559,6 +1579,9 @@ function change_mirrors_main() {
"${SYSTEM_OPENKYLIN}")
change_mirrors_openKylin
;;
"${SYSTEM_NIXOS}")
change_mirrors_NixOS
;;
esac
## 比较差异
if [[ "${PRINT_DIFF}" == "true" ]]; then
Expand Down Expand Up @@ -1586,6 +1609,10 @@ function change_mirrors_main() {
"${SYSTEM_GENTOO}")
emerge --sync --quiet
;;
"${SYSTEM_NIXOS}")
nix-store --verify
nix-channel --update
;;
esac
if [ $? -eq 0 ]; then
echo -e "\n$SUCCESS 软件源更换完毕"
Expand Down Expand Up @@ -1679,6 +1706,9 @@ function upgrade_software() {
"${SYSTEM_GENTOO}")
emerge --update --deep --with-bdeps=y --ask=n @world
;;
"${SYSTEM_NIXOS}")
nixos-rebuild switch
;;
esac
if [[ "${CLEAN_CACHE}" == "false" ]]; then
return
Expand All @@ -1703,6 +1733,9 @@ function upgrade_software() {
eclean-dist --deep >/dev/null 2>&1
eclean-packages --deep >/dev/null 2>&1
;;
"${SYSTEM_NIXOS}")
nix-collect-garbage -d >/dev/null 2>&1
;;
esac
}
Expand Down Expand Up @@ -2301,6 +2334,23 @@ deb ${1} ${2}-updates ${3}
$(gen_source "${base_url}" "${SYSTEM_VERSION_CODENAME}" "${repository_sections}")" >>$File_DebianSourceList
}
## 更换 NixOS 发行版软件源
function change_mirrors_NixOS() {
local binary_cache_source channel_source
if [[ "${USE_OFFICIAL_SOURCE}" == "true" ]]; then
binary_cache_source="https://cache.nixos.org/"
channel_source="https://nixos.org/channels"
else
binary_cache_source="${WEB_PROTOCOL}://${SOURCE}/${SOURCE_BRANCH}/store https://cache.nixos.org/"
channel_source="${WEB_PROTOCOL}://${SOURCE}/${SOURCE_BRANCH}"
fi
# binary cache
sed -i "s|^substituters.*|substituters = ${binary_cache_source}|g" $File_NixConf
# channel
nix-channel --add "${channel_source}/nixos-${SYSTEM_VERSION_NUMBER}" nixos
nix-channel --update >/dev/null 2>&1
}
## EPEL (Extra Packages for Enterprise Linux) 附加软件包 - 安装或更换软件源
function change_mirrors_or_install_EPEL() {
if [[ "${INSTALL_EPEL}" != "true" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 SuperManito
Copyright (c) 2025 SuperManito

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@
<td align="center">v3 / edge</td>
</tr>
<tr>
<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>
<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>
<td align="center">all</td>
</tr>
<tr>
<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>
<td align="center">all</td>
</tr>
</table>
Expand All @@ -116,7 +120,7 @@

### LICENSE

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

<a href="https://star-history.com/#SuperManito/LinuxMirrors&Date">
<picture>
Expand Down
1 change: 1 addition & 0 deletions docs/assets/images/icon/nixos.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ hide:
| <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_ |
| <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_ |
| <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_ |
| <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_ |

</div>

Expand Down
Loading

0 comments on commit 4d91f7d

Please sign in to comment.