Merge branch 'master' of https://github.com/LCTT/TranslateProject into translating

This commit is contained in:
geekpi 2023-03-27 08:54:17 +08:00
commit c224390331
29 changed files with 5259 additions and 652 deletions

View File

@ -0,0 +1,130 @@
[#]: subject: "Learn everything about computers with this Raspberry Pi kit"
[#]: via: "https://opensource.com/article/21/9/raspberry-pi-crowpi2"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "XiaotingHuang22"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15656-1.html"
用 CrowPi 树莓派套件了解关于计算机的一切
======
> CrowPi 是一个超棒的树莓派项目系统,安装在一个笔记本电脑般的外壳里。
![][0]
我喜欢历史,也喜欢计算机,因此相比于计算机如何变成个人配件,我更喜欢听它在成为日常家用电器前的故事。[我经常听到的一个故事][2] 是很久以前(反正在计算机时代算久远了)的计算机是多么的简单。事实上,它们简单到对于一个好奇的用户来说,弄清楚如何编程并不是十分困难。再看看现代计算机,它具有面向对象的编程语言、复杂的 GUI 框架、网络 API、容器等但愈发令人担忧的是计算工具正变得越来越难懂对于那些没有接受过专门培训的人来说基本上无法使用。
从树莓派在 2012 年发布之日起,它就一直被定位为一个教育平台。一些第三方供应商通过附加组件和培训套件支持树莓派,以帮助所有年龄段的学习者探索编程、物理计算和开源。然而,直到最近,很大程度上还是要由用户来弄清楚市场上的所有部件如何组合在一起,直到我最近买了 CrowPi。
![CrowPi 不是一个笔记本电脑][3]
### CrowPi2 介绍
乌鸦是非常聪明的鸟。它们能识别并记住面孔模仿听到的声音解决复杂的谜题甚至使用工具来完成任务。CrowPi 使用乌鸦作为其徽标和名字是恰当的,因为这个设备充满了探索、实验、教育的机会,最重要的是,充满了乐趣。
其设计很巧妙:它看起来像笔记本电脑,但远不止于此。当你从机壳中取出蓝牙键盘时,它会显示一个隐藏的电子设备工坊,配有 LCD 屏幕、16 个按钮、刻度盘、RFID 传感器、接近传感器、线路板、扬声器、GPIO 连接、LED 阵列等等。_而且这一切都是可编程的。_
顾名思义,该装置本身完全由树莓派提供支持,它牢固地固定在机壳底部。
![CrowPi 的树莓派板][5]
默认情况下,你应该用电源适配器为设备充电,包装附带一个壁式插头,你可以将其插入机壳,而不是直接为树莓派供电。你还可以使用插入外部微型 USB 端口的电池电源。机壳内甚至还有一个抽屉,方便你存放电池。这样做的时候,有一根 USB 线从电池抽屉中弹出,并插入机壳电源端口,因此你不会产生这是一台“普通”笔记本电脑的错觉。然而,这样一台设备能够有如此美观的设计已经很理想了!
### 首次启动系统
CrowPi2 提供一张安装了 Raspbian 系统,贴有 “System” 标签的 microSD 卡,不过它同时还提供了装载 [RetroPie][6] 的第二张 microSD 卡。作为一个负责任的成年人(咳咳),我自然是先启动了 RetroPie。
RetroPie 总是很有趣CrowPi2 附带两个超任风格的游戏控制器,确保你能获得最佳的复古游戏体验。
令人赞叹不已的是,启动实际的 Raspbian 系统的过程同样有趣甚至可以说更有趣。它的登录管理器是一个自定义项目中心有一些快速链接如编程示例项目、Python 和 Arduino IDE、Scratch、Python 示例游戏、Minecraft 等。你也可以选择退出项目中心,只使用桌面。
![CrowPi 中心][7]
对于习惯使用树莓派或 Linux 的人来说CrowPi 桌面很熟悉,不过它也足够简单,所以很容易上手。左上角有应用程序菜单,桌面上有快捷图标,右上角有网络选择和音量控制的系统托盘等等。
![CrowPi 桌面][8]
CrowPi 上有很多东西可供选择所以你可能很难决定从哪里开始。对我来说主要分为四大类编程、物理电子学、Linux 和游戏。
盒子里有一本使用说明,所以你会知道你需要怎样进行连接(例如,键盘是电池供电的,所以它有时确实需要充电,它和鼠标总是需要一个 USB 适配器)。虽然说明书很快就能读完,但这一例子也充分体现了 CrowPi 团队是如何认真对待说明书的。
![CrowPi 文档][9]
### 编程
如果你想学习如何编码,在 CrowPi 上有很多成功的途径。你可以从中选择你觉得最满意的路径。
#### 1、Scratch
[Scratch][10] 是一个简单的可视化编码应用程序,可让你像拼 [乐高积木][11] 一样将代码块组合在一起,制作出游戏和互动故事。这是开启编程之旅最简单的方法,我曾见过年仅 8 岁的孩子会花数小时来研究自己设计的游戏的最佳算法。当然,它不仅适合孩子们!成年人也可以从中获得很多乐趣。不知道从哪里开始?包装盒中有一本 99 页的小册子(打印在纸张上),其中包含 Scratch 课程和项目供你尝试。
#### 2、Java 和 Minecraft
Minecraft 不是开源的(虽然有 [几个开源项目][12] 复刻了它但它有足够的可用资源因此也经常被用来教授编程。Minecraft 是用 Java 编写的CrowPi 同时装载有 [Minecraft Pi Edition][13] 和 [BlueJ Java IDE][14] ,如此可使学习 Java 变得比以往更容易、更有趣。
#### 3、Python 和 PyGame
CrowPi 上有几个非常有趣的游戏,它们是用 Python 和 [PyGame 游戏引擎][15] 编写的。你可以玩这些游戏然后查看其源代码以了解游戏的运行方式。CrowPi 中包含 Geany、Thonny 和 [Mu][16] 编辑器,因此你可以使用 Python 立即开始编程。与 Scratch 一样,包装盒中有一本包含有课程的小册子,因此你可以学习 Python 基础知识。
### 电子器件
隐藏在键盘下的物理电子工坊本质上是一系列 Pi Hat附着在上的硬件。为了让你可以认识所有的组件CrowPi 绘制了一张中英双语的折页图进行详细的说明。除此之外还有很多示例项目可以帮助你入门。 以下是一张小清单:
* **你好**:当你与 CrowPi 说话时LCD 屏幕上打印输出“你好”。
* **入侵警报**:使用接近传感器发出警报。
* **远程控制器**:让你能够使用远程控制(是的,这个也包含在盒子里)来触发 CrowPi 上的事件。
* **RGB 俄罗斯方块**:让你可以在 LED 显示屏上玩俄罗斯方块游戏。
* **语音识别**:演示自然语言处理。
* **超声波音乐**:利用距离传感器和扬声器创建简易版的 <ruby>特雷门琴<rt>Theramin</rt></ruby>LCTT 译注:世上唯一不需要身体接触的电子乐器)。
这些项目仅仅是入门级别而已因为你还可以在现有的基础上搭建更多东西。当然还有更多内容值得探索。包装盒里还有网络跳线、电阻、LED 和各种组件,这样你闲暇时也可以了解树莓派的 GPIO (通用输入输出端口)功能的所有信息。
不过我也发现了一个问题:示例项目的位置有点难找。找到演示项目很容易(它们就在 CrowPi 中心上),但源代码的位置并不是很容易被找到。我后来发现大多数示例项目都在 `/usr/share/code` 中,你可以通过文件管理器或终端进行访问。
![CrowPi 外围设备][17]
### Linux
树莓派上运行的是 Linux 系统。如果你一直想更深入了解 Linux那么 CrowPi 同样会是一个很好的平台。你可以探索 Linux 桌面、终端以及几乎所有 Linux 或开源应用程序。如果你多年来一直在阅读有关开源的文章,并准备深入研究开源操作系统,那么 CrowPi 会是你想要的平台(当然还有很多其他平台也可以)。
### 游戏
包装盒中包含的 **RetroPie** SD 卡意味着你可以重新启动切换为复古游戏机,并任意玩各种老式街机游戏。它跟 Steam Deck 并不完全相同,但也是一个有趣且令人振奋的小游戏平台。因为它配备的不是一个而是两个游戏控制器,所以它非常适合多人合作的沙发游戏。最重要的是,你不仅可以在 CrowPi 上玩游戏,还可以制作自己的游戏。
### 配备螺丝刀
自我坐下开始使用 CrowPi2 以来已经大约两周,但我还没有通关所有项目。有很多个晚上,我不得不强迫自己停下摆弄它,因为即使我厌倦了一个项目,我也会不可避免地发现还有其他东西可以探索。总而言之,我在盒子里找到了一个特别的组件,这个组件让我马上知道 CrowPi 和我就是天造地设它是一把不起眼的小螺丝刀。盒子上没有撕开就不保修的标签。CrowPi 希望你去修补、拆解、探索和学习。它不是笔记本电脑,甚至也不仅仅是个树莓派;而是一个便携的、低功耗的、多样化的、开源的学习者工具包。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/9/raspberry-pi-crowpi2
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[XiaotingHuang22](https://github.com/XiaotingHuang22)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-lead-teacher-learner.png?itok=rMJqBN5G (Teacher or learner?)
[2]: https://opensource.com/article/21/8/my-first-programming-language
[3]: https://opensource.com/sites/default/files/crowpi-not-laptop.jpeg (CrowPi more than a laptop)
[4]: https://creativecommons.org/licenses/by-sa/4.0/
[5]: https://opensource.com/sites/default/files/crowpi-pi.jpeg (crowpi pi board)
[6]: https://opensource.com/article/19/1/retropie
[7]: https://opensource.com/sites/default/files/crowpi-hub.png (CrowPi hub)
[8]: https://opensource.com/sites/default/files/crowpi-desktop.png (CrowPi desktop)
[9]: https://opensource.com/sites/default/files/crowpi-docs.jpeg (CrowPi docs)
[10]: https://opensource.com/article/20/9/scratch
[11]: https://opensource.com/article/20/6/open-source-virtual-lego
[12]: https://opensource.com/alternatives/minecraft
[13]: https://www.minecraft.net/en-us/edition/pi
[14]: https://opensource.com/article/20/7/ide-java#bluej
[15]: https://opensource.com/downloads/python-gaming-ebook
[16]: https://opensource.com/article/18/8/getting-started-mu-python-editor-beginners
[17]: https://opensource.com/sites/default/files/crowpi-peripherals.jpeg (CrowPi peripherals)
[0]: https://img.linux.net.cn/data/attachment/album/202303/24/170210th71d0o707worogv.jpg

View File

@ -0,0 +1,117 @@
[#]: subject: "A Guide to Find the Right Debian ISO for Download"
[#]: via: "https://www.debugpoint.com/download-debian-iso/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "robsean"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15662-1.html"
如何找到合适的 Debian ISO 来下载
======
![][0]
> Linux 初学者可能会被官方的 Debian 下载 ISO 的页面弄得不知所措。这篇指南旨在简化下载体验。
对于 Debian 初学者来说,安装 Debian 可能会是一次艰难的经历。官方的下载页面包含了不少链接,以至于到底需要下载哪个令人困惑。
我准备这篇指南来帮助你从下载页面挑选合适的 Debian ISO 文件。
总的来说,你可以将 Debian ISO 文件分为两大类。它们是 “自由” 和 “非自由” 。
### 关于 “自由” 和 “非自由” Debian 镜像之间的一些注意事项
- Debian “非自由” 镜像是指包含不符合 Debian 自由软件准则的软件包的 Debian 操作系统的安装镜像。
- “非自由” 软件包包含专有的、有版权的或受许可证限制的软件这些软件包禁止用户修改或分发代码。Debian 项目提供这些 “非自由” 镜像作为用户的一种可选下载项,以便他们使用需要专有驱动或固件的特定硬件设备或软件。
- “自由” 版本的 Debian仅包含开源和可自由分发的软件包这意味着用户有修改、分发和与他人分享的自由而不受任何法律和道德上的限制。
从 Debian 12 “Bookworm”即将发布之后非自由固件软件包将正式包含在主 ISO 文件中。因此,这篇指南将分为两个部分。
### 下载: Debian 12 “Bookworm”
这里是一份下载 ISO 版本的 Debian 12 “Bookworm” 的简单的表格(当前还不稳定,正在测试)。
| 描述 | 最大 ISO 体积 | **选择此 ISO 的情形** | ISO 下载链接amd64 |
| :- | :- | :- | :- |
| 最小的体积;非常适合基本安装 | 700 MB | 你想下载基础的软件包,然后通过互联网来安装 | [iso-cd][1] |
| 完整的 DVD 体积 | 5 GB | 你想先下载所有的东西,然后开始安装,它非常适合离线安装 | [iso-dvd][2] |
### 下载: Debian 11 “Bullseye”
#### 自由版本的 ISO 文件(没有专有软件包)
下面的 ISO 镜像是 “自由” 版本的镜像,这意味着它们不包含用于固件的大量专有软件包。
| 描述 | 最大 ISO 体积 | **选择此 ISO 的情形** | ISO 下载链接amd64 |
| :- | :- | :- | :- |
| 最小的体积(网络安装 CD需要联通互联网下载软件包 | 500 MB | 你有稳定高速的互联网,希望开始时下载较少 | [iso-cd][3] [torrent][4] |
| 完整的 CD 体积;带有 CD 1、2 和 3对于最基础的安装你只需要 CD 1 | 700 MB | 你希望下载基础的软件包,然后不使用互联网来安装它们 | [iso-cd][5] [torrent][6] |
| 完整的 DVD 体积;带有 DVD 1、2 和 3对于最基础的安装你只需要 DVD 1 | 5 GB | 你想先下载所有的东西,然后开始安装,这是离线安装的最理想方式 | [iso-dvd][7] [torrent][8] |
#### 非自由版本的 ISO 文件(带有专有软件包)
如果你有 Wi-Fi、蓝牙等特殊硬件 你可能会希望从下面的表中获取 “非自由” 版本的软件包。
| 类型 | 镜像种类 | **选择此 ISO 的情形** | ISO 下载链接amd64 |
| :- | :- | :- | :- |
| 非自由 | 完整的 CD 、DVD | 你想要减少工作量,并希望 Debian 能够在所有受支持的硬件上工作 | [cd-dvd][9] (然后转到 `*-nonfree` 目录) |
| 非自由 | 完整的 CD 、DVD<ruby>立付<rt>Live</rt></ruby>版) 独立的桌面环境软件包 | 你想要减少工作量Debian 能够工作,并且带有一个立付系统。立付系统也提供完整的安装 | [cd-dvd-live][9](然后转到 `*-nonfree` 目录) |
### 其它的架构
#### 针对 Debian 11 “Bullseye”
- [arm64][10]
- [armel][11]
- [armhf][12]
- [i386][13]
- mips (不可用)
- [mips64el][14]
- [mipsel][15]
- [ppc64el][16]
- [s390x][17]
所有的镜像,下载链接: [单击这里][18]。
### 较旧的版本Debian 10 “Buster”
如果你需要一些针对 Debian 10 “Buster” 的镜像,请访问这个 [页面][19]。
### 总结
对新用户来说,如果想要从官方网站上下载 Debian ISO 镜像,网站的信息可能多到无所适从。因此,我以一种恰当的格式总结下载链接。我希望这篇文章有助于你找到适合于你系统的目标 Debian ISO 镜像。
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/download-debian-iso/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[robsean](https://github.com/robsean)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://cdimage.debian.org/cdimage/bookworm_di_alpha2/amd64/iso-cd/
[2]: https://cdimage.debian.org/cdimage/bookworm_di_alpha2/amd64/iso-dvd/
[3]: https://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/
[4]: https://cdimage.debian.org/cdimage/release/current/amd64/bt-cd/
[5]: https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/
[6]: https://cdimage.debian.org/debian-cd/current/amd64/bt-cd/
[7]: https://cdimage.debian.org/cdimage/release/current/amd64/iso-dvd/
[8]: https://cdimage.debian.org/cdimage/release/current/amd64/bt-dvd/
[9]: https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/
[10]: http://ftp.debian.org/debian/dists/bullseye/main/installer-arm64/current/images/
[11]: http://ftp.debian.org/debian/dists/bullseye/main/installer-armel/current/images/
[12]: http://ftp.debian.org/debian/dists/bullseye/main/installer-armhf/current/images/
[13]: http://ftp.debian.org/debian/dists/bullseye/main/installer-i386/current/images/
[14]: http://ftp.debian.org/debian/dists/buster/main/installer-mips64el/current/images/
[15]: http://ftp.debian.org/debian/dists/bullseye/main/installer-mipsel/current/images/
[16]: http://ftp.debian.org/debian/dists/bullseye/main/installer-ppc64el/current/images/
[17]: http://ftp.debian.org/debian/dists/bullseye/main/installer-s390x/current/images/
[18]: https://cdimage.debian.org/cdimage/
[19]: https://www.debian.org/releases/buster/debian-installer/
[0]: https://img.linux.net.cn/data/attachment/album/202303/26/101016gdf20utfqsu1215a.jpg

View File

@ -0,0 +1,354 @@
[#]: subject: "NixOS Series #4: Things To Do After Installing NixOS"
[#]: via: "https://itsfoss.com/things-to-do-after-installing-nixos/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15663-1.html"
NixOS 系列 #4:安装 NixOS 后要做的事
======
![][0]
安装之后,你会发现 NixOS 与通用的 Linux 发行版有很大的不同。
当然,作为 [高级 Linux 发行版][1]之一,大多数新用户对它并不熟悉。
如果你不知道 [为什么你应该使用 NixOS][2],并且出于好奇而尝试它,那么在继续进行之前,知道它是为谁准备的至关重要。
虽然我假设你已经安装了这个发行版,但如果你是第一次使用,我建议先 [在虚拟机上安装 NixOS][3]。
### 1、更新软件包
即使你使用最新的 ISO 进行安装,也总是会有更新的。那么为什么不从更新软件包开始呢?
要升级软件包,首先,你必须在添加的频道中检查是否有更新:
```
nix-channel --update
```
然后,使用下面的命令来安装这些更新(如果有的话):
```
sudo nixos-rebuild switch --upgrade
```
这就行了!它将处理其余的事情。
### 2、在 NixOS 中改变主机名
如果你尝试用传统的方法 [改变主机名][4](使用 `hostnamectl` 命令),会出现以下错误:
![在 NixOS 中改变主机名的错误][5]
在 NixOS 中,你可以用它的主配置文件轻松地改变主机名。使用如下命令:
```
sudo nano /etc/nixos/configuration.nix
```
在这个配置文件中,寻找以下一行:
```
networking.hostName = "nixos"
```
然后把它改成:
```
networking.hostName = "Your_Hostname"
```
例如,我把我的主机名改为 `itsFOSS`
```
networking.hostName = "itsFOSS"
```
![在 NixOS 中改变主机名][6]
现在,[保存更改并退出 nano][7] 文本编辑器。
为了使你对主机名的修改生效,执行以下命令:
```
sudo nixos-rebuild switch
```
最后,重新打开终端,主机名的变化应该反映出来。
### 3、设置 Flatpak
我知道你可能在想什么。Nix 软件包管理器已经提供了大量的软件包。那么,为什么你需要 Flatpak 呢?
安装你所需要的东西对于第一次使用的人来说可能有点费时。所以Flatpak 应该能给你带来方便。
[设置 Flatpak][8] 与你在 Ubuntu 上做的不一样。
要设置 Flatpak你必须对 `configuration.nix` 文件进行修改,可以通过以下方式访问该文件:
```
sudo nano /etc/nixos/configuration.nix
```
[在 nano 中移动到最后一行][9],在 `}` 前添加以下一行:
```
services.flatpak.enable = true
```
![在 NixOS 上设置 Flatpak][10]
`Ctrl + O` 保存更改,按回车键,按 `Ctrl + X` 退出。
接下来,使用以下命令重建并切换到新的配置文件:
```
sudo nixos-rebuild switch
```
最后,使用下面的命令将 Flathub 软件库添加到系统中:
```
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
```
想知道到底什么是 Flatpak 包吗?你可以参考我们关于它的文章:
> **[什么是 Flatpak你需要知道的关于这个通用包装系统的一切重要信息][23]**
### 4、启用垃圾收集
NixOS 以其不可改变性而闻名,这是有充分理由的。
每当你升级一个软件包时,旧的软件包不会被删除。只是指向旧包的符号链接将被指向最新的版本。
而这样做,你的系统中会积累下不必要的垃圾。
但是,删除每一个旧世代将违背 NixOS 的初衷。
所以,在这种情况下,你可以将你的系统配置为每周删除垃圾包。
要做到这一点,首先,打开 NixOS 配置文件:
```
sudo nano /etc/nixos/configuration.nix
```
并在配置文件末尾的 `}` 前添加以下一行:
```
# Automatic Garbage Collection
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 7d";
};
```
![在 NixOS 中启用自动垃圾收集][11]
保存修改并退出 nano 文本编辑器。
为了激活垃圾收集,重建并切换到新的配置文件:
```
sudo nixos-rebuild switch
```
如果你不确定垃圾收集器是否在后台正常运行,你可以用以下命令列出活动的计时器:
```
systemctl list-timers
```
![][12]
正如你所看到的Nix 垃圾收集器正在如期运行,并显示距离下次清理还有 5 天。
### 5、安装你喜欢的软件
我是说这是我们使用电脑的唯一原因 —— “为了使用我们最喜欢的软件”,如果还不是,我们就把它变成现实!
寻找软件包的最好地方是 [Nix 软件包搜索][13],可以使用你喜欢的任何浏览器访问。
- 搜索软件包
- 选择软件包
- 点击 “nix-env” 并复制给定的 NixOS 的命令
- 执行该命令,就可以了
你可以查看我们的 [NixOS 软件包管理][14] 指南,了解所有的细节。
让我在这里给你一个简单的回顾。例如,在这里,我想安装 Librewolf所以我采用了以下方法
![搜索 NixOS 的软件包][15]
**但如果你想安装 SSH 或 Plex 等服务,上述方法就不能用了**。
为此,你得查看位于页面顶部的 “<ruby>NixOS 选项<rt>NixOS options</rt></ruby>”。
因此,假设我想安装 OpenSSH那么我必须按照给定的步骤进行
- 进入 “NixOS 选项”。
- 搜索服务的名称
- 获取服务的名称并将其粘贴到 `configuration.nix` 中,将其值改为 `true`
![搜索 NixOS 的服务][16]
```
services.openssh.enable = true
```
![在 NixOS 上启用 OpenSSH][17]
在配置文件中加入这一行后,重建服务:
```
sudo nixos-rebuild switch
```
### 6、在 NixOS 中启用自动更新(可选)
一些用户喜欢启用自动更新功能,而另一些用户则可以在他们方便的时候更新软件包。
所以这完全取决于你。
**要启用自动更新**,首先打开 `configuration.nix` 文件:
```
sudo nano /etc/nixos/configuration.nix
```
接下来,在配置文件的末尾,在 `}` 之前添加以下一行:
```
# Auto system update
system.autoUpgrade = {
enable = true
};
```
![在 NixOS 中启用自动系统更新][18]
保存修改并退出 nano。
要启用自动更新,你必须用以下方法重建并切换到该文件:
```
sudo nixos-rebuild switch
```
你也可以用下面的命令检查 NixOS 的升级定时器:
```
systemctl list-timers
```
![NixOS 的自动升级定时器][19]
正如你所看到的,`nixos-upgrade.service` 正在后台如期运行!
### 7、减少交换度
如果你正在利用交换分区,你可能想减少交换度。
交换度只不过是你想要多积极地使用交换分区(或内存)的数值,其范围从 0 到 100。
交换度越小你的系统就会越多地使用物理内存RAM而交换分区只不过是你的存储驱动器的一部分而已。
另外,存储驱动器的速度相对比内存慢,所以如果可能的话,你应该减少交换度。
要检查你的系统的默认交换度,请使用以下方法:
```
cat /proc/sys/vm/swappiness
```
![检查 Linux 系统的交换度][20]
而对于大多数 Linux 发行版,它被设置为 `60`
我建议你把这个值降低到 `10`
要做到这一点,首先,用以下命令打开配置文件:
```
sudo nano /etc/nixos/hardware-configuration.nix
```
并在 `}` 之前的行末添加以下一行:
```
boot.kernel.sysctl = { "vm.swappiness" = 10;}
```
![减少 NixOS 中的交换度][21]
保存修改并退出文本编辑器。
现在,重建配置并使用下面的方法切换到它:
```
sudo nixos-rebuild switch
```
现在,你可以再次检查交换度,它应该反映出变化:
```
cat /proc/sys/vm/swappiness
```
![减少 NixOS 中的交换度][22]
就这些了。
### 总结
如果你在第一次安装 NixOS 后马上遵循这些要点,你应该得到一个良好的用户体验。
当然,根据你的要求,还可以有一些其他的东西。但是,我认为上面提到的事情是最基本或最常见的事情。
在本系列的下一部分,我将讨论在 NixOS 上设置家庭管理器,这对有多个用户的系统应该是有帮助的。
💬 安装NixOS后你首先做什么让我知道你的想法。
--------------------------------------------------------------------------------
via: https://itsfoss.com/things-to-do-after-installing-nixos/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/advanced-linux-distros/
[2]: https://linux.cn/article-15606-1.html
[3]: https://linux.cn/article-15624-1.html
[4]: https://itsfoss.com/change-hostname-ubuntu/
[5]: https://itsfoss.com/content/images/2023/02/error-changing-hostname-in-nixos.png
[6]: https://itsfoss.com/content/images/2023/02/change-hostname-in-NixOS.png
[7]: https://linuxhandbook.com/nano-save-exit/?ref=its-foss
[8]: https://itsfoss.com/flatpak-guide/
[9]: https://linuxhandbook.com/beginning-end-file-nano/?ref=its-foss
[10]: https://itsfoss.com/content/images/2023/02/setup-flatpak-on-nixos.png
[11]: https://itsfoss.com/content/images/2023/02/enable-automatic-garbage-collection-in-NixOS.png
[12]: https://itsfoss.com/content/images/2023/02/list-active-timers-in-nixos.png
[13]: https://search.nixos.org/packages?ref=its-foss
[14]: https://linux.cn/article-15645-1.html
[15]: https://itsfoss.com/content/images/2023/02/search-packages-for-nixos.png
[16]: https://itsfoss.com/content/images/2023/02/Search-the-service-for-nixos.png
[17]: https://itsfoss.com/content/images/2023/02/enable-openssh-on-nixos.png
[18]: https://itsfoss.com/content/images/2023/02/enable-auto-system-update-in-nixos.png
[19]: https://itsfoss.com/content/images/2023/02/auto-upgrade-timer-in-nixos.png
[20]: https://itsfoss.com/content/images/2023/02/check-swapiness-of-linux-system.png
[21]: https://itsfoss.com/content/images/2023/02/reduce-swapiness-in-nixos.png
[22]: https://itsfoss.com/content/images/2023/02/reduce-swapiness-in-NixOS.png
[23]: https://itsfoss.com/what-is-flatpak/
[0]: https://img.linux.net.cn/data/attachment/album/202303/26/142500uzc095szl064s9xx.jpg

View File

@ -3,30 +3,30 @@
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15660-1.html"
Python 中的输入函数:概念和示例
======
**在这篇文章中,我将通过一些通俗易懂的例子来解释 Python 的 Input 函数的基础知识。**
> 在这篇文章中,我将通过一些通俗易懂的例子来解释 Python 的 Input 函数的基础知识。
![][1]
Python 是世界上最流行的编程语言之一广泛应用于各种应用程序中。Python 中的一个基本概念是 `Input()` 函数,它允许用户通过提供输入值与程序进行交互。
Python 是世界上最流行的编程语言之一广泛应用于各种应用程序中。Python 中的一个基本概念是 `input()` 函数,它允许用户通过提供输入值与程序进行交互。
让我们看看 input 函数是如何工作的,以及如何在 Python 程序中有效地使用它。
让我们看看 `input()` 函数是如何工作的,以及如何在 Python 程序中有效地使用它。
在开始之前,我希望你已经安装了 Python 并设置了一个基本的编辑器。如果没有,请参考我的以下指南:
- [如何在 Ubuntu/Linux 上安装 Python 3.11][2]
- [如何在 UbuntuLinux 上安装 Python 3.11][2]
- [如何在 Windows 上安装 Python][3]
- [如何为 Python 设置 IDLE 编辑器][4]
### Python Input 函数
Python 中的 input 函数用于接受用户输入的字符串。它提示用户输入一个值并等待用户提供输入。然后将用户的输入作为字符串存储在变量中,稍后可以在程序中使用。
Python 中的 `input()` 函数用于接受用户输入的字符串。它提示用户输入一个值并等待用户提供输入。然后将用户的输入作为字符串存储在变量中,稍后可以在程序中使用。
#### 句法
@ -34,21 +34,20 @@ Python 中的 input 函数用于接受用户输入的字符串。它提示用户
input("your message to user")
```
当你运行 input 函数时它会向用户显示消息并_等待_输入。光标等待。当用户输入并按下回车键input 函数就会读取用户的输入。该值存储在你指定的变量中。
当你运行 `input()` 函数时,它会向用户显示消息并 _等待_ 输入。显示光标等待。当用户输入并按下回车键,`input()` 函数就会读取用户的输入。该值存储在你指定的变量中。
让我们看几个例子。
### 示例 1简单的 input 函数用法
以下代码片段接受输入并显示带有附加字符串的输出。
### 示例 1简单的 input() 函数用法
以下代码片段接受输入并显示带有附加字符串的输出:
```
your_name = input("Enter your name:")
print("Hello " + your_name)
```
**输出:**
输出:
```
Enter your name:arindamHello arindam
@ -58,7 +57,7 @@ Enter your name:arindamHello arindam
### 示例 2以整数和浮点数作为输入
在使用 input() 函数时,你还可以在运行时将输入转换为 int() 或 float() 。这是一个例子。
在使用 `input()` 函数时,你还可以在运行时使用 `int()``float()` 将输入转换。这是一个例子:
```
no_of_books = int(input("Enter total books ordered:"))
@ -79,7 +78,7 @@ Total price: 50.5
### 示例 3连接列表
你还可以使用其他函数(例如列表)来接受一组值并将它们转换为 Python 中的 [list][6]。这是一个接受输入并将其转换为列表的示例。然后使用另一组值并附加到第一个列表
你还可以使用其他函数(例如列表)来接受一组值并将它们转换为 Python 中的 [列表][6]。这是一个接受输入并将其转换为列表的示例。然后使用另一组值并附加到第一个列表
```
# 获取第一个列表的输入
@ -96,7 +95,7 @@ for j in list_2:
print(list_1)
```
**输出:**
输出:
```
Enter numbers for list 1:1234
@ -106,7 +105,7 @@ Enter some letters for list 2:ABCD
### 总结
我希望这个简单的指南通过几个示例阐明了 input() 函数。对于简单的场景,它是一个强大的功能,可以从标准输入中接受值。
我希望这个简单的指南通过几个示例阐明了 `input()` 函数。对于简单的场景,它是一个强大的功能,可以从标准输入中接受值。
--------------------------------------------------------------------------------
@ -115,15 +114,15 @@ via: https://www.debugpoint.com/input-function-python/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://www.debugpoint.com/wp-content/uploads/2023/03/pyinput.jpg
[2]: https://www.debugpoint.com/install-python-3-11-ubuntu/
[3]: https://www.debugpoint.com/install-python-windows/
[4]: https://www.debugpoint.com/install-idle-ubuntu-linux/
[2]: https://linux.cn/article-15230-1.html
[3]: https://linux.cn/article-15480-1.html
[4]: https://linux.cn/article-15622-1.html
[5]: https://www.debugpoint.com/wp-content/uploads/2023/03/Python-Input-function-a-simple-example.jpg
[6]: https://docs.python.org/3/library/stdtypes.html?highlight=list#lists

View File

@ -3,14 +3,16 @@
[#]: author: "Sreenath https://itsfoss.com/author/sreenath/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15657-1.html"
如何知道你是否使用了代理服务器?
======
**什么是代理?**
![][0]
什么是代理?
代理是充当客户端和另一台服务器之间的中介的服务器或软件应用。它充当客户端和互联网之间的网关,允许用户访问在线资源,同时隐藏他们的身份、位置和其他个人信息。
@ -26,15 +28,14 @@
有时,可能是你的互联网服务提供商和内容交付网络使用它们来缓存资源的副本以节省带宽或只是为了监视/过滤网络。
有几种方法可以检查你是否在透明代理后面:
- **通过某些在线 IP 检测/检查网站获得的 IP 地址可能与你的计算机或设备的 IP 地址不匹配**。因为代理服务器正在拦截你的流量并将其与 IP 地址一起发送出去。
- **检查你的网络设置以查看是否配置了代理服务器。**
- **借助一些在线代理检测工具。**
- **连接到你知道不存在的服务器。**如果网页上显示的错误看起来与平时不同,你可能使用了代理。
- **连接到你知道不存在的服务器。** 如果网页上显示的错误看起来与平时不同,你可能使用了代理。
无论你喜欢与否,你始终可以使用 [VPN 服务][1]绕过透明代理。
无论你喜欢与否,你始终可以使用 [VPN 服务][1] 绕过透明代理。
### 如何检查你是否在 Ubuntu 上使用代理
@ -42,17 +43,17 @@ Ubuntu 或任何其他 Linux 发行版提供了多种检查方法。此处使用
#### 使用 GNOME 设置
这是直接的 GUI 方式。打开 GNOME 设置并转到“网络”选项卡,然后按旁边的齿轮图标。
这是直接的 GUI 方式。打开 GNOME <ruby>设置<rt>Settings</rt></ruby> 并转到 <ruby>网络<rt>Networks</rt></ruby> 选项卡,然后按旁边的齿轮图标。
![Select the gear icon adjacent to the Network proxy section][2]
它应该**默认关闭**
它应该默认 <ruby>禁用<rt>Disabled</rt></ruby>
如果你在代理后面,你可以在这里获得不同的状态。在代理设置中,你可以看到,我在这里使用了代理(手动配置)。
如果你在代理后面,你可以在这里看到不同的状态。在代理设置中,你可以看到,我在这里使用了代理(手动配置)。
![Proxy details in GNOME Settings][3]
可以使用 GNOME 桌面中的 gsettings 命令更改相同的代理状态。
可以使用 GNOME 桌面中的 `gsettings` 命令更改相同的代理状态。
```
gsettings set org.gnome.system.proxy mode 'none'
@ -64,7 +65,7 @@ gsettings set org.gnome.system.proxy mode 'none'
你可以通过命令行以多种方式获取代理的状态。
**通过列出关联的环境变量获取代理的状态**
##### 通过列出关联的环境变量获取代理的状态
打开终端并运行以下任一命令:
@ -84,9 +85,7 @@ set | grep -i proxy
空输出意味着没有配置代理。否则,它将打印相关的环境变量。
🚧
请注意,如果你将代理设置为环境变量,这将起作用。
> 🚧 请注意,如果你将代理设置为环境变量,这将起作用。
或者,你可以回显每个代理变量以检查是否设置了特定的代理变量。
@ -96,7 +95,7 @@ set | grep -i proxy
echo $http_proxy
```
**使用 nmcli 命令检查**
##### 使用 nmcli 命令检查
打开终端并输入:
@ -131,7 +130,7 @@ via: https://itsfoss.com/check-proxy-server/
作者:[Sreenath][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
@ -142,4 +141,5 @@ via: https://itsfoss.com/check-proxy-server/
[3]: https://itsfoss.com/content/images/2023/02/Proxy-in-GNOME-settings.png
[4]: https://itsfoss.com/content/images/2023/02/set_grep_proxy.png
[5]: https://itsfoss.com/content/images/2023/02/nmcli-connection-show.png
[6]: https://itsfoss.com/content/images/2023/02/proxy-using-nmcli.png
[6]: https://itsfoss.com/content/images/2023/02/proxy-using-nmcli.png
[0]: https://img.linux.net.cn/data/attachment/album/202303/24/174021wkdzn81kvtnngzaw.jpg

View File

@ -0,0 +1,144 @@
[#]: subject: "GNOME 44 is Here With New Tricks Up its Sleeve"
[#]: via: "https://news.itsfoss.com/gnome-44-release/"
[#]: author: "Sourav Rudra https://news.itsfoss.com/author/sourav/"
[#]: collector: "lkxed"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-15659-1.html"
GNOME 44 发布
======
> GNOME 44 终于来了,它带来了重新打造的设置应用,更新了快速设置功能,改进了可访问性等等。
![GNOME 44][1]
GNOME 可以说是***最受欢迎的桌面环境**之一。
之前的 [GNOME 43 版本][2] 就补充了许多有用的功能,而现在的 GNOME 44 版本也是一样。
让我们看看都有哪些内容。
### 🆕 GNOME 44 有什么新功能?
![介绍 GNOME 44][3]
我们最近已经分别介绍了 GNOME 44 的最佳功能;在这里,让我回顾一下这个发布的相关细节。
主要的亮点包括:
- 设置菜单的改造
- 快速设置的改进
- 文件选择器的网格视图
- 文件管理器的改进
#### 1、设置菜单的改造
![GNOME 44 上更新的设置菜单的截图][4]
设置菜单进行了小规模的改造,**可访问性面板被重新设计**,以提供一个更现代的导航体验。
![鼠标和触摸板设置更新后的截图][5]
然后,一项新的功能让你可以 **通过二维码分享 Wi-Fi 密码**,并且改进了鼠标/触摸板设置。
“设备安全”下的信息也得到了更新,以增加技术细节的清晰度。
![GNOME 44 设备安全][6]
#### 2、改进的快速设置菜单
![GNOME 44 快速设置面板中的蓝牙设置截图][7]
快速设置面板已经得到了许多更新;它现在可以让你 **查看和管理当前连接的蓝牙设备**
但你必须前往设置菜单来配对新设备。
![GNOME 44 快速设置菜单中的新截图快捷方式][8]
另一个新增功能是**新的屏幕截图快捷方式**,可以毫不费力地从快速设置菜单中进行屏幕截图。
这还不是全部GNOME 44 的快速设置菜单现在有一个检查**在后台运行的应用程序的巧妙方法**。
![][9]
你可以在我们之前的报道中找到关于这个功能的更多细节:
> **[GNOME 正在(某种程度上)恢复在几年前删除的功能](https://linux.cn/article-15551-1.html)**
#### 3、新的锁屏/登录窗口
![GNOME 44 的新锁屏和登录窗口的截图][10]
GNOME 44 提供了**更新的锁屏和登录窗口**,有一个更大的用户头像和各种元素的细微变化,例如时钟的字体大小。
#### 4、GNOME 文件选取器中的缩略图
![GNOME 44 的文件选取器中的文件缩略图预览截图][11]
去年年底,我们看到了 GNOME 文件选取器的一个**长时间要求的功能** 的 [回归][12],而现在它终于到来了。
GNOME 的文件选取器从来没有一个合适的缩略图预览来查看文件。取而代之的是,它**依赖于一个普通的列表视图**。
直到现在。
它现在**带来了一个合适的缩略图视图**,可以通过点击文件选取器右上角的 “列表-网格视图” 切换进行切换。
#### 🛠️ 其他变化和改进
![GNOME 44 壁纸集合][13]
这些并不是 GNOME 44 带来的唯一改进;这里有一些值得一提的改进:
- 新壁纸。
- 对文件管理器的各种小更新带来了性能的提高。
- Epiphany 网页浏览器被移植到 GTK4并进行了许多错误修正。
- 在 GNOME 软件应用中加入了一个新的过滤器,激活后只显示开源的应用程序。
- 对联系人应用进行了各种改进,能够以二维码的形式分享联系人。
- 对 GNOME Builder 的许多 UI 和风格进行了修复。
- 在 [GNOME Circle][14] 集合中添加了十个新的应用程序。
你可以通过 [官方发布说明][15] 来了解更多。
### 开始使用 GNOME 44
你可以在下个月期待 GNOME 44 与 Ubuntu 23.04 和 Fedora 38 一起出现。
如果你迫不及待地想得到它,使用 [Boxes][17] 安装 [GNOME OS][16] 应该是一个测试它的好方法。
> **[GNOME][18]**
💬 你对这个丰富的 GNOME 44 更新有何看法?你想在你的 Linux 系统上使用它吗?
--------------------------------------------------------------------------------
via: https://news.itsfoss.com/gnome-44-release/
作者:[Sourav Rudra][a]
选题:[lkxed][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://news.itsfoss.com/author/sourav/
[b]: https://github.com/lkxed/
[1]: https://news.itsfoss.com/content/images/size/w1304/2023/03/gnome-44-release.jpg
[2]: https://news.itsfoss.com/gnome-43-release/
[3]: https://youtu.be/N7SGe1MiqNA
[4]: https://news.itsfoss.com/content/images/2023/03/GNOME44_settings.jpg
[5]: https://news.itsfoss.com/content/images/2023/03/GNOME44_settings_2.jpg
[6]: https://news.itsfoss.com/content/images/2023/03/gnome-44-device-security.png
[7]: https://news.itsfoss.com/content/images/2023/03/GNOME44_QuickSettings.jpg
[8]: https://news.itsfoss.com/content/images/2023/03/GNOME44_QuickSettings_2.jpg
[9]: https://news.itsfoss.com/content/images/2023/03/background-app-running--1-.png
[10]: https://news.itsfoss.com/content/images/2023/03/GNOME44_lockscreen.jpg
[11]: https://news.itsfoss.com/content/images/2023/03/GNOME44_file_view.jpg
[12]: https://news.itsfoss.com/gnome-file-picker/
[13]: https://news.itsfoss.com/content/images/2023/03/gnome-44-wallpapers.jpg
[14]: https://circle.gnome.org/?ref=its-foss-news
[15]: https://release.gnome.org/44/?ref=its-foss-news
[16]: https://os.gnome.org/?ref=its-foss-news
[17]: https://wiki.gnome.org/Apps/Boxes?ref=its-foss-news
[18]: https://www.gnome.org/getting-gnome/?ref=its-foss-news

View File

@ -0,0 +1,69 @@
[#]: subject: "Mozilla Plans to Work On Open-Source AI to Develop Solutions like ChatGPT"
[#]: via: "https://news.itsfoss.com/mozilla-open-source-ai/"
[#]: author: "Sourav Rudra https://news.itsfoss.com/author/sourav/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Mozilla Plans to Work On Open-Source AI to Develop Solutions like ChatGPT
======
Mozilla's getting into the A.I. game? I think we need more of this!
![mozilla AI][1]
[Mozilla][2] is a well-known name in the tech space for its privacy-focused endeavors and the Firefox web browser.
But, as we all know, the **biggest catch of 2023 has been A.I**. It has seen rapid growth across many sectors, with big tech betting heavily on it.
Microsoft, Google, and several others 🤯 Chatbots, search engine integration, content creation, graphics design, and what not.
And Mozilla doesn't want to miss out on it.
In a recent announcement, they revealed **plans to set up a new startup** and **gather a community** to build a trustworthy, independent, and open-source AI ecosystem.
Let's look at what we can expect.
**What is happening?:** Mozilla has **committed $30M to kick-start a new startup** called [Mozilla.ai][3].
It aims to bring together people from different walks of life to collectively work on creating a trustworthy and independent AI ecosystem that will benefit everyone.
The first order of business will be to create **tools that make generative AI much safer and transparent** than what it is now, and to make 'people-centric' recommendation systems that don't serve skewed information.
This startup will be led by [Moez Draief][4] (_Managing Director of Mozilla)._The initial board members will be **Harvard's**[Karim Lakhani][5], Credo's [Navrina Singh][6], and Mozilla's [Mark Surman][7] (_Director of the Mozilla Foundation_).
**Why now?:** Obviously, the new wave of AI has created a lot of excitement and concerns ⚡
The current/upcoming wave of AI can potentially improve many people's lives, but only **if the technology is more human-focused**. Mozilla says this will only be possible when they put '_human agency and the interests of users at the cor_e' and prioritize transparency and accountability.
In contrast, the tech giants and cloud companies with significant resources are **scrambling to continue their dominance** over the market by doing things the usual way, with no special focus on improving transparency and moderation.
🙌 It is good to hear that the Mozilla Foundation is getting involved to develop open-source A.I. solutions that could challenge the likes of ChatGPT, Google Bard, and more.
Not to forget, there's another team working on making an open-source alternative to ChatGPT. And, yes, we need more of this t**o compete with the big tech clenching their claws in the consumer market with no community oversight**.
I suggest you go through the [announcement blog][8] to know more about Mozilla's AI plans if you are curious.
--------------------------------------------------------------------------------
via: https://news.itsfoss.com/mozilla-open-source-ai/
作者:[Sourav Rudra][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://news.itsfoss.com/author/sourav/
[b]: https://github.com/lkxed/
[1]: https://news.itsfoss.com/content/images/size/w1304/2023/03/mozilla-ai-opensource.png
[2]: https://www.mozilla.org/?ref=its-foss-news
[3]: https://mozilla.ai/?ref=its-foss-news
[4]: https://www.linkedin.com/in/moezdraief/?ref=its-foss-news
[5]: https://www.linkedin.com/in/professorkl?ref=its-foss-news
[6]: https://www.linkedin.com/in/navrina/?ref=its-foss-news
[7]: https://ca.linkedin.com/in/msurman?ref=its-foss-news
[8]: https://blog.mozilla.org/en/mozilla/introducing-mozilla-ai-investing-in-trustworthy-ai/?ref=its-foss-news

View File

@ -0,0 +1,76 @@
[#]: subject: "Adding a Pop of Color to GNOME: Accent Colors Are on the Way"
[#]: via: "https://news.itsfoss.com/gnome-accent-colors/"
[#]: author: "Sourav Rudra https://news.itsfoss.com/author/sourav/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Adding a Pop of Color to GNOME: Accent Colors Are on the Way
======
GNOME users, were you waiting for this moment? Get ready to choose your color!
![gnome accent][1]
Support for accent colors has been on Ubuntu since [22.04 LTS][2], and people loved it. Sadly, GNOME never had that kind of support — yet.
Thanks to an **effort underway to introduce accent color support in GNOME,** that is changing.
**What is it?:** Recently, a proposal was sent out with a [merge request][3] to add support for accent colors to GNOME, the development of which is being led by [Alexander Mikhaylenko][4].
In its current state, it's in a **very work-in-progress condition** with a lot of work pending as well as a few issues here and there which should be handled before the final release.
When looking at the code, it is clear that **initially support for 10 accent colors will be offered**, with the possibility of more options after release.
**Wondering how it might look?**
Well, in a [discussion][5] on Mastodon, a few mockups made by Alexander were shared by a GNOME foundation member, [Jamie][6], that depicts two distinct colorways.
One is a green one.
![early look at gnome's upcoming color accent support][7]
The other is blue.
![another early look at gnome's upcoming color accent support][8]
I must say these look nice! 😃 Want some Fedora love on your non-Fedora distro? Turn it to blue and something else? Choices, choices!
> 📝 Do keep in mind that whatever you see above is subject to change before final release.
**When to expect?:** When asked by another user in the above-mentioned discussion, Alexander mentioned that we can **expect accent color support to arrive with GNOME 45**.
Seeing that GNOME 44 was recently released, we will have to wait a bit before we can actually see this being implemented.
But, it is good to know that there is a possibility of it happening soon after!
I do like that GNOME is finally getting support for accent colors, and I hope the wait is worth it.
**Via**: [omg!linux][9]
_💬 If you ask me, I would love having the Green accent color on my GNOME system. What about you?_
--------------------------------------------------------------------------------
via: https://news.itsfoss.com/gnome-accent-colors/
作者:[Sourav Rudra][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://news.itsfoss.com/author/sourav/
[b]: https://github.com/lkxed/
[1]: https://news.itsfoss.com/content/images/size/w1304/2023/03/gnome-accent-picker.jpg
[2]: https://news.itsfoss.com/ubuntu-22-04-release/
[3]: https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2715?ref=its-foss-news
[4]: https://gitlab.gnome.org/exalm?ref=its-foss-news
[5]: https://crab.garden/@jamie/110063105101806314?ref=its-foss-news
[6]: https://crab.garden/@jamie?ref=its-foss-news
[7]: https://news.itsfoss.com/content/images/2023/03/GNOME_Accent_Color_1.png
[8]: https://news.itsfoss.com/content/images/2023/03/GNOME_Accent_Color_2.png
[9]: https://www.omglinux.com/gnome-accent-colors-are-coming/?ref=its-foss-news

View File

@ -2,7 +2,7 @@
[#]: via: "https://opensource.com/article/23/2/your-first-tech-job"
[#]: author: "Fatima https://opensource.com/users/ftaj"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: translator: "XiaotingHuang22"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
@ -136,11 +136,11 @@ via: https://opensource.com/article/23/2/your-first-tech-job
作者:[Fatima][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
译者:[XiaotingHuang22](https://github.com/XiaotingHuang22)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ftaj
[b]: https://github.com/lkxed/
[1]: https://opensource.com/article/21/5/open-source-burnout
[1]: https://opensource.com/article/21/5/open-source-burnout

View File

@ -0,0 +1,81 @@
[#]: subject: "Why your open source project needs a content strategy"
[#]: via: "https://opensource.com/article/23/3/open-source-project-content-strategy"
[#]: author: "Emily O'Neill https://opensource.com/users/emilyo"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Why your open source project needs a content strategy
======
If you search for content strategy in your favorite search engine, I bet that you find that it is a term more strongly associated with marketing content than with technical content. However, a technical content strategy is a powerful way to align stakeholders around content goals for your open source project. In this article, I explore the benefits of technical content strategy and how having one can improve the user and contributor experience of your community projects.
When developing a content strategy, you should consider your goals. The goals differ depending on the user. For the marketing team, the goal of content strategy is to attract and connect with existing and potential customers by using content. Marketing content strategists aim to engage customers and develop relationships with the brand.
The goal of technical content strategists is to guide users with technical content that helps them achieve their goals. It should provide them with just enough information to successfully complete their task.
### Creating a content strategy
So how do you create a content strategy that helps you achieve your goal? You can do this by having someone on your project take the role of content strategist. Their task is to document what user content is created, where it is published, how users can find it, and how it can be maintained, published, and retired. The content strategy should be available where contributors can find it easily.
### Content types and publication locations
The first step to creating content is to get to know the project's audience. Identifying users is best done with all project stakeholders contributing, so there is a shared understanding of who the users are and what their goals are. A tip for open source content strategies is to consider your contributor personas as well as your end-user consumer personas.
A good content strategy is grounded in meeting the user's needs. The project's content should not tell users everything the content creator knows about something. The content should tell the user just enough to complete a task. When the personas are identified and documented, the strategist considers what types of content help these personas be successful. For example, can the user needs be met completely with microcopy in the user interface, or do they need more detailed documentation? Is the contributor onboarding workflow best demonstrated in a video or a blog with screenshots?
While considering what content types to create, the strategist also looks at where the content should be published so your personas can easily find it. The strategist needs to consider how content creators should progressively disclose information if it is not possible to keep the user in their context. For example, if the user is struggling to understand a log file, you can link them to more information on the project's documentation website.
The strategy should give guidance to help decisions about what types of content might best solve the user's problem. The content creator should be challenged to ask themselves what content type best meets the user's needs in the moment. Do they need a new documentation article on the website? Could the user friction point be avoided with a clear error or log message, a better UI label, or other content type? You should make clear that sometimes the answer to a problem isn't always to create more content.
### Content reviews and retirement
Now that you have a strategy for what types of content you want and where to publish them, you need to consider governance. The first part of this process is to decide what types of reviews your content requires before publishing. For example, does it require a content plan review, subject matter expert review, editorial review, peer author reviews, or copy reviews. You should also decide how reviews and approvals are tracked.
The second aspect of governance is to decide on a schedule for retirement or archival of content. The strategist should document how content is reviewed for retirement in the future. You should decide if content needs to be retired annually or before every new version release. You should also consider if the content needs to be accessible in some format for users using older versions.
If you are creating a content strategy for an existing project, the chances are high that your project already has some content. As part of the creation process, the content strategist should audit this content, and consider if it is still current and useful. If it is out of date, it should be retired or archived.
### A content strategy is beneficial for everyone
Now that you have a content strategy for your project, you should see how it benefits your users, contributors, and your project as a whole.
#### Project end users
At the heart of the content strategy is the audience. The strategy is centered on the personas interacting with the project. It considers how you can provide them with easily findable information in a consumable format that helps them complete their goals. End users benefit from a content experience that is built around their needs. It should also be self-service so they can solve problems independently.
#### Contributors
Content consumers, just like end users, benefit from self-service content. New contributors to the project benefit from content designed to onboard them to the project quickly and with ease. The experienced contributor persona gets content that helps them learn about new features of the project. They can also get help with more technically challenging areas. Contributor personas benefit from having accessible reference information. This information can describe the interfaces and features that are available to them to use, build on, and use to interact with the product or service.
The contributors to your project are also the people creating the content that your users consume. Content strategy can help them to understand and feel empathy for user personas, their goals, and use cases. Giving contributors a common understanding of the user's content needs and the types of content that satisfies them supports the creation of a consistent content experience.
Creating a strategy helps all content creators easily understand and align with the content vision. It keeps them focused on creating high-value content that reduces user friction.
#### Project
In an ideal world, your project would have all the resources needed to create the ideal content experience for your users as envisioned in your strategy. Unfortunately, we live in the real world with conflicting priorities and resource-constrained projects. The good news is that a user-centered content strategy gives the team a shared vision of the content experience. This strategy helps build a content foundation that the project can iterate with each release. It also helps the team make more informed decisions about content.
Your project also benefits from accessible documentation that better serves your users. Your content experience helps users recognize and realize the value of what you have created.
### Implement a content strategy
Your content strategy should be a living artifact, guiding content decisions for the project. With this in mind, it should be revisited frequently and tweaked to reflect what is working or not working for your users. Keeping it current enhances your content experience and improves its effectiveness in guiding your users to success.
I believe that the practice of content strategy should be more widely adopted in the technical world as it is a powerful tool. It can help you create a better experience for all of your users. The experience should consider each user's needs, workflow, pain points, and emotions. This helps projects deliver the right content in the right place at the right time.
--------------------------------------------------------------------------------
via: https://opensource.com/article/23/3/open-source-project-content-strategy
作者:[Emily O'Neill][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/emilyo
[b]: https://github.com/lkxed/

View File

@ -0,0 +1,415 @@
[#]: subject: "Examples of floating point problems"
[#]: via: "https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Examples of floating point problems
======
Hello! Ive been thinking about writing a zine about how things are represented on computers in bytes, so I was thinking about floating point.
Ive heard a million times about the dangers of floating point arithmetic, like:
- addition isnt associative (`x + (y + z)` is different from `(x + y) + z`)
- if you add very big values to very small values, you can get inaccurate results (the small numbers get lost!)
- you cant represent very large integers as floating numbers
- NaN/infinity values can propagate and cause chaos
- there are two zeros (+0 and -0), and theyre not represented the same way
- denormal/subnormal values are weird
But I find all of this a little abstract on its own, and I really wanted some
specific examples of floating point bugs in real-world programs.
So I [asked on Mastodon][1] for
examples of how floating point has gone wrong for them in real programs, and as
always folks delivered! Here are a bunch of examples. Ive also written some
example programs for some of them to see exactly what happens. Heres a table of contents:
[how does floating point work?][2][floating point isnt “bad” or random][3][example 1: the odometer that stopped][4][example 2: tweet IDs in Javascript][5][example 3: a variance calculation gone wrong][6][example 4: different languages sometimes do the same floating point calculation differently][7][example 5: the deep space kraken][8][example 6: the inaccurate timestamp][9][example 7: splitting a page into columns][10][example 8: collision checking][11]
None of these 8 examples talk about NaNs or +0/-0 or infinity values or
subnormals, but its not because those things dont cause problems its just
that I got tired of writing at some point :).
Also Ive probably made some mistakes in this post.
#### how does floating point work?
Im not going to write a long explanation of how floating point works in this post, but heres a comic I wrote a few years ago that talks about the basics:
![][12]
#### floating point isnt “bad” or random
I dont want you to read this post and conclude that floating point is bad.
Its an amazing tool for doing numerical calculations. So many smart people
have done so much work to make numerical calculations on computers efficient and
accurate! Two points about how all of this isnt floating points fault:
- Doing numerical computations on a computer inherently involves
some approximation and rounding, especially if you want to do it
efficiently. You cant always store an arbitrary amount of precision for
every single number youre working with.
- Floating point is standardized (IEEE 754), so operations like addition on
floating point numbers are deterministic my understanding is that 0.1 +
0.2 will always give you the exact same result (0.30000000000000004), even
across different architectures. It might not be the result you _expected_,
but its actually very predictable.
My goal for this post is just to explain what kind of problems can come up with
floating point numbers and why they happen so that you know when to be
careful with them, and when theyre not appropriate.
Now lets get into the examples.
#### example 1: the odometer that stopped
One person said that they were working on an odometer that was continuously
adding small amounts to a 32-bit float to measure distance travelled, and
things went very wrong.
To make this concrete, lets say that were adding numbers to the odometer 1cm
at a time. What does it look like after 10,000 kilometers?
Heres a C program that simulates that:
```
#include <stdio.h>
int main() {
float meters = 0;
int iterations = 100000000;
for (int i = 0; i < iterations; i++) {
meters += 0.01;
}
printf("Expected: %f km\n", 0.01 * iterations / 1000 );
printf("Got: %f km \n", meters / 1000);
}
```
and heres the output:
```
Expected: 10000.000000 km
Got: 262.144012 km
```
This is VERY bad its not a small error, 262km is a LOT less than 10,000km. What went wrong?
#### what went wrong: gaps between floating point numbers get big
The problem in this case is that, for 32-bit floats, 262144.0 + 0.01 = 262144.0.
So its not just that the number is inaccurate, itll actually never increase
at all! If we travelled another 10,000 kilometers, the odometer would still be
stuck at 262144 meters (aka 262.144km).
Why is this happening? Well, floating point numbers get farther apart as they get bigger. In this example, for 32-bit floats, here are 3 consecutive floating point numbers:
- 262144.0
- 262144.03125
- 262144.0625
I got those numbers by going to [https://float.exposed/0x48800000][13] and incrementing the significand number a couple of times.
So, there are no 32-bit floating point numbers between 262144.0 and 262144.03125. Why is that a problem?
The problem is that 262144.03125 is about 262144.0 + 0.03. So when we try to
add 0.01 to 262144.0, it doesnt make sense to round up to the next number. So
the sum just stays at 262144.0.
Also, its not a coincidence that 262144 is a power of 2 (its 2^18). The gaps
been floating point numbers change after every power of 2, and at 2^18 the gap
between 32-bit floats is 0.03125, increasing from 0.016ish.
#### one way to solve this: use a double
Using a 64-bit float fixes this if we replace `float` with `double` in the above C program, everything works a lot better. Heres the output:
```
Expected: 10000.000000 km
Got: 9999.999825 km
```
There are still some small inaccuracies here were off about 17 centimeters.
Whether this matters or not depends on the context: being slightly off could very
well be disastrous if we were doing a precision space maneuver or something, but
its probably fine for an odometer.
Another way to improve this would be to increment the odometer in bigger chunks
instead of adding 1cm at a time, maybe we could update it less frequently,
like every 50cm.
If we use a double **and** increment by 50cm instead of 1cm, we get the exact
correct answer:
```
Expected: 10000.000000 km
Got: 10000.000000 km
```
A third way to solve this could be to use an **integer**: maybe we decide that
the smallest unit we care about is 0.1mm, and then measure everything as
integer multiples of 0.1mm. I have never built an odometer so I cant say what
the best approach is.
#### example 2: tweet IDs in Javascript
Javascript only has floating point numbers it doesnt have an integer type.
The biggest integer you can represent in a 64-bit floating point number is
2^53.
But tweet IDs are big numbers, bigger than 2^53. The Twitter API now returns
them as both integers and strings, so that in Javascript you can just use the
string ID (like “1612850010110005250”), but if you tried to use the integer
version in JS, things would go very wrong.
You can check this yourself by taking a tweet ID and putting it in the
Javascript console, like this:
```
>> 1612850010110005250
1612850010110005200
```
Notice that 1612850010110005200 is NOT the same number as 1612850010110005250!! Its 50 less!
This particular issue doesnt happen in Python (or any other language that I
know of), because Python has integers. Heres what happens if we enter the same number in a Python REPL:
```
In [3]: 1612850010110005250
Out[3]: 1612850010110005250
```
Same number, as youd expect.
#### example 2.1: the corrupted JSON data
This is a small variant of the “tweet IDs in Javascript” issue, but even if
youre _not_ actually writing Javascript code, numbers in JSON are still sometimes
treated as if theyre floats. This mostly makes sense to me because JSON has
“Javascript” in the name, so it seems reasonable to decode the values the way
Javascript would.
For example, if we pass some JSON through `jq`, we see the exact same issue:
the number 1612850010110005250 gets changed into 1612850010110005200.
```
$ echo '{"id": 1612850010110005250}' | jq '.'
{
"id": 1612850010110005200
}
```
But its not consistent across all JSON libraries Pythons `json` module will decode `1612850010110005250` as the correct integer.
Several people mentioned issues with sending floats in JSON, whether either
they were trying to send a large integer (like a pointer address) in JSON and
it got corrupted, or sending smaller floating point values back and forth
repeatedly and the value slowly diverging over time.
#### example 3: a variance calculation gone wrong
Lets say youre doing some statistics, and you want to calculate the variance
of many numbers. Maybe more numbers than you can easily fit in memory, so you
want to do it in a single pass.
Theres a simple (but bad!!!) algorithm you can use to calculate the variance in a single pass,
from [this blog post][14]. Heres some Python code:
```
def calculate_bad_variance(nums):
sum_of_squares = 0
sum_of_nums = 0
N = len(nums)
for num in nums:
sum_of_squares += num**2
sum_of_nums += num
mean = sum_of_nums / N
variance = (sum_of_squares - N * mean**2) / N
print(f"Real variance: {np.var(nums)}")
print(f"Bad variance: {variance}")
```
First, lets use this bad algorithm to calculate the variance of 5 small numbers. Everything looks pretty good:
```
In [2]: calculate_bad_variance([2, 7, 3, 12, 9])
Real variance: 13.84
Bad variance: 13.840000000000003 <- pretty close!
```
Now, lets try it the same 100,000 large numbers that are very close together (distributed between 100000000 and 100000000.06)
```
In [7]: calculate_bad_variance(np.random.uniform(100000000, 100000000.06, 100000))
Real variance: 0.00029959105209321173
Bad variance: -138.93632 <- OH NO
```
This is extremely bad: not only is the bad variance way off, its NEGATIVE! (the variance is never supposed to be negative, its always zero or more)
#### what went wrong: catastrophic cancellation
Whats going here is similar to our odometer number problem: the
`sum_of_squares` number gets extremely big (about 10^21 or 2^69), and at that point, the
gap between consecutive floating point numbers is also very big its 2**46.
So we just lose all precision in our calculations.
The term for this problem is “catastrophic cancellation” were subtracting
two very large floating point numbers which are both going to be pretty far
from the correct value of the calculation, so the result of the subtraction is
also going to be wrong.
[The blog post I mentioned before][14]
talks about a better algorithm people use to compute variance called
Welfords algorithm, which doesnt have the catastrophic cancellation issue.
And of course, the solution for most people is to just use a scientific
computing library like Numpy to calculate variance instead of trying to do it
yourself :)
#### example 4: different languages sometimes do the same floating point calculation differently
A bunch of people mentioned that different platforms will do the same
calculation in different ways. One way this shows up in practice is maybe
you have some frontend code and some backend code that do the exact same
floating point calculation. But its done slightly differently in Javascript
and in PHP, so you users end up seeing discrepancies and getting confused.
In principle you might think that different implementations should work the
same way because of the IEEE 754 standard for floating point, but here are a
couple of caveats that were mentioned:
- math operations in libc (like sin/log) behave differently in different
implementations. So code using glibc could give you different results than
code using musl
- some x86 instructions can use 80 bit precision for some double operations
internally instead of 64 bit precision. [Heres a GitHub issue talking about
that][15]
Im not very sure about these points and I dont have concrete examples I can reproduce.
#### example 5: the deep space kraken
Kerbal Space Program is a space simulation game, and it used to have a bug
called the [Deep Space Kraken][16] where when
you moved very fast, your ship would start getting destroyed due to floating point issues. This is similar to the other problems weve talked out involving big floating numbers (like the variance problem), but I wanted to mention it because:
- it has a funny name
- it seems like a very common bug in video games / astrophysics / simulations in general if you have points that are very far from the origin, your math gets messed up
Another example of this is the [Far Lands][17] in Minecraft.
#### example 6: the inaccurate timestamp
I promise this is the last example of “very large floating numbers can ruin your day”.
But! Just one more! Lets imagine that we try to represent the current Unix epoch in nanoseconds
(about 1673580409000000000) as a 64-bit floating point number.
This is no good! 1673580409000000000 is about 2^60 (crucially, bigger than 2^53), and the next 64-bit float after it is 1673580409000000256.
So this would be a great way to end up with inaccuracies in your time math. Of
course, time libraries actually represent times as integers, so this isnt
usually a problem. (theres always still the [year 2038 problem][18], but thats not
related to floats)
In general, the lesson here is that sometimes its better to use integers.
#### example 7: splitting a page into columns
Now that weve talked about problems with big floating point numbers, lets do
a problem with small floating point numbers.
Lets say you have a page width, and a column width, and you want to figure out:
- how many columns fit on the page
- how much space is left over
You might reasonably try `floor(page_width / column_width)` for the first
question and `page_width % column_width` for the second question. Because
that would work just fine with integers!
```
In [5]: math.floor(13.716 / 4.572)
Out[5]: 3
In [6]: 13.716 % 4.572
Out[6]: 4.571999999999999
```
This is wrong! The amount of space left is 0!
A better way to calculate the amount of space left might have been
`13.716 - 3 * 4.572`, which gives us a very small negative number.
I think the lesson here is to never calculate the same thing in 2 different ways with floats.
This is a very basic example but I can kind of see how this would create all
kinds of problems if I was doing page layout with floating point numbers, or
doing CAD drawings.
#### example 8: collision checking
Heres a very silly Python program, that starts a variable at 1000 and
decrements it until it collides with 0. You can imagine that this is part of a
pong game or something, and that `a` is a ball thats supposed to collide with
a wall.
```
a = 1000
while a != 0:
a -= 0.001
```
You might expect this program to terminate. But it doesnt! `a` is never 0,
instead it goes from 1.673494676862619e-08 to -0.0009999832650532314.
The lesson here is that instead of checking for float equality, usually you
want to check if two numbers are different by some very small amount. Or here
we could just write `while a > 0`.
#### thats all for now
I didnt even get to NaNs (the are so many of them!) or infinity or +0 / -0 or subnormals, but weve
already written 2000 words and Im going to just publish this.
I might write another followup post later that Mastodon thread has literally
15,000 words of floating point problems in it, theres a lot of material! Or I
might not, who knows :)
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://mastodon.social/@b0rk/109670855322107281
[2]: https://jvns.ca#how-does-floating-point-work
[3]: https://jvns.ca#floating-point-isn-t-bad-or-random
[4]: https://jvns.ca#example-1-the-odometer-that-stopped
[5]: https://jvns.ca#example-2-tweet-ids-in-javascript
[6]: https://jvns.ca#example-3-a-variance-calculation-gone-wrong
[7]: https://jvns.ca#example-4-different-languages-sometimes-do-the-same-floating-point-calculation-differently
[8]: https://jvns.ca#example-5-the-deep-space-kraken
[9]: https://jvns.ca#example-6-the-inaccurate-timestamp
[10]: https://jvns.ca#example-7-splitting-a-page-into-columns
[11]: https://jvns.ca#example-8-collision-checking
[12]: https://wizardzines.com/comics/floating-point/floating-point.png
[13]: https://float.exposed/0x48800000
[14]: https://jonisalonen.com/2013/deriving-welfords-method-for-computing-variance/
[15]: https://github.com/microsoft/WSL/issues/830
[16]: https://wiki.kerbalspaceprogram.com/wiki/Deep_Space_Kraken
[17]: https://minecraftbedrock-archive.fandom.com/wiki/Far_Lands
[18]: https://en.wikipedia.org/wiki/Year_2038_problem

View File

@ -0,0 +1,472 @@
[#]: subject: "Examples of problems with integers"
[#]: via: "https://jvns.ca/blog/2023/01/18/examples-of-problems-with-integers/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Examples of problems with integers
======
Hello! A few days back we talked about [problems with floating point numbers][1].
This got me thinking but what about integers? Of course integers have all
kinds of problems too anytime you represent a number in a small fixed amount of
space (like 8/16/32/64 bits), youre going to run into problems.
So I [asked on Mastodon again][2] for examples of integer problems and got all kinds of great responses again. Heres a table of contents.
[example 1: the small database primary key][3][example 2: integer overflow/underflow][4][aside: how do computers represent negative integers?][5][example 3: decoding a binary format in Java][6][example 4: misinterpreting an IP address or string as an integer][7][example 5: security problems because of integer overflow][8][example 6: the case of the mystery byte order][9][example 7: modulo of negative numbers][10][example 8: compilers removing integer overflow checks][11][example 9: the && typo][12]
Like last time, Ive written some example programs to demonstrate these
problems. Ive tried to use a variety of languages in the examples (Go,
Javascript, Java, and C) to show that these problems dont just show up in
super low level C programs integers are everywhere!
Also Ive probably made some mistakes in here, I learned several things while writing this.
#### example 1: the small database primary key
One of the most classic (and most painful!) integer problems is:
- You create a database table where the primary key is a 32-bit unsigned integer, thinking “4 billion rows should be enough for anyone!”
- You are massively successful and eventually, your table gets close to 4 billion rows
- oh no!
- You need to do a database migration to switch your primary key to be a 64-bit integer instead
If the primary key actually reaches its maximum value Im not sure exactly what
happens, Id imagine you wouldnt be able to create any new database rows and
it would be a very bad day for your massively successful service.
#### example 2: integer overflow/underflow
Heres a Go program:
```
package main
import "fmt"
func main() {
var x uint32 = 5
var length uint32 = 0
if x < length-1 {
fmt.Printf("%d is less than %d\n", x, length-1)
}
}
```
This slightly mysteriously prints out:
```
5 is less than 4294967295
```
That true, but its not what you might have expected.
#### whats going on?
`0 - 1` is equal to the 4 bytes `0xFFFFFFFF`.
There are 2 ways to interpret those 4 bytes:
- As a _signed_ integer (-1)
- As an _unsigned_ integer (4294967295)
Go here is treating `length - 1` as a **unsigned** integer, because we defined `x` and `length` as uint32s (the “u” is for “unsigned”). So its testing if 5 is less than 4294967295, which it is!
#### what do we do about it?
Im not actually sure if theres any way to automatically detect integer overflow errors in Go. (though it looks like theres a [github issue from 2019 with some discussion][13])
Some brief notes about other languages:
- Lots of languages (Python, Java, Ruby) dont have unsigned integers at all, so this specific problem doesnt come up
- In C, you can compile with `clang -fsanitize=unsigned-integer-overflow`. Then if your code has an overflow/underflow like this, the program will crash.
- Similarly in Rust, if you compile your program in debug mode itll crash if theres an integer overflow. But in release mode it wont crash, itll just happily decide that 0 - 1 = 4294967295.
The reason Rust doesnt check for overflows if you compile your program in
release mode (and the reason C and Go dont check) is that these checks are
expensive! Integer arithmetic is a very big part of many computations, and
making sure that every single addition isnt overflowing makes it slower.
#### aside: how do computers represent negative integers?
I mentioned in the last section that `0xFFFFFFFF` can mean either `-1` or
`4294967295`. You might be thinking what??? Why would `0xFFFFFFFF` mean `-1`?
So lets talk about how computers represent negative integers for a second.
Im going to simplify and talk about 8-bit integers instead of 32-bit integers,
because there are less of them and it works basically the same way.
You can represent 256 different numbers with an 8-bit integer: 0 to 255
```
00000000 -> 0
00000001 -> 1
00000010 -> 2
...
11111111 -> 255
```
But what if you want to represent _negative_ integers? We still only have 8
bits! So we need to reassign some of these and treat them as negative numbers
instead.
Heres the way most modern computers do it:
- Every number thats 128 or more becomes a negative number instead
- How to know _which_ negative number it is: take the positive integer youd expect it to be, and then subtract 256
So 255 becomes -1, 128 becomes -128, and 200 becomes -56.
Here are some maps of bits to numbers:
```
00000000 -> 0
00000001 -> 1
00000010 -> 2
01111111 -> 127
10000000 -> -128 (previously 128)
10000001 -> -127 (previously 129)
10000010 -> -126 (previously 130)
...
11111111 -> -1 (previously 255)
```
This gives us 256 numbers, from -128 to 127.
And `11111111` (or `0xFF`, or 255) is -1.
For 32 bit integers, its the same story, except its “every number larger than 2^31 becomes negative” and “subtract 2^32”. And similarly for other integer sizes.
Thats how we end up with `0xFFFFFFFF` meaning -1.
#### there are multiple ways to represent negative integers
The way we just talked about of representing negative integers (“its the equivalent positive integer, but you subtract 2^n”) is called
**twos complement**, and its the most common on modern computers. There are several other ways
though, the [wikipedia article has a list][14].
#### weird thing: the absolute value of -128 is negative
This [Go program][15] has a pretty simple `abs()` function that computes the absolute value of an integer:
```
package main
import (
"fmt"
)
func abs(x int8) int8 {
if x < 0 {
return -x
}
return x
}
func main() {
fmt.Println(abs(-127))
fmt.Println(abs(-128))
}
```
This prints out:
```
127
-128
```
This is because the signed 8-bit integers go from -128 to 127 there **is** no +128!
Some programs might crash when you try to do this (its an overflow), but Go
doesnt.
Now that weve talked about signed integers a bunch, lets dig into another example of how they can cause problems.
#### example 3: decoding a binary format in Java
Lets say youre parsing a binary format in Java, and you want to get the first
4 bits of the byte `0x90`. The correct answer is 9.
```
public class Main {
public static void main(String[] args) {
byte b = (byte) 0x90;
System.out.println(b >> 4);
}
}
```
This prints out “-7”. Thats not right!
#### whats going on?
There are two things we need to know about Java to make sense of this:
- Java doesnt have unsigned integers.
- Java cant right shift bytes, it can only shift integers. So anytime you shift a byte, it has to be promoted into an integer.
Lets break down what those two facts mean for our little calculation `b >> 4`:
- In bits, `0x90` is `10010000`. This starts with a 1, which means that its more than 128, which means its a negative number
- Java sees the `>>` and decides to promote `0x90` to an integer, so that it can shift it
- The way you convert a negative byte to an 32-bit integer is to add a bunch of `1`s at the beginning. So now our 32-bit integer is `0xFFFFFF90` (`F` being 15, or `1111`)
- Now we right shift (`b >> 4`). By default, Java does a **signed shift**, which means that it adds 0s to the beginning if its positive, and 1s to the beginning if its negative. (`>>>` is an unsigned shift in Java)
- We end up with `0xFFFFFFF9` (having cut off the last 4 bits and added more 1s at the beginning)
- As a signed integer, thats -7!
#### what can you do about it?
I dont the actual idiomatic way to do this in Java is, but the way Id naively
approach fixing this is to put in a bit mask before doing the right shift. So
instead of:
```
b >> 4
```
wed write
```
(b & 0xFF) >> 4
```
`b & 0xFF` seems redundant (`b` is already a byte!), but its actually not because `b` is being promoted to an integer.
Now instead of `0x90 -> 0xFFFFFF90 -> 0xFFFFFFF9`, we end up calculating `0x90 -> 0xFFFFFF90 -> 0x00000090 -> 0x00000009`, which is the result we wanted: 9.
And when we actually try it, it prints out “9”.
Also, if we were using a language with unsigned integers, the natural way to
deal with this would be to treat the value as an unsigned integer in the first
place. But thats not possible in Java.
#### example 4: misinterpreting an IP address or string as an integer
I dont know if this is technically a “problem with integers” but its funny
so Ill mention it: [Rachel by the bay][16] has a bunch of great
examples of things that are not integers being interpreted as integers. For
example, “HTTP” is `0x48545450` and `2130706433` is `127.0.0.1`.
She points out that you can actually ping any integer, and itll convert that integer into an IP address, for example:
```
$ ping 2130706433
PING 2130706433 (127.0.0.1): 56 data bytes
$ ping 132848123841239999988888888888234234234234234234
PING 132848123841239999988888888888234234234234234234 (251.164.101.122): 56 data bytes
```
(Im not actually sure how ping is parsing that second integer or why ping accepts these giant larger-than-2^64-integers as valid inputs, but its a fun weird thing)
#### example 5: security problems because of integer overflow
Another integer overflow example: heres a [search for CVEs involving integer overflows][17].
There are a lot! Im not a security person, but heres one random example: this [json parsing library bug][18]
My understanding of that json parsing bug is roughly:
- you load a JSON file thats 3GB or something, or 3,000,000,000
- due to an integer overflow, the code allocates close to 0 bytes of memory instead of ~3GB amount of memory
- but the JSON file is still 3GB, so it gets copied into the tiny buffer with almost 0 bytes of memory
- this overwrites all kinds of other memory that its not supposed to
The CVE says “This vulnerability mostly impacts process availability”, which I
think means “the program crashes”, but sometimes this kind of thing is much
worse and can result in arbitrary code execution.
My impression is that there are a large variety of different flavours of
security vulnerabilities caused by integer overflows.
#### example 6: the case of the mystery byte order
One person said that theyre do scientific computing and sometimes they need to
read files which contain data with an unknown byte order.
Lets invent a small example of this: say youre reading a file which contains 4
bytes - `00`, `00`, `12`, and `81` (in that order), that you happen to know
represent a 4-byte integer. There are 2 ways to interpret that integer:
- `0x00001281` (which translates to 4737). This order is called “big endian”
- `0x81120000` (which translates to 2165440512). This order is called “little endian”.
Which one is it? Well, maybe the file contains some metadata that specifies the
endianness. Or maybe you happen to know what machine it was generated on and
what byte order that machine uses. Or maybe you just read a bunch of values,
try both orders, and figure out which makes more sense. Maybe 2165440512 is too
big to make sense in the context of whatever your data is supposed to mean, or
maybe `4737` is too small.
A couple more notes on this:
- this isnt just a problem with integers, floating point numbers have byte
order too
- this also comes up when reading data from a network, but in that case the
byte order isnt a “mystery”, its just going to be big endian. But x86
machines (and many others) are little endian, so you have to swap the byte
order of all your numbers.
#### example 7: modulo of negative numbers
This is more of a design decision about how different programming languages design their math libraries, but its still a little weird and lots of people mentioned it.
Lets say you write `-13 % 3` in your program, or `13 % -3`. Whats the result?
It turns out that different programming languages do it differently, for
example in Python `-13 % 3 = 2` but in Javascript `-13 % 3 = -1`.
Theres a table in [this blog post][19] that
describes a bunch of different programming languages choices.
#### example 8: compilers removing integer overflow checks
Weve been hearing a lot about integer overflow and why its bad. So lets
imagine you try to be safe and include some checks in your programs after
each addition, you make sure that the calculation didnt overflow. Like this:
```
#include <stdio.h>
#define INT_MAX 2147483647
int check_overflow(int n) {
n = n + 100;
if (n + 100 < 0)
return -1;
return 0;
}
int main() {
int result = check_overflow(INT_MAX);
printf("%d\n", result);
}
```
`check_overflow` here should return `-1` (failure), because `INT_MAX + 100` is more than the maximum integer size.
```
$ gcc check_overflow.c -o check_overflow && ./check_overflow
-1
$ gcc -O3 check_overflow.c -o check_overflow && ./check_overflow
0
```
Thats weird when we compile with `gcc`, we get the answer we expected, but
with `gcc -O3`, we get a different answer. Why?
#### whats going on?
My understanding (which might be wrong) is:
- Signed integer overflow in C is **undefined behavior**. I think thats
because different C implementations might be using different representations
of signed integers (maybe theyre using ones complement instead of twos
complement or something)
- “undefined behaviour” in C means “the compiler is free to do literally whatever it wants after that point” (see this post [With undefined behaviour, anything is possible][20] by Raph Levine for a lot more)
- Some compiler optimizations assume that undefined behaviour will never
happen. Theyre free to do this, because if that undefined behaviour
_did_ happen, then theyre allowed to do whatever they want, so “run the
code that I optimized assuming that this would never happen” is fine.
- So this `if (n + 100 < 0)` check is irrelevant if that did
happen, it would be undefined behaviour, so theres no need to execute the
contents of that if statement.
So, thats weird. Im not going to write a “what can you do about it?” section here because Im pretty out of my depth already.
I certainly would not have expected that though.
My impression is that “undefined behaviour” is really a C/C++ concept, and
doesnt exist in other languages in the same way except in the case of “your
program called some C code in an incorrect way and that C code did something
weird because of undefined behaviour”. Which of course happens all the time.
#### example 9: the && typo
This one was mentioned as a very upsetting bug. Lets say you have two integers
and you want to check that theyre both nonzero.
In Javascript, you might write:
```
if a && b {
/* some code */
}
```
But you could also make a typo and type:
```
if a & b {
/* some code */
}
```
This is still perfectly valid code, but it means something completely different
its a bitwise and instead of a boolean and. Lets go into a Javascript
console and look at bitwise vs boolean and for `9` and `4`:
```
> 9 && 4
4
> 9 & 4
0
> 4 && 5
5
> 4 & 5
4
```
Its easy to imagine this turning into a REALLY annoying bug since it would be
intermittent often `x & y` does turn out to be truthy if `x && y` is truthy.
#### what to do about it?
For Javascript, ESLint has a [no-bitwise check][21] check), which
requires you manually flag “no, I actually know what Im doing, I want to do
bitwise and” if you use a bitwise and in your code. Im sure many other linters
have a similar check.
#### thats all for now!
There are definitely more problems with integers than this, but this got pretty
long again and Im tired of writing again so Im going to stop :)
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/01/18/examples-of-problems-with-integers/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/
[2]: https://social.jvns.ca/@b0rk/109700446576896509
[3]: https://jvns.ca#example-1-the-small-database-primary-key
[4]: https://jvns.ca#example-2-integer-overflow-underflow
[5]: https://jvns.ca#aside-how-do-computers-represent-negative-integers
[6]: https://jvns.ca#example-3-decoding-a-binary-format-in-java
[7]: https://jvns.ca#example-4-misinterpreting-an-ip-address-or-string-as-an-integer
[8]: https://jvns.ca#example-5-security-problems-because-of-integer-overflow
[9]: https://jvns.ca#example-6-the-case-of-the-mystery-byte-order
[10]: https://jvns.ca#example-7-modulo-of-negative-numbers
[11]: https://jvns.ca#example-8-compilers-removing-integer-overflow-checks
[12]: https://jvns.ca#example-9-the-typo
[13]: https://github.com/golang/go/issues/30613
[14]: https://en.wikipedia.org/wiki/Signed_number_representations
[15]: https://go.dev/play/p/iSFxbFAe75M
[16]: https://rachelbythebay.com/w/2020/11/26/magic/
[17]: https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=integer+overflow
[18]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-24795
[19]: https://torstencurdt.com/tech/posts/modulo-of-negative-numbers/
[20]: https://raphlinus.github.io/programming/rust/2018/08/17/undefined-behavior.html
[21]: https://eslint.org/docs/latest/rules/no-bitwise

View File

@ -0,0 +1,386 @@
[#]: subject: "Why does 0.1 + 0.2 = 0.30000000000000004?"
[#]: via: "https://jvns.ca/blog/2023/02/08/why-does-0-1-plus-0-2-equal-0-30000000000000004/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Why does 0.1 + 0.2 = 0.30000000000000004?
======
Hello! I was trying to write about floating point yesterday,
and I found myself wondering about this calculation, with 64-bit floats:
```
>>> 0.1 + 0.2
0.30000000000000004
```
I realized that I didnt understand exactly how it worked. I mean, I know
floating point calculations are inexact, and I know that you cant exactly
represent `0.1` in binary, but: theres a floating point number thats closer to
0.3 than `0.30000000000000004`! So why do we get the answer
`0.30000000000000004`?
If you dont feel like reading this whole post with a bunch of calculations, the short answer is that
`0.1000000000000000055511151231257827021181583404541015625 + 0.200000000000000011102230246251565404236316680908203125` lies exactly between
2 floating point numbers,
`0.299999999999999988897769753748434595763683319091796875` (usually printed as `0.3`) and
`0.3000000000000000444089209850062616169452667236328125` (usually printed as `0.30000000000000004`). The answer is
`0.30000000000000004` (the second one) because its significand is even.
#### how floating point addition works
This is roughly how floating point addition works:
- Add together the numbers (with extra precision)
- Round the result to the nearest floating point number
So lets use these rules to calculate 0.1 + 0.2. I just learned how floating
point addition works yesterday so its possible Ive made some mistakes in this
post, but I did get the answers I expected at the end.
#### step 1: find out what 0.1 and 0.2 are
First, lets use Python to figure out what the exact values of `0.1` and `0.2` are, as 64-bit floats.
```
>>> f"{0.1:.80f}"
'0.10000000000000000555111512312578270211815834045410156250000000000000000000000000'
>>> f"{0.2:.80f}"
'0.20000000000000001110223024625156540423631668090820312500000000000000000000000000'
```
These really are the exact values: because floating point numbers are in base
2, you can represent them all exactly in base 10. You just need a lot of digits
sometimes :)
#### step 2: add the numbers together
Next, lets add those numbers together. We can add the fractional parts together as integers to get the exact answer:
```
>>> 1000000000000000055511151231257827021181583404541015625 + 2000000000000000111022302462515654042363166809082031250
3000000000000000166533453693773481063544750213623046875
```
So the exact sum of those two floating point numbers is `0.3000000000000000166533453693773481063544750213623046875`
This isnt our final answer though because `0.3000000000000000166533453693773481063544750213623046875` isnt a 64-bit float.
#### step 3: look at the nearest floating point numbers
Now, lets look at the floating point numbers around `0.3`. Heres the closest floating point number to `0.3` (usually written as just `0.3`, even though that isnt its exact value):
```
>>> f"{0.3:.80f}"
'0.29999999999999998889776975374843459576368331909179687500000000000000000000000000'
```
We can figure out the next floating point number after `0.3` by serializing
`0.3` to 8 bytes with `struct.pack`, adding 1, and then using `struct.unpack`:
```
>>> struct.pack("!d", 0.3)
b'?\xd3333333'
# manually add 1 to the last byte
>>> next_float = struct.unpack("!d", b'?\xd3333334')[0]
>>> next_float
0.30000000000000004
>>> f"{next_float:.80f}"
'0.30000000000000004440892098500626161694526672363281250000000000000000000000000000'
```
Apparently you can also do this with `math.nextafter`:
```
>>> math.nextafter(0.3, math.inf)
0.30000000000000004
```
So the two 64-bit floats around
`0.3` are
`0.299999999999999988897769753748434595763683319091796875` and
`0.3000000000000000444089209850062616169452667236328125`
#### step 4: find out which one is closest to our result
It turns out that `0.3000000000000000166533453693773481063544750213623046875`
is exactly in the middle of
`0.299999999999999988897769753748434595763683319091796875` and
`0.3000000000000000444089209850062616169452667236328125`.
You can see that with this calculation:
```
>>> (3000000000000000444089209850062616169452667236328125000 + 2999999999999999888977697537484345957636833190917968750) // 2 == 3000000000000000166533453693773481063544750213623046875
True
```
So neither of them is closest.
#### how does it know which one to round to?
In the binary representation of a floating point number, theres a number
called the “significand”. In cases like this (where the result is exactly in
between 2 successive floating point number, itll round to the one with the
even significand.
In this case thats `0.300000000000000044408920985006261616945266723632812500`
We actually saw the significand of this number a bit earlier:
- 0.30000000000000004 is `struct.unpack('!d', b'?\xd3333334')`
- 0.3 is `struct.unpack('!d', b'?\xd3333333')`
The last digit of the big endian hex representation of `0.30000000000000004` is
`4`, so thats the one with the even significand (because the significand is at
the end).
#### lets also work out the whole calculation in binary
Above we did the calculation in decimal, because thats a little more intuitive
to read. But of course computers dont do these calculations in decimal
theyre done in a base 2 representation. So I wanted to get an idea of how that
worked too.
I dont think this binary calculation part of the post is particularly clear
but it was helpful for me to write out. There are a really a lot of numbers and
it might be terrible to read.
#### how 64-bit floats numbers work: exponent and significand
64-bit floating point numbers are represented with 2 integers: an **exponent** and the **significand** and a 1-bit **sign**.
Heres the equation of how the exponent and significand correspond to an actual number
$$\text{sign} \times 2^\text{exponent} (1 + \frac{\text{significand}}{2^{52}})$$
For example if the exponent was `1` the significand was `2**51`, and the sign was positive, wed get
$$2^{1} (1 + \frac{2^{51}}{2^{52}})$$
which is equal to `2 * (1 + 0.5)` , or 3.
#### step 1: get the exponent and significand for 0.1 and 0.2
I wrote some inefficient functions to get the exponent and significand of a positive float in Python:
```
def get_exponent(f):
# get the first 12 bytes
bytestring = struct.pack('!d', f)
return int.from_bytes(bytestring, byteorder='big') >> 52
def get_significand(f):
# get the last 52 bytes
bytestring = struct.pack('!d', f)
x = int.from_bytes(bytestring, byteorder='big')
exponent = get_exponent(f)
return x ^ (exponent << 52)
```
Im ignoring the sign bit (the first bit) because we only need these functions
to work on two numbers (0.1 and 0.2) and those two numbers are both positive.
First, lets get the exponent and significand of 0.1. We need to subtract 1023
to get the actual exponent because thats how floating point works.
```
>>> get_exponent(0.1) - 1023
-4
>>> get_significand(0.1)
2702159776422298
```
The way these numbers work together to get `0.1` is `2**exponent + significand / 2**(52 - exponent)`.
Heres that calculation in Python:
```
>>> 2**-4 + 2702159776422298 / 2**(52 + 4)
0.1
```
(you might legitimately be worried about floating point accuracy issues with
this calculation, but in this case Im pretty sure its fine because these
numbers by definition dont have accuracy issues the floating point numbers starting at `2**-4` go up in steps of `1/2**(52 + 4)`)
We can do the same thing for `0.2`:
```
>>> get_exponent(0.2) - 1023
-3
>>> get_significand(0.2)
2702159776422298
```
And heres how that exponent and significand work together to get `0.2`:
```
>>> 2**-3 + 2702159776422298 / 2**(52 + 3)
0.2
```
(by the way, its not a coincidence that 0.1 and 0.2 have the same significand its because `x` and `2*x` always have the same significand)
#### step 2: rewrite 0.1 to have a bigger exponent
`0.2` has a bigger exponent than `0.1` -3 instead of -4.
So we need to rewrite
```
2**-4 + 2702159776422298 / 2**(52 + 4)
```
to be `X / (2**52 + 3)`
If we solve for X in `2**-4 + 2702159776422298 / 2**(52 + 4) = X / (2**52 + 3)`, we get:
`X = 2**51 + 2702159776422298 /2`
We can calculate that in Python pretty easily:
```
>>> 2**51 + 2702159776422298 //2
3602879701896397
```
#### step 3: add the significands
Now were trying to do this addition
```
2**-3 + 2702159776422298 / 2**(52 + 3) + 3602879701896397 / 2**(52 + 3)
```
So we need to add together `2702159776422298` and `3602879701896397`
```
>>> 2702159776422298 + 3602879701896397
6305039478318695
```
Cool. But `6305039478318695` is more than 2**52 - 1 (the maximum value for a significand), so we have a problem:
```
>>> 6305039478318695 > 2**52
True
```
#### step 4: increase the exponent
Right now our answer is
```
2**-3 + 6305039478318695 / 2**(52 + 3)
```
First, lets subtract 2**52 to get
```
2**-2 + 1801439850948199 / 2**(52 + 3)
```
This is almost perfect, but the `2**(52 + 3)` at the end there needs to be a `2**(52 + 2)`.
So we need to divide 1801439850948199 by 2. This is where we run into inaccuracies `1801439850948199` is odd!
```
>>> 1801439850948199 / 2
900719925474099.5
```
Its exactly in between two integers, so we round to the nearest even number (which is what the floating point specification says to do), so our final floating point number result is:
```
>>> 2**-2 + 900719925474100 / 2**(52 + 2)
0.30000000000000004
```
Thats the answer we expected:
```
>>> 0.1 + 0.2
0.30000000000000004
```
#### this probably isnt exactly how it works in hardware
The way Ive described the operations here isnt literally exactly
what happens when you do floating point addition (its not “solving for X” for
example), Im sure there are a lot of efficient tricks. But I think its about
the same idea.
#### printing out floating point numbers is pretty weird
We said earlier that the floating point number 0.3 isnt equal to 0.3. Its actually this number:
```
>>> f"{0.3:.80f}"
'0.29999999999999998889776975374843459576368331909179687500000000000000000000000000'
```
So when you print out that number, why does it display `0.3`?
The computer isnt actually printing out the exact value of the number, instead
its printing out the _shortest_ decimal number `d` which has the property that
our floating point number `f` is the closest floating point number to `d`.
It turns out that doing this efficiently isnt trivial at all, and there are a bunch of academic papers about it like [Printing Floating-Point Numbers Quickly and Accurately][1]. or [How to print floating point numbers accurately][2].
#### would it be more intuitive if computers printed out the exact value of a float?
Rounding to a nice clean decimal value is nice, but in a way I feel like it
might be more intuitive if computers just printed out the exact value of a
floating point number it might make it seem a lot less surprising when you
get weird results.
To me,
0.1000000000000000055511151231257827021181583404541015625 +
0.200000000000000011102230246251565404236316680908203125
= 0.3000000000000000444089209850062616169452667236328125 feels less surprising than 0.1 + 0.2 = 0.30000000000000004.
Probably this is a bad idea, it would definitely use a lot of screen space.
#### a quick note on PHP
Someone in the comments somewhere pointed out that `<?php echo (0.1 + 0.2 );?>`
prints out `0.3`. Does that mean that floating point math is different in PHP?
I think the answer is no if I run:
`<?php echo (0.1 + 0.2 )- 0.3);?>` on [this
page][3], I get the exact same answer as in
Python 5.5511151231258E-17. So it seems like the underlying floating point
math is the same.
I think the reason that `0.1 + 0.2` prints out `0.3` in PHP is that PHPs
algorithm for displaying floating point numbers is less precise than Pythons
itll display `0.3` even if that number isnt the closest floating point
number to 0.3.
#### thats all!
I kind of doubt that anyone had the patience to follow all of that arithmetic,
but it was helpful for me to write down, so Im publishing this post anyway.
Hopefully some of this makes sense.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/02/08/why-does-0-1-plus-0-2-equal-0-30000000000000004/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://legacy.cs.indiana.edu/~dyb/pubs/FP-Printing-PLDI96.pdf
[2]: https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfkieTlklRzN.pdf
[3]: https://replit.com/languages/php_cli

View File

@ -0,0 +1,226 @@
[#]: subject: "Writing Javascript without a build system"
[#]: via: "https://jvns.ca/blog/2023/02/16/writing-javascript-without-a-build-system/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Writing Javascript without a build system
======
Hello! Ive been writing some Javascript this week, and as always when I start
a new frontend project, I was faced with the question: should I use a build
system?
I want to talk about whats appealing to me about build systems, why I
(usually) still dont use them, and why I find it frustrating that some
frontend Javascript libraries require that you use a build system.
Im writing this because most of the writing I see about JS assumes that
youre using a build system, and it can be hard to navigate for folks like me
who write very simple small Javascript projects that dont require a build
system.
#### whats a build system?
The idea is that you have a bunch of Javascript or Typescript code, and you
want to translate it into different Javascript code before you put it on your
website.
Build systems can do lots of useful things, like:
- combining 100s of JS files into one big bundle (for efficiency reasons)
- translating Typescript into Javascript
- typechecking Typescript
- minification
- adding polyfills to support older browsers
- compiling JSX
- treeshaking (remove unused JS code to reduce file sizes)
- building CSS (like [tailwind][1] does)
- and probably lots of other important things
Because of this, if youre building a complex frontend project today, probably youre using a build system like webpack, rollup, esbuild, parcel, or vite.
Lots of those features are appealing to me, and Ive used build systems in the past for some of these reasons: [Mess With DNS][2] uses `esbuild` to translate Typescript and combine lots of files into one big file, for example.
#### the goal: easily make changes to old tiny websites
I make a lot [of][3][small][4][simple][5][websites][6], I have approximately 0 maintenance energy for any of them, and I change them very infrequently.
My goal is that if I have a site that I made 3 or 5 years ago, Id like to be able to, in 20 minutes:
- get the source from github on a new computer
- make some changes
- put it on the internet
But my experience with build systems (not just Javascript build systems!), is
that if you have a 5-year-old site, often its a huge pain to get the site
built again.
And because most of my websites are pretty small, the _advantage_ of using a
build system is pretty small I dont really need Typescript or JSX. I can
just have one 400-line `script.js` file and call it a day.
#### example: trying to build the SQL playground
One of my sites (the [sql playground][5]) uses a build system (its using Vue). I last edited that project 2 years ago, on a different machine.
Lets see if I can still easily build it today on my machine. To start out, we have to run `npm install`. Heres the output I get.
```
$ npm install
[lots of output redacted]
npm ERR! code 1
npm ERR! path /Users/bork/work/sql-playground.wizardzines.com/node_modules/grpc
npm ERR! command failed
npm ERR! command sh /var/folders/3z/g3qrs9s96mg6r4dmzryjn3mm0000gn/T/install-b52c96ad.sh
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/surface/init.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/avl/avl.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/backoff/backoff.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/channel/channel_args.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/channel/channel_stack.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/channel/channel_stack_builder.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/channel/channel_trace.o
npm ERR! CXX(target) Release/obj.target/grpc/deps/grpc/src/core/lib/channel/channelz.o
```
Theres some kind of error building `grpc`. No problem. I dont
really need that dependency anyway, so I can just take 5 minutes to tear it out
and rebuild. Now I can `npm install` and everything works.
Now lets try to build the project:
```
$ npm run build
? Building for production...Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:130:10)
at module.exports (/Users/bork/work/sql-playground.wizardzines.com/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/bork/work/sql-playground.wizardzines.com/node_modules/webpack/lib/NormalModule.js:414:16)
at handleParseError (/Users/bork/work/sql-playground.wizardzines.com/node_modules/webpack/lib/NormalModule.js:467:10)
at /Users/bork/work/sql-playground.wizardzines.com/node_modules/webpack/lib/NormalModule.js:499:5
at /Users/bork/work/sql-playground.wizardzines.com/node_modules/webpack/lib/NormalModule.js:356:12
at /Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
at /Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:236:3
at runSyncOrAsync (/Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
at iterateNormalLoaders (/Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
at Array.<anonymous> (/Users/bork/work/sql-playground.wizardzines.com/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
at Storage.finished (/Users/bork/work/sql-playground.wizardzines.com/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16)
at /Users/bork/work/sql-playground.wizardzines.com/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9
```
[This stack overflow answer][7] suggests running `export NODE_OPTIONS=--openssl-legacy-provider` to fix this error.
That works, and finally I can `npm run build` to build the project.
This isnt really that bad (I only had to remove a dependency and pass a slightly mysterious node option!),
but I would rather not be derailed by those build errors.
#### for me, a build system isnt worth it for small projects
For me, a complicated Javascript build system just doesnt seem worth it for
small 500-line projects it means giving up being able to easily update the
project in the future in exchange for some pretty marginal benefits.
#### esbuild seems a little more stable
I want to give a quick shoutout to esbuild: I [learned about esbuild in 2021][8] and used for a project, and
so far it does seem a more reliable way to build JS projects.
I just tried to build an `esbuild` project that I last touched 8 months ago on
a new computer, and it worked. But I cant say for sure if Ill be able to
easily build that project in 2 years. Maybe it will, I hope so!
#### not using a build system is usually pretty easy
Heres what the part of [nginx playground][6] code that imports all the libraries looks like:
```
<script src="js/vue.global.prod.js"></script>
<script src="codemirror-5.63.0/lib/codemirror.js"></script>
<script src="codemirror-5.63.0/mode/nginx/nginx.js"></script>
<script src="codemirror-5.63.0/mode/shell/shell.js"></script>
<script src="codemirror-5.63.0/mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="codemirror-5.63.0/lib/codemirror.css">
<script src="script.js "></script>
```
This project is also using Vue, but it just uses a `<script src` to load Vue
theres no build process for the frontend.
#### a no-build-system template for using Vue
A couple of people asked how to get started writing Javascript without a build
system. Of course you can write vanilla JS if you want, but my usual framework
is Vue 3.
[Heres a tiny template I built][9]
for starting a Vue 3 project with no build system. Its just 2 files and ~30 lines of HTML/JS.
#### some libraries require you to use a build system
This build system stuff is on my mind recently because Im using CodeMirror 5
for a new project this week, and I saw there was a new version, CodeMirror 6.
So I thought cool, maybe I should use CodeMirror 6 instead of CodeMirror 5.
But it seems like you cant use CodeMirror 6 without a build system (according to [the migration guide][10]). So Im going to stick with CodeMirror 5.
Similarly, you used to be able to just download Tailwind as a giant CSS file,
but [Tailwind 3][11] doesnt seem to be available as a
big CSS file at all anymore, you need to run Javascript to build it. So Im
going to keep using Tailwind 2 for now. (I know, I know, youre not supposed to use the big CSS file, but its only 300KB gzipped and I really dont want a build step)
(edit: it looks like Tailwind released a [standalone CLI][12] in 2021 which seems like a nice option)
Im not totally sure why some libraries dont provide a no-build-system version
maybe distributing a no-build-system version would add a lot of additional
complexity to the library, and the maintainer doesnt think its worth it. Or
maybe the librarys design means that its not possible to distribute a
no-build-system version for some reason.
#### Id love more tips for no-build-system javascript
My main strategies so far are:
- search for “CDN” on a librarys website to find a standalone javascript file
- use [https://unpkg.com][13] to see if the library has a built version I can use
- host my own version of libraries instead of relying on a CDN that might go down
- write my own simple integrations instead of pulling in another dependency (for example I wrote my own CodeMirror component for Vue the other day)
- if I want a build system, use esbuild
A couple of other things that look interesting but that I havent looked into:
- this [typescript proposal for type syntax in Javascript comments][14]
- ES modules generally
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/02/16/writing-javascript-without-a-build-system/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://tailwindcss.com/
[2]: https://messwithdns.net/
[3]: https://css-examples.wizardzines.com/
[4]: https://questions.wizardzines.com
[5]: https://sql-playground.wizardzines.com/
[6]: https://nginx-playground.wizardzines.com/
[7]: https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
[8]: https://jvns.ca/blog/2021/11/15/esbuild-vue/
[9]: https://github.com/jvns/vue3-tiny-template
[10]: https://codemirror.net/docs/migration/
[11]: https://tailwindcss.com/docs/installation
[12]: https://tailwindcss.com/blog/standalone-cli
[13]: https://unpkg.com
[14]: https://devblogs.microsoft.com/typescript/a-proposal-for-type-syntax-in-javascript/

View File

@ -0,0 +1,381 @@
[#]: subject: "Some notes on using nix"
[#]: via: "https://jvns.ca/blog/2023/02/28/some-notes-on-using-nix/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Some notes on using nix
======
Recently I started using a Mac for the first time. The biggest downside Ive
noticed so far is that the package management is much worse than on Linux.
At some point I got frustrated with homebrew because I felt like it was
spending too much time upgrading when I installed new packages, and so I
thought maybe Ill try the [nix][1] package manager!
nix has a reputation for being confusing (it has its whole
own programming language!), so Ive been trying to figure out how to use nix in
a way thats as simple as possible and does not involve managing any
configuration files or learning a new programming language. Heres what Ive
figured out so far! Well talk about how to:
- install packages with nix
- build a custom nix package for a C++ program called [paperjam][2]
- install a 5-year-old version of [hugo][3] with nix
As usual Ive probably gotten some stuff wrong in this post since Im still
pretty new to nix. Im also still not sure how much I like nix its very
confusing! But its helped me compile some software that I was struggling to
compile otherwise, and in general it seems to install things faster than
homebrew.
#### whats interesting about nix?
People often describe nix as “declarative package management”. I dont
care that much about declarative package management, so here are two things
that I appreciate about nix:
- It provides binary packages (hosted at [https://cache.nixos.org/][4]) that you can quickly download and install
- For packages which dont have binary packages, it makes it easier to compile them
I think that the reason nix is good at compiling software is that:
- you can have multiple versions of the same library or program installed at a time (you could have 2 different versions of libc for instance). For example I have two versions of node on my computer right now, one at `/nix/store/4ykq0lpvmskdlhrvz1j3kwslgc6c7pnv-nodejs-16.17.1` and one at `/nix/store/5y4bd2r99zhdbir95w5pf51bwfg37bwa-nodejs-18.9.1`.
- when nix builds a package, it builds it in isolation, using only the
specific versions of its dependencies that you explicitly declared. So
theres no risk that the package secretly depends on another package on your
system that you dont know about. No more fighting with `LD_LIBRARY_PATH`!
- a lot of people have put a lot of work into writing down all of the
dependencies of packages
Ill give a couple of examples later in this post of two times nix made it easier for me to compile software.
#### how I got started with nix
heres how I got started with nix:
- Install nix. I forget exactly how I did this, but it looks like theres an [official installer][5] and an [unofficial installer from zero-to-nix.com][6]. The [instructions for uninstalling nix on MacOS with the standard multi-user install][7] are a bit complicated, so it might be worth choosing an installation method with simpler uninstall instructions.
- Put `~/.nix-profile/bin` on my PATH
- Install packages with `nix-env -iA nixpkgs.NAME`
- Thats it.
Basically the idea is to treat `nix-env -iA` like `brew install` or `apt-get install`.
For example, if I want to install `fish`, I can do that like this:
```
nix-env -iA nixpkgs.fish
```
This seems to just download some binaries from [https://cache.nixos.org][8] pretty simple.
Some people use nix to install their Node and Python and Ruby packages, but I havent
been doing that I just use `npm install` and `pip install` the same way I
always have.
#### some nix features Im not using
There are a bunch of nix features/tools that Im not using, but that Ill
mention. I originally thought that you _had_ to use these features to use nix,
because most of the nix tutorials Ive read talk about them. But you dont have to use them.
- NixOS (a Linux distribution)
- [nix-shell][9]
- [nix flakes][10]
- [home-manager][11]
- [devenv.sh][12]
I wont go into these because I havent really used them and there are lots of
explanations out there.
#### where are nix packages defined?
I think packages in the main nix package repository are defined in [https://github.com/NixOS/nixpkgs/][13]
It looks like you can search for packages at [https://search.nixos.org/packages][14]. The two official ways to search packages seem to be:
- `nix-env -qaP NAME`, which is very extremely slow and which I havent been able to get to actually work
- `nix --extra-experimental-features 'nix-command flakes' search nixpkgs NAME`, which does seem to work but is kind of a mouthful. Also all of the packages it prints out start with `legacyPackages` for some reason
I found a way to search nix packages from the command line that I liked better:
- Run `nix-env -qa '*' > nix-packages.txt` to get a list of every package in the Nix repository
- Write a short `nix-search` script that just greps `packages.txt` (`cat ~/bin/nix-packages.txt | awk '{print $1}' | rg "$1"`)
#### everything is installed with symlinks
One of nixs major design choices is that there isnt one single `bin` with all
your packages, instead you use symlinks. There are a lot of layers of symlinks. A few examples of symlinks:
- `~/.nix-profile` on my machine is (indirectly) a symlink to `/nix/var/nix/profiles/per-user/bork/profile-111-link/`
- `~/.nix-profile/bin/fish` is a symlink to `/nix/store/afkwn6k8p8g97jiqgx9nd26503s35mgi-fish-3.5.1/bin/fish`
When I install something, it creates a new `profile-112-link` directory with new symlinks and updates my `~/.nix-profile` to point to that directory.
I think this means that if I install a new version of `fish` and I dont like it, I can
easily go back just by running `nix-env --rollback` itll move me to my previous profile directory.
#### uninstalling packages doesnt delete them
If I uninstall a nix package like this, it doesnt actually free any hard drive space, it just removes the symlinks.
```
$ nix-env --uninstall oil
```
Im still not sure how to actually delete the package I ran a garbage collection like this, which seemed to delete some things:
```
$ nix-collect-garbage
...
85 store paths deleted, 74.90 MiB freed
```
But I still have `oil` on my system at `/nix/store/8pjnk6jr54z77jiq5g2dbx8887dnxbda-oil-0.14.0`.
Theres a more aggressive version of `nix-collect-garbage` that also deletes old versions of your profiles (so that you cant rollback)
```
$ nix-collect-garbage -d --delete-old
```
That doesnt delete `/nix/store/8pjnk6jr54z77jiq5g2dbx8887dnxbda-oil-0.14.0` either though and Im not sure why.
#### upgrading
It looks like you can upgrade nix packages like this:
```
nix-channel --update
nix-env --upgrade
```
(similar to `apt-get update && apt-get upgrade`)
I havent really upgraded anything yet. I think that if something goes wrong with an upgrade, you can roll back (because everything is immutable in nix!) with
```
nix-env --rollback
```
Someone linked me to [this post from Ian Henry][15] that
talks about some confusing problems with `nix-env --upgrade` maybe it
doesnt work the way youd expect? I guess Ill be wary around upgrades.
#### next goal: make a custom package of paperjam
After a few months of installing existing packages, I wanted to make a custom package with nix for a program called [paperjam][2] that wasnt already packaged.
I was actually struggling to compile `paperjam` at all even without nix because the version I had
of `libiconv` I has on my system was wrong. I thought it might be easier to
compile it with nix even though I didnt know how to make nix packages yet. And
it actually was!
But figuring out how to get there was VERY confusing, so here are some notes about how I did it.
#### how to build an example package
Before I started working on my `paperjam` package, I wanted to build an example existing package just to
make sure I understood the process for building a package. I was really
struggling to figure out how to do this, but I asked in Discord and someone
explained to me how I could get a working package from [https://github.com/NixOS/nixpkgs/][13] and build it. So here
are those instructions:
**step 1:** Download some arbitrary package from [nixpkgs][13] on github, for example the `dash` package:
```
wget https://raw.githubusercontent.com/NixOS/nixpkgs/47993510dcb7713a29591517cb6ce682cc40f0ca/pkgs/shells/dash/default.nix -O dash.nix
```
**step 2**: Replace the first statement (`{ lib , stdenv , buildPackages , autoreconfHook , pkg-config , fetchurl , fetchpatch , libedit , runCommand , dash }:` with `with import <nixpkgs> {};` I dont know why you have to do this,
but it works.
**step 3**: Run `nix-build dash.nix`
This compiles the package
**step 4**: Run `nix-env -i -f dash.nix`
This installs the package into my `~/.nix-profile`
Thats all! Once Id done that, I felt like I could modify the `dash` package and make my own package.
#### how I made my own package
`paperjam` has one dependency (`libpaper`) that also isnt packaged yet, so I needed to build `libpaper` first.
Heres `libpaper.nix`. I basically just wrote this by copying and pasting from
other packages in the [nixpkgs][13] repository.
My guess is whats happening here is that nix has some default rules for
compiling C packages (like “run `make install`”), so the `make install` happens
default and I dont need to configure it explicitly.
```
with import <nixpkgs> {};
stdenv.mkDerivation rec {
pname = "libpaper";
version = "0.1";
src = fetchFromGitHub {
owner = "naota";
repo = "libpaper";
rev = "51ca11ec543f2828672d15e4e77b92619b497ccd";
hash = "sha256-S1pzVQ/ceNsx0vGmzdDWw2TjPVLiRgzR4edFblWsekY=";
};
buildInputs = [ ];
meta = with lib; {
homepage = "https://github.com/naota/libpaper";
description = "libpaper";
platforms = platforms.unix;
license = with licenses; [ bsd3 gpl2 ];
};
}
```
Basically this just tells nix how to download the source from GitHub.
I built this by running `nix-build libpaper.nix`
Next, I needed to compile `paperjam`. Heres a link to the [nix package I wrote][16]. The main things I needed to do other than telling it where to download the source were:
- add some extra build dependencies (like `asciidoc`)
- set some environment variables for the install (`installFlags = [ "PREFIX=$(out)" ];`) so that it installed in the correct directory instead of `/usr/local/bin`.
I set the hashes by first leaving the hash empty, then running `nix-build` to get an error message complaining about a mismatched hash. Then I copied the correct hash out of the error message.
I figured out how to set `installFlags` just by running `rg PREFIX`
in the nixpkgs repository I figured that needing to set a `PREFIX` was
pretty common and someone had probably done it before, and I was right. So I
just copied and pasted that line from another package.
Then I ran:
```
nix-build paperjam.nix
nix-env -i -f paperjam.nix
```
and then everything worked and I had `paperjam` installed! Hooray!
#### next goal: install a 5-year-old version of hugo
Right now I build this blog using Hugo 0.40, from 2018. I dont need any new
features so I havent felt a need to upgrade. On Linux this is easy: Hugos
releases are a static binary, so I can just download the 5-year-old binary from
the [releases page][17] and
run it. Easy!
But on this Mac I ran into some complications. Mac hardware has changed in the
last 5 years, so the Mac Hugo binary I downloaded crashed. And when I tried to
build it from source with `go build`, that didnt work either because Go build
norms have changed in the last 5 years as well.
I was working around this by running Hugo in a Linux docker container, but I
didnt love that: it was kind of slow and it felt silly. It shouldnt be that
hard to compile one Go program!
Nix to the rescue! Heres what I did to install the old version of Hugo with
nix.
#### installing Hugo 0.40 with nix
I wanted to install Hugo 0.40 and put it in my PATH as `hugo-0.40`. Heres how
I did it. I did this in a kind of weird way, but it worked ([Searching and installing old versions of Nix packages][18]
describes a probably more normal method).
**step 1**: Search through the nixpkgs repo to find Hugo 0.40
I found the `.nix` file here [https://github.com/NixOS/nixpkgs/blob/17b2ef2/pkgs/applications/misc/hugo/default.nix][19]
**step 2**: Download that file and build it
I downloaded that file (and another file called `deps.nix` in the same directory), replaced the first line with `with import <nixpkgs> {};`, and built it with `nix-build hugo.nix`.
That almost worked without any changes, but I had to make two changes:
- replace `with stdenv.lib` to `with lib` for some reason.
- rename the package to `hugo040` so that it wouldnt conflict with the other version of `hugo` that I had installed
**step 3**: Rename `hugo` to `hugo-0.40`
I write a little post install script to rename the Hugo binary.
```
postInstall = ''
mv $out/bin/hugo $out/bin/hugo-0.40
'';
```
I figured out how to run this by running `rg 'mv '` in the nixpkgs repository and just copying and modifying something that seemed related.
**step 4**: Install it
I installed into my `~/.nix-profile/bin` by running `nix-env -i -f hugo.nix`.
And it all works! I put the final `.nix` file into my own personal [nixpkgs repo][20] so that I can use it again later if I
want.
#### reproducible builds arent magic, theyre really hard
I think its worth noting here that this `hugo.nix` file isnt magic the
reason I can easily compile Hugo 0.40 today is that many people worked for a long time to make it possible to
package that version of Hugo in a reproducible way.
#### thats all!
Installing `paperjam` and this 5-year-old version of Hugo were both
surprisingly painless and actually much easier than compiling it without nix,
because nix made it much easier for me to compile the `paperjam` package with
the right version of `libiconv`, and because someone 5 years ago had already
gone to the trouble of listing out the exact dependencies for Hugo.
I dont have any plans to get much more complicated with nix (and its still
very possible Ill get frustrated with it and go back to homebrew!), but well
see what happens! Ive found it much easier to start in a simple way and then
start using more features if I feel the need instead of adopting a whole bunch
of complicated stuff all at once.
I probably wont use nix on Linux Ive always been happy enough with `apt`
(on Debian-based distros) and `pacman` (on Arch-based distros), and theyre
much less confusing. But on a Mac it seems like it might be worth it. Well
see! Its very possible in 3 months Ill get frustrated with nix and just go back to homebrew.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/02/28/some-notes-on-using-nix/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://nixos.org/
[2]: https://mj.ucw.cz/sw/paperjam/
[3]: https://github.com/gohugoio/hugo/
[4]: https://cache.nixos.org/
[5]: https://nixos.org/download
[6]: https://zero-to-nix.com/concepts/nix-installer
[7]: https://nixos.org/manual/nix/stable/installation/installing-binary.html#macos
[8]: https://cache.nixos.org
[9]: https://nixos.org/guides/nix-pills/developing-with-nix-shell.html
[10]: https://nixos.wiki/wiki/Flakes
[11]: https://github.com/nix-community/home-manager
[12]: https://devenv.sh/
[13]: https://github.com/NixOS/nixpkgs/
[14]: https://search.nixos.org/packages
[15]: https://ianthehenry.com/posts/how-to-learn-nix/my-first-package-upgrade/
[16]: https://github.com/jvns/nixpkgs/blob/22b70a48a797538c76b04261b3043165896d8f69/paperjam.nix
[17]: https://github.com/gohugoio/hugo/releases/tag/v0.40
[18]: https://lazamar.github.io/download-specific-package-version-with-nix/
[19]: https://github.com/NixOS/nixpkgs/blob/17b2ef2/pkgs/applications/misc/hugo/default.nix
[20]: https://github.com/jvns/nixpkgs/

View File

@ -0,0 +1,504 @@
[#]: subject: "How do Nix builds work?"
[#]: via: "https://jvns.ca/blog/2023/03/03/how-do-nix-builds-work-/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How do Nix builds work?
======
Hello! For some reason after the last [nix post][1] I got nerdsniped by trying to understand how Nix builds
work under the hood, so heres a quick exploration I did today. There are probably some mistakes in here.
I started by [complaining on Mastodon][2]:
> are there any guides to nix that start from the bottom up (for example
> starting with [this bash script][3]
> and then working up the layers of abstraction) instead of from the top down?
>
> all of the guides Ive seen start by describing the nix programming language
> or other abstractions, and Id love to see a guide that starts with concepts I
> already understand like compiler flags, linker flags, Makefiles, environment
> variables, and bash scripts.
Ross Light wrote a great blog post in response called [Connecting Bash to Nix][4], that shows how to compile a basic C program without using most of Nixs standard machinery.
I wanted to take this a tiny bit further and compile a slightly more
complicated C program.
#### the goal: compile a C program, without using Nixs standard machinery
Our goal is to compile a C program called `paperjam`. This is a real C program
that wasnt in the Nix repository already. I already figured out how to
compile it in [this post][1] by copying and pasting a bunch of stuff I didnt understand, but this time I wanted to do
it in a more principled way where I actually understand more of the steps.
Were going to avoid using most of Nixs helpers for compiling C programs.
The plan is to start with an almost empty build script, and then resolve errors
until we have a working build.
#### first: whats a derivation?
I said that we werent going to talk about too many Nix abstractions (and we wont!), but understanding what a derivation is really helped me.
Everything I read about Nix talks about derivations all the time, but I was
really struggling to figure out what a derivation _is_. It turns out that `derivation`
is a function in the Nix language. But not just any function! The whole point of the Nix language seems to be to
to call this function. The [official documentation for the `derivation` function][5] is actually extremely clear. Heres what I took away:
`derivation` takes a bunch of keys and values as input. There are 3 required keys:
- `system`: the system, for example `x86_64-darwin`
- `name`: the name of the package youre building
- `builder`: a program (usually a bash script) that runs the build
Every other key is an arbitrary string that gets passed as an environment
variable to the `builder` shell script.
#### derivations automatically build all their inputs
A derivation doesnt just call a shell script though! Lets say I reference another derivation called `pkgs.qpdf` in my script.
Nix will:
- automatically build the `qpdf` package
- put the resulting output directory somewhere like `/nix/store/4garxzr1rpdfahf374i9p9fbxnx56519-qpdf-11.1.0`
- expand `pkgs.qpdf` into that output directory (as a string), so that I can reference it in my build script
The derivation function does some other things (described in the
[documentation][5]), but “it builds all of its inputs” is all we really need to know
for now.
#### step 1: write a derivation file
Lets write a very simple build script and call the `derivation` function. These dont work yet,
but I found it pretty fun to go through all the errors, fix them one at a time,
and learn a little more about how Nix works by fixing them.
Heres the build script (`build_paperjam.sh`). This just unpacks the tarball and runs `make install`.
```
#!/bin/bash
tar -xf "$SOURCE"
cd paperjam-1.2
make install
```
And heres the Nix code calling the `derivation` function (in `paperjam.nix`). This calls the core `derivation` function, without too much magic.
```
let pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/4d2b37a84fad1091b9de401eb450aae66f1a741e.tar.gz") {};
builtins.derivation {
name = "paperjam-fake";
builder = ./build-paperjam.sh;
system = builtins.currentSystem;
SOURCE = pkgs.fetchurl {
url = "https://mj.ucw.cz/download/linux/paperjam-1.2.tar.gz";
hash = "sha256-0AziT7ROICTEPKaA4Ub1B8NtIfLmxRXriW7coRxDpQ0";
};
}
```
The main things here are:
- `fetchurl` (which downloads an url and puts the path in to the `SOURCE` environment variable)
- `pkgs` (which lets us depend on other Nix packages from the central repository). I dont totally understand this but Im already in a pretty deep rabbit hole so were going to leave that for now.
`SOURCE` evaluates to a string its the path to the downloaded source tarball.
#### problem 1: tar: command not found
Nix needs you to declare all the dependencies for your builds. It forces this
by removing your `PATH` environment variable so that you have no binaries in
your PATH at all.
This is pretty easy to fix: we just need to edit our `PATH`.
I added this to `paperjam.nix` to get `tar`, `gzip`, and `make`:
```
PATH = "${pkgs.gzip}/bin:${pkgs.gnutar}/bin:${pkgs.gnumake}/bin";
```
#### problem 2: we need a compiler
Next, we had this error:
```
g++ -O2 -Wall -Wextra -Wno-parentheses -std=gnu++11 -g -DVERSION='"1.2"' -DYEAR='"2022"' -DBUILD_DATE='""' -DBUILD_COMMIT='""' -c -o paperjam.o paperjam.cc
make: g++: No such file or directory
```
So we need to put a compiler in our PATH. For some reason I felt like using `clang++` to compile, not `g++`. To do that I need to make 2 changes to `paperjam.nix`:
- Add the line `CXX="clang++";`
- Add `${pkgs.clang}/bin` to my `PATH`
#### problem 3: missing header files
The next error was:
```
> ./pdf-tools.h:13:10: fatal error: 'qpdf/QPDF.hh' file not found
> #include <qpdf/QPDF.hh>
```
Makes sense: everything is isolated, so it cant access my system header files.
Figuring out how to handle this was a little more confusing though.
It turns out that the way Nix handles header files is that it has a shell
script wrapper around `clang`. So when you run `clang++`, youre actually
running a shell script.
On my system, the `clang++` wrapper script was at `/nix/store/d929v59l9a3iakvjccqpfqckqa0vflyc-clang-wrapper-11.1.0/bin/clang++`. I searched that file for `LDFLAGS` and found that it uses 2 environment variables:
- `NIX_LDFLAGS_aarch64_apple_darwin`
- `NIX_CFLAGS_COMPILE_aarch64_apple_darwin`
So I figured I needed to put all the arguments to clang in the `NIX_CFLAGS` variable and all the linker arguments in `NIX_LDFLAGS`. Great! Lets do that.
I added these 2 lines to my `paperjam.nix`, to link the `libpaper` and `qpdf` libraries:
```
NIX_LDFLAGS_aarch64_apple_darwin = "-L ${pkgs.qpdf}/lib -L ${pkgs.libpaper}/lib";
NIX_CFLAGS_COMPILE_aarch64_apple_darwin = "-isystem ${pkgs.qpdf}/include -isystem ${pkgs.libpaper}/include";
```
And that worked!
#### problem 4: missing c++abi
The next error was:
```
> ld: library not found for -lc++abi
```
Not sure what this means, but I searched for “abi” in the Nix packages and fixed it by adding `-L ${pkgs.libcxxabi}/lib` to my `NIX_LDFLAGS` environment variable.
#### problem 5: missing iconv
Heres the next error:
```
> Undefined symbols for architecture arm64:
> "_iconv", referenced from: ...
```
I started by adding `-L ${pkgs.libiconv}/lib` to my `NIX_LDFLAGS` environment variable, but that didnt fix it. Then I spent a while going around in circles and being confused.
I eventually figured out how to fix this by taking a working version of the `paperjam` build that Id made before
and editing my `clang++` wrapper file to print out all of its environment
variables. The `LDFLAGS` environment variable in the working version was different from mine: it had `-liconv` in it.
So I added `-liconv` to `NIX_LDFLAGS` as well and that fixed it.
#### why doesnt the original Makefile have -liconv?
I was a bit puzzled by this `-liconv` thing though: the original Makefile links
in `libqpdf` and `libpaper` by passing `-lqpdf -lpaper`. So why doesnt it link in iconv, if it requires the
iconv library?
I think the reason for this is that the original Makefile assumed that you were
running on Linux and using glibc, and glibc includes these iconv functions by
default. But I guess Mac OS libc doesnt include iconv, so we need to
explicitly set the linker flag `-liconv` to add the iconv library.
#### problem 6: missing codesign_allocate
Time for the next error:
```
libc++abi: terminating with uncaught exception of type std::runtime_error: Failed to spawn codesign_allocate: No such file or directory
```
I guess this is some kind of Mac code signing thing. I used `find /nix/store -name codesign_allocate` to find `codesign_allocate` on my system. Its at
`/nix/store/a17dwfwqj5ry734zfv3k1f5n37s4wxns-cctools-binutils-darwin-973.0.1/bin/codesign_allocate`.
But this doesnt tell us what the package is called we need to be able to refer to it as `${pkgs.XXXXXXX}` and `${pkgs.cctools-binutils-darwin}` doesnt work.
I couldnt figure out a way go from a Nix folder to the name of the package, but I ended up poking around and finding out that it was called `pkgs.darwin.cctools`.
So I added `${pkgs.darwin.cctools}/bin` to the `PATH`.
#### problem 7: missing a2x
Easy, just add `${pkgs.asciidoc}/bin` to the `PATH`.
##### problem 8: missing install
```
make: install: No such file or directory
```
Apparently `install` is a program? This turns out to be in `coreutils`, so we add `${pkgs.coreutils}/bin` to the `PATH`. Adding `coreutils` also fixes some other warnings I was seeing about missing commands like `date`.
#### problem 9: cant create /usr/local/bin/paperjam
This took me a little while to figure out because Im not very familiar with make. The Makefile has a `PREFIX` of `/usr/local`, but we want it to be the programs output directory in `/nix/store/`
I edited the `build-paperjam.sh` shell script to say:
```
make install PREFIX="$out"
```
and everything worked! Hooray!
#### our final configuration
Heres the final `paperjam.nix`. Its not so different from what we started with we just added 4 environment variables.
```
let pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/ae8bdd2de4c23b239b5a771501641d2ef5e027d0.tar.gz") {};
in
builtins.derivation {
name = "paperjam-fake";
builder = ./build-paperjam.sh;
system = builtins.currentSystem;
SOURCE = pkgs.fetchurl {
url = "https://mj.ucw.cz/download/linux/paperjam-1.2.tar.gz";
hash = "sha256-0AziT7ROICTEPKaA4Ub1B8NtIfLmxRXriW7coRxDpQ0";
};
CXX="clang++";
PATH = "${pkgs.gzip}/bin:${pkgs.gnutar}/bin:${pkgs.gnumake}/bin:${pkgs.clang}/bin:${pkgs.darwin.cctools}/bin:${pkgs.asciidoc}/bin:${pkgs.coreutils}/bin:${pkgs.bash}/bin";
NIX_LDFLAGS_aarch64_apple_darwin = "-L ${pkgs.qpdf}/lib -L ${pkgs.libpaper}/lib -L ${pkgs.libcxxabi}/lib -liconv -L ${pkgs.libiconv}/lib ";
NIX_CFLAGS_COMPILE_aarch64_apple_darwin = "-isystem ${pkgs.qpdf}/include -isystem ${pkgs.libpaper}/include";
}
```
And heres the final `build-paperjam.sh` build script. Here we just needed to edit the `make install` line to set the `PREFIX`.
```
#!/bin/bash
tar -xf "$SOURCE"
cd paperjam-1.2
make install PREFIX="$out"
```
#### lets look at our compiled derivation!
Now that we understand this configuration a little better, lets talk about
what `nix-build` is doing a little more.
Behind the scenes, `nix-build paperjam.nix` actually runs `nix-instantiate` and `nix-store --realize`:
```
$ nix-instantiate paperjam.nix
/nix/store/xp8kibpll55s0bm40wlpip51y7wnpfs0-paperjam-fake.drv
$ nix-store --realize /nix/store/xp8kibpll55s0bm40wlpip51y7wnpfs0-paperjam-fake.drv
```
I think what this means is that `paperjam.nix` get compiled to some
intermediate representation (also called a derivation?), and then the Nix
runtime takes over and is in charge of actually running the build scripts.
We can look at this `.drv` intermediate representation with `nix show-derivation`
```
{
"/nix/store/xp8kibpll55s0bm40wlpip51y7wnpfs0-paperjam-fake.drv": {
"outputs": { "out": { "path": "/nix/store/bcnyqizvcysqc1vy382wfx015mmwn3bd-paperjam-fake" }
},
"inputSrcs": [ "/nix/store/pbjj91f0qr8g14k58m744wdl9yvr2f5k-build-paperjam.sh" ],
"inputDrvs": {
"/nix/store/38sikqcggyishxbgi2xnyrdsnq928gqx-asciidoc-10.2.0.drv": [ "out" ],
"/nix/store/3llc749f9pn0amlb9vgwsi22hin7kmz4-libcxxabi-11.1.0.drv": [ "out" ],
"/nix/store/a8ny8lrbpyn15wdxk3v89f4bdr08a38a-libpaper-1.1.28.drv": [ "out" ],
"/nix/store/d888pj9lll12s5qx11v850g1vd4h3vxq-cctools-port-973.0.1.drv": [ "out" ],
"/nix/store/gkpdv7xl39x9yxch0wjarq19mmv7j1pm-bash-5.2-p15.drv": [ "out" ],
"/nix/store/hwx16m7hmkp2rcik8h67nnyjp52zj849-gnutar-1.34.drv": [ "out" ],
"/nix/store/kqqwffajj24fmagxqps3bjcbrglbdryg-gzip-1.12.drv": [ "out" ],
"/nix/store/lnrxa45bza18dk8qgqjayqb65ilfvq2n-qpdf-11.2.0.drv": [ "out" ],
"/nix/store/rx7a5401h44dqsasl5g80fl25jqqih8r-gnumake-4.4.drv": [ "out" ],
"/nix/store/sx8blaza5822y51abdp3353xkdcbkpkb-coreutils-9.1.drv": [ "out" ],
"/nix/store/v3b7r7a8ipbyg9wifcqisf5vpy0c66cs-clang-wrapper-11.1.0.drv": [ "out" ],
"/nix/store/wglagz34w1jnhr4xrfdk0g2jghbk104z-paperjam-1.2.tar.gz.drv": [ "out" ],
"/nix/store/y9mb7lgqiy38fbi53m5564bx8pl1arkj-libiconv-50.drv": [ "out" ]
},
"system": "aarch64-darwin",
"builder": "/nix/store/pbjj91f0qr8g14k58m744wdl9yvr2f5k-build-paperjam.sh",
"args": [],
"env": {
"CXX": "clang++",
"NIX_CFLAGS_COMPILE_aarch64_apple_darwin": "-isystem /nix/store/h25d99pd3zln95viaybdfynfq82r2dqy-qpdf-11.2.0/include -isystem /nix/store/agxp1hx267qk1x79dl4jk1l5cg79izv1-libpaper-1.1.28/include",
"NIX_LDFLAGS_aarch64_apple_darwin": "-L /nix/store/h25d99pd3zln95viaybdfynfq82r2dqy-qpdf-11.2.0/lib -L /nix/store/agxp1hx267qk1x79dl4jk1l5cg79izv1-libpaper-1.1.28/lib -L /nix/store/awkb9g93ci2qy8yg5jl0zxw46f3xnvgv-libcxxabi-11.1.0/lib -liconv -L /nix/store/nmphpbjn8hhq7brwi9bw41m7l05i636h-libiconv-50/lib ",
"PATH": "/nix/store/90cqrp3nxbcihkx4vswj5wh85x5klaga-gzip-1.12/bin:/nix/store/siv9312sgiqwsjrdvj8lx0mr3dsj3nf5-gnutar-1.34/bin:/nix/store/yy3fdgrshcblwx0cfp76nmmi24szw89q-gnumake-4.4/bin:/nix/store/cqag9fv2gia03nzcsaygan8fw1ggdf4g-clang-wrapper-11.1.0/bin:/nix/store/f16id36r9xxi50mgra55p7cf7ra0x96k-cctools-port-973.0.1/bin:/nix/store/x873pgpwqxkmyn35jvvfj48ccqav7fip-asciidoc-10.2.0/bin:/nix/store/vhivi799z583h2kf1b8lrr72h4h3vfcx-coreutils-9.1/bin:/nix/store/0q1jfjlwr4vig9cz7lnb5il9rg0y1n84-bash-5.2-p15/bin",
"SOURCE": "/nix/store/6d2fcw88d9by4fz5xa9gdpbln73dlhdk-paperjam-1.2.tar.gz",
"builder": "/nix/store/pbjj91f0qr8g14k58m744wdl9yvr2f5k-build-paperjam.sh",
"name": "paperjam-fake",
"out": "/nix/store/bcnyqizvcysqc1vy382wfx015mmwn3bd-paperjam-fake",
"system": "aarch64-darwin"
}
}
}
```
This feels surprisingly easy to understand you can see that there are a
bunch of environment variables, our bash script, and the paths to our inputs.
#### the compilation helpers were not using: stdenv
Normally when you build a package with Nix, you dont do all of this stuff
yourself. Instead, you use a helper called `stdenv`, which seems to have two parts:
- a function called `stdenv.mkDerivation` which takes some arguments and generates a bunch of environment variables (it seems to be [documented here][6])
- a 1600-line bash build script ([setup.sh][7]) that consumes those environment variables. This is like our `build-paperjam.sh`, but much more generalized.
Together, these two tools:
- add `LDFLAGS` automatically for each C library you depend on
- add `CFLAGS` automatically so that you can get your header files
- run `make`
- depend on clang and coreutils and bash and other core utilities so that you dont need to add them yourself
- set `system` to your current system
- let you easily add custom bash code to run at various phases of your build
- maybe also manage versions somehow? Not sure about this one.
and probably lots more useful things I dont know about yet
#### lets look at the derivation for jq
Lets look at one more compiled derivation, for `jq`. This is quite long but there
are some interesting things in here. I wanted to look at this because I wanted to see what a more typical derivation generated by `stdenv.mkDerivation` looked like.
```
$ nix show-derivation /nix/store/q9cw5rp0ibpl6h4i2qaq0vdjn4pyms3p-jq-1.6.drv
{
"/nix/store/q9cw5rp0ibpl6h4i2qaq0vdjn4pyms3p-jq-1.6.drv": {
"outputs": {
"bin": { "path": "/nix/store/vabn35a2m2qmfi9cbym4z50bwq94fdzm-jq-1.6-bin" },
"dev": { "path": "/nix/store/akda158i8gr0v0w397lwanxns8yrqldy-jq-1.6-dev" },
"doc": { "path": "/nix/store/6qimafz8q88l90jwrzciwc27zhjwawcl-jq-1.6-doc" },
"lib": { "path": "/nix/store/3wzlsin34l1cs70ljdy69q9296jnvnas-jq-1.6-lib" },
"man": { "path": "/nix/store/dl1xf9w928jai5hvm5s9ds35l0m26m0k-jq-1.6-man" },
"out": { "path": "/nix/store/ivzm5rrr7riwvgy2xcjhss6lz55qylnb-jq-1.6" }
},
"inputSrcs": [
"/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh",
"/nix/store/jd98q1h1rxz5iqd5xs8k8gw9zw941lj6-fix-tests-when-building-without-regex-supports.patch"
],
"inputDrvs": {
"/nix/store/0lbzkxz56yhn4gv5z0sskzzdlwzkcff8-autoreconf-hook.drv": [ "out" ],
"/nix/store/6wh5w7hkarfcx6fxsdclmlx097xsimmg-jq-1.6.tar.gz.drv": [ "out" ],
"/nix/store/87a32xgqw85rxr1fx3c5j86y177hr9sr-oniguruma-6.9.8.drv": [ "dev" ],
"/nix/store/gkpdv7xl39x9yxch0wjarq19mmv7j1pm-bash-5.2-p15.drv": [ "out" ],
"/nix/store/xn1mjk78ly9wia23yvnsyw35q1mz4jqh-stdenv-darwin.drv": [ "out" ]
},
"system": "aarch64-darwin",
"builder": "/nix/store/0q1jfjlwr4vig9cz7lnb5il9rg0y1n84-bash-5.2-p15/bin/bash",
"args": [
"-e",
"/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh"
],
"env": {
"__darwinAllowLocalNetworking": "",
"__impureHostDeps": "/bin/sh /usr/lib/libSystem.B.dylib /usr/lib/system/libunc.dylib /dev/zero /dev/random /dev/urandom /bin/sh",
"__propagatedImpureHostDeps": "",
"__propagatedSandboxProfile": "",
"__sandboxProfile": "",
"__structuredAttrs": "",
"bin": "/nix/store/vabn35a2m2qmfi9cbym4z50bwq94fdzm-jq-1.6-bin",
"buildInputs": "/nix/store/xfnl6xqbvnpacx8hw9d99ca4mly9kp0h-oniguruma-6.9.8-dev",
"builder": "/nix/store/0q1jfjlwr4vig9cz7lnb5il9rg0y1n84-bash-5.2-p15/bin/bash",
"cmakeFlags": "",
"configureFlags": "--bindir=${bin}/bin --sbindir=${bin}/bin --datadir=${doc}/share --mandir=${man}/share/man",
"depsBuildBuild": "",
"depsBuildBuildPropagated": "",
"depsBuildTarget": "",
"depsBuildTargetPropagated": "",
"depsHostHost": "",
"depsHostHostPropagated": "",
"depsTargetTarget": "",
"depsTargetTargetPropagated": "",
"dev": "/nix/store/akda158i8gr0v0w397lwanxns8yrqldy-jq-1.6-dev",
"doCheck": "",
"doInstallCheck": "1",
"doc": "/nix/store/6qimafz8q88l90jwrzciwc27zhjwawcl-jq-1.6-doc",
"installCheckTarget": "check",
"lib": "/nix/store/3wzlsin34l1cs70ljdy69q9296jnvnas-jq-1.6-lib",
"man": "/nix/store/dl1xf9w928jai5hvm5s9ds35l0m26m0k-jq-1.6-man",
"mesonFlags": "",
"name": "jq-1.6",
"nativeBuildInputs": "/nix/store/ni9k35b9llfc3hys8nv5qsipw8pfy1ln-autoreconf-hook",
"out": "/nix/store/ivzm5rrr7riwvgy2xcjhss6lz55qylnb-jq-1.6",
"outputs": "bin doc man dev lib out",
"patches": "/nix/store/jd98q1h1rxz5iqd5xs8k8gw9zw941lj6-fix-tests-when-building-without-regex-supports.patch",
"pname": "jq",
"postInstallCheck": "$bin/bin/jq --help >/dev/null\n$bin/bin/jq -r '.values[1]' <<< '{\"values\":[\"hello\",\"world\"]}' | grep '^world$' > /dev/null\n",
"preBuild": "rm -r ./modules/oniguruma\n",
"preConfigure": "echo \"#!/bin/sh\" > scripts/version\necho \"echo 1.6\" >> scripts/version\npatchShebangs scripts/version\n",
"propagatedBuildInputs": "",
"propagatedNativeBuildInputs": "",
"src": "/nix/store/ggjlgjx2fw29lngbnvwaqr6hiz1qhy8g-jq-1.6.tar.gz",
"stdenv": "/nix/store/qrz2mnb2gsnzmw2pqax693daxh5hsgap-stdenv-darwin",
"strictDeps": "",
"system": "aarch64-darwin",
"version": "1.6"
}
}
}
```
I thought it was interesting that some of the environment variables in here are actually bash scripts themselves for example the `postInstallCheck` environment variable is a bash script.
Those bash script environment variables are `eval`ed in the main bash script (you can [see that happening in setup.sh here][8])
The `postInstallCheck` environment variable in this particular derivation starts like this:
```
$bin/bin/jq --help >/dev/null
$bin/bin/jq -r '.values[1]' <<< '{"values":["hello","world"]}' | grep '^world$' > /dev/null
```
I guess this is a test to make sure that `jq` installed correctly.
#### finally: clean up
All of my compiler experiments used about 3GB of disk space, but `nix-collect-garbage` cleaned up all of it.
#### lets recap the process!
I feel like I understand Nix a bit better after going through this. I still
dont feel very motivated to learn the Nix language, but now I have some
idea of what Nix programs are actually doing under the hood!
My understanding is:
- First, `.nix` files get compiled into a `.drv` file, which is mostly a bunch of inputs and outputs and environment variables. This is where the Nix language stops being relevant.
- Then all the environment variables get passed to a build script, which is in charge of doing the actual build
- In the Nix standard environment (`stdenv`), some of those environment variables are themselves bash code, which gets `eval`ed by the big build script `setup.sh`
Thats all! I probably made some mistakes in here, but this was kind of a fun rabbit hole.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/03/03/how-do-nix-builds-work-/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://jvns.ca/blog/2023/02/28/some-notes-on-using-nix/
[2]: https://social.jvns.ca/@b0rk/109954253779465018
[3]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh
[4]: https://www.zombiezen.com/blog/2023/03/connecting-bash-to-nix/
[5]: https://nixos.org/manual/nix/stable/language/derivations.html
[6]: https://nixos.org/manual/nixpkgs/stable/#chap-stdenv
[7]: https://github.com/NixOS/nixpkgs/blob/fc2bfe1cdc910104e6df52c5dc449e8f855c66b7/pkgs/stdenv/generic/setup.sh
[8]: https://github.com/NixOS/nixpkgs/blob/fc2bfe1cdc910104e6df52c5dc449e8f855c66b7/pkgs/stdenv/generic/setup.sh#L61-L74

View File

@ -0,0 +1,312 @@
[#]: subject: "Some possible reasons for 8-bit bytes"
[#]: via: "https://jvns.ca/blog/2023/03/06/possible-reasons-8-bit-bytes/"
[#]: author: "Julia Evans https://jvns.ca/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Some possible reasons for 8-bit bytes
======
Ive been working on a zine about how computers represent thing in binary, and
one question Ive gotten a few times is why does the x86 architecture use 8-bit bytes? Why not
some other size?
With any question like this, I think there are two options:
- Its a historical accident, another size (like 4 or 6 or 16 bits) would work just as well
- 8 bits is objectively the Best Option for some reason, even if history had played out differently we would still use 8-bit bytes
- some mix of 1 & 2
Im not super into computer history (I like to use computers a lot more than I
like reading about them), but I am always curious if theres an essential
reason for why a computer thing is the way it is today, or whether its mostly
a historical accident. So were going to talk about some computer history.
As an example of a historical accident: DNS has a `class` field which has 5
possible values (“internet”, “chaos”, “hesiod”, “none”, and “any”). To me thats
a clear example of a historical accident I cant imagine that wed define
the class field the same way if we could redesign DNS today without worrying about backwards compatibility. Im
not sure if wed use a class field at all!
There arent any definitive answers in this post, but I asked [on Mastodon][1] and
here are some potential reasons I found for the 8-bit byte. I think the answer
is some combination of these reasons.
#### whats the difference between a byte and a word?
First, this post talks about “bytes” and “words” a lot. Whats the difference between a byte and a word? My understanding is:
- the **byte size** is the smallest unit you can address. For example in a program on my machine `0x20aa87c68` might be the address of one byte, then `0x20aa87c69` is the address of the next byte.
- The **word size** is some multiple of the byte size. Ive been confused about
this for years, and the Wikipedia definition is incredibly vague (“a word is
the natural unit of data used by a particular processor design”). I
originally thought that the word size was the same as your register size (64
bits on x86-64). But according to section 4.1 (“Fundamental Data Types”) of the [Intel architecture manual][2],
on x86 a word is 16 bits even though the registers are 64 bits. So Im
confused is a word on x86 16 bits or 64 bits? Can it mean both, depending
on the context? Whats the deal?
Now lets talk about some possible reasons that we use 8-bit bytes!
#### reason 1: to fit the English alphabet in 1 byte
[This Wikipedia article][3] says that the IBM System/360 introduced the 8-bit byte in 1964.
Heres a [video interview with Fred Brooks (who managed the project)][4] talking about why. Ive transcribed some of it here:
> … the six bit bytes [are] really better for scientific computing and the 8-bit byte ones are really better for commercial computing and each one can be made to work for the other.
> So it came down to an executive decision and I decided for the 8-bit byte, Jerrys proposal.
>
> ...
>
> My most important technical decision in my IBM career was to go with the 8-bit byte for the 360.
> And on the basis of I believe character processing was going to become important as opposed to decimal digits.
It makes sense that an 8-bit byte would be better for text processing: 2^6 is
64, so 6 bits wouldnt be enough for lowercase letters, uppercase letters, and symbols.
To go with the 8-bit byte, System/360 also introduced the [EBCDIC][5] encoding, which is an 8-bit character encoding.
It looks like the next important machine in 8-bit-byte history was the
[Intel 8008][6], which was built to be
used in a computer terminal (the Datapoint 2200). Terminals need to be able to
represent letters as well as terminal control codes, so it makes sense for them
to use an 8-bit byte.
[This Datapoint 2200 manual from the Computer History Museum][7]
says on page 7 that the Datapoint 2200 supported ASCII (7 bit) and EBCDIC (8 bit).
#### why was the 6-bit byte better for scientific computing?
I was curious about this comment that the 6-bit byte would be better for scientific computing. Heres a quote from [this interview from Gene Amdahl][8]:
> I wanted to make it 24 and 48 instead of 32 and 64, on the basis that this
> would have given me a more rational floating point system, because in floating
> point, with the 32-bit word, you had to keep the exponent to just 8 bits for
> exponent sign, and to make that reasonable in terms of numeric range it could
> span, you had to adjust by 4 bits instead of by a single bit. And so it caused
> you to lose some of the information more rapidly than you would with binary
> shifting
I dont understand this comment at all why does the exponent have to be 8 bits
if you use a 32-bit word size? Why couldnt you use 9 bits or 10 bits if you
wanted? But its all I could find in a quick search.
#### why did mainframes use 36 bits?
Also related to the 6-bit byte: a lot of mainframes used a 36-bit word size. Why? Someone pointed out
that theres a great explanation in the Wikipedia article on [36-bit computing][9]:
> Prior to the introduction of computers, the state of the art in precision
> scientific and engineering calculation was the ten-digit, electrically powered,
> mechanical calculator… These calculators had a column of keys for each digit,
> and operators were trained to use all their fingers when entering numbers, so
> while some specialized calculators had more columns, ten was a practical limit.
>
> Early binary computers aimed at the same market therefore often used a 36-bit
> word length. This was long enough to represent positive and negative integers
> to an accuracy of ten decimal digits (35 bits would have been the minimum)
So this 36 bit thing seems to based on the fact that log_2(20000000000) is 34.2. Huh.
My guess is that the reason for this is in the 50s, computers were
extremely expensive. So if you wanted your computer to support ten decimal
digits, youd design so that it had exactly enough bits to do that, and no
more.
Today computers are way faster and cheaper, so if you want to represent ten
decimal digits for some reason you can just use 64 bits wasting a little bit
of space is usually no big deal.
Someone else mentioned that some of these machines with 36-bit word sizes let
you choose a byte size you could use 5 or 6 or 7 or 8-bit bytes, depending
on the context.
#### reason 2: to work well with binary-coded decimal
In the 60s, there was a popular integer encoding called binary-coded decimal (or [BCD][10] for short) that
encoded every decimal digit in 4 bits.
For example, if you wanted to encode the number 1234, in BCD that would be something like:
```
0001 0010 0011 0100
```
So if you want to be able to easily work with binary-coded decimal, your byte
size should be a multiple of 4 bits, like 8 bits!
#### why was BCD popular?
This integer representation seemed really weird to me why not just use
binary, which is a much more efficient way to store integers? Efficiency was really important in early computers!
My best guess about why is that early computers didnt have displays the same way we do
now, so the contents of a byte were mapped directly to on/off lights.
Heres a [picture from Wikipedia of an IBM 650 with some lights on its display][11] ([CC BY-SA 3.0][12]):
![][13]
So if you want people to be relatively able to easily read off a decimal number
from its binary representation, this makes a lot more sense. I think today BCD
is obsolete because we have displays and our computers can convert numbers
represented in binary to decimal for us and display them.
Also, I wonder if BCD is where the term “nibble” for 4 bits comes from in
the context of BCD, you end up referring to half bytes a lot (because every
digits is 4 bits). So it makes sense to have a word for “4 bits”, and people
called 4 bits a nibble. Today “nibble” feels to me like an archaic term though
Ive definitely never used it except as a fun fact (its such a fun word!). The Wikipedia article on [nibbles][14] supports this theory:
> The nibble is used to describe the amount of memory used to store a digit of
> a number stored in packed decimal format (BCD) within an IBM mainframe.
Another reason someone mentioned for BCD was **financial calculations**. Today
if you want to store a dollar amount, youll typically just use an integer
amount of cents, and then divide by 100 if you want the dollar part. This is no
big deal, division is fast. But apparently in the 70s dividing an integer
represented in binary by 100 was very slow, so it was worth it to redesign how
you represent your integers to avoid having to divide by 100.
Okay, enough about BCD.
#### reason 3: 8 is a power of 2?
A bunch of people said its important for a CPUs byte size to be a power of 2.
I cant figure out whether this is true or not though, and I wasnt satisfied with the explanation that “computers use binary so powers of 2 are good”. That seems very plausible but I wanted to dig deeper.
And historically there have definitely been lots of machines that used byte sizes that werent powers of 2, for example (from [this retro computing stack exchange thread][15]):
- Cyber 180 mainframes used 6-bit bytes
- the Univac 1100 / 2200 series used a 36-bit word size
- the PDP-8 was a 12-bit machine
Some reasons I heard for why powers of 2 are good that I havent understood yet:
- every bit in a word needs a bus, and you want the number of buses to be a power of 2 (why?)
- a lot of circuit logic is susceptible to divide-and-conquer techniques (I think I need an example to understand this)
Reasons that made more sense to me:
- it makes it easier to design **clock dividers** that can measure “8 bits were
sent on this wire” that work based on halving you can put 3 halving clock
dividers in series. [Graham Sutherland][16] told me about this and made this really cool
[simulator of clock dividers][17] showing what these clock dividers look like. That site (Falstad) also has a bunch of other example circuits and it seems like a really cool way to make circuit simulators.
- if you have an instruction that zeroes out a specific bit in a byte, then if
your byte size is 8 (2^3), you can use just 3 bits of your instruction to
indicate which bit. x86 doesnt seem to do this, but the [Z80s bit testing instructions][18] do.
- someone mentioned that some processors use [Carry-lookahead adders][19], and they work
in groups of 4 bits. From some quick Googling it seems like there are a wide
variety of adder circuits out there though.
- **bitmaps**: Your computers memory is organized into pages (usually of size 2^n). It
needs to keep track of whether every page is free or not. Operating systems
use a bitmap to do this, where each bit corresponds to a page and is 0 or 1
depending on whether the page is free. If you had a 9-bit byte, you would
need to divide by 9 to find the page youre looking for in the bitmap.
Dividing by 9 is slower than dividing by 8, because dividing by powers of 2
is always the fastest thing.
I probably mangled some of those explanations pretty badly: Im pretty far out
of my comfort zone here. Lets move on.
#### reason 4: small byte sizes are good
You might be wondering well, if 8-bit bytes were better than 4-bit bytes,
why not keep increasing the byte size? We could have 16-bit bytes!
A couple of reasons to keep byte sizes small:
- Its a waste of space a byte is the minimum unit you can address, and if
your computer is storing a lot of ASCII text (which only needs 7 bits), it
would be a pretty big waste to dedicate 12 or 16 bits to each character when
you could use 8 bits instead.
- As bytes get bigger, your CPU needs to get more complex. For example you need one bus line per bit. So I guess simpler is better.
My understanding of CPU architecture is extremely shaky so Ill leave it at
that. The “its a waste of space” reason feels pretty compelling to me though.
#### reason 5: compatibility
The Intel 8008 (from 1972) was the precursor to the 8080 (from 1974), which was the precursor to the
8086 (from 1976) the first x86 processor. It seems like the 8080 and the
8086 were really popular and thats where we get our modern x86 computers.
I think theres an “if it aint broke dont fix it” thing going on here I
assume that 8-bit bytes were working well, so Intel saw no need to change the
design. If you keep the same 8-bit byte, then you can reuse more of your
instruction set.
Also around the 80s we start getting network protocols like TCP
which use 8-bit bytes (usually called “octets”), and if youre going to be
implementing network protocols, you probably want to be using an 8-bit byte.
#### thats all!
It seems to me like the main reasons for the 8-bit byte are:
- a lot of early computer companies were American, the most commonly used language in the US is English
- those people wanted computers to be good at text processing
- smaller byte sizes are in general better
- 7 bits is the smallest size you can fit all English characters + punctuation in
- 8 is a better number than 7 (because its a power of 2)
- once you have popular 8-bit computers that are working well, you want to keep the same design for compatibility
Someone pointed out that [page 65 of this book from 1962][20]
talking about IBMs reasons to choose an 8-bit byte basically says the same thing:
- Its full capacity of 256 characters was considered to be sufficient for the great majority of applications.
- Within the limits of this capacity, a single character is represented by a
single byte, so that the length of any particular record is not dependent on
the coincidence of characters in that record.
- 8-bit bytes are reasonably economical of storage space
- For purely numerical work, a decimal digit can be represented by only 4
bits, and two such 4-bit bytes can be packed in an 8-bit byte. Although such
packing of numerical data is not essential, it is a common practice in
order to increase speed and storage efficiency. Strictly speaking, 4-bit
bytes belong to a different code, but the simplicity of the 4-and-8-bit
scheme, as compared with a combination 4-and-6-bit scheme, for example,
leads to simpler machine design and cleaner addressing logic.
- Byte sizes of 4 and 8 bits, being powers of 2, permit the computer designer
to take advantage of powerful features of binary addressing and indexing to
the bit level (see Chaps. 4 and 5 ) .
>
Overall this makes me feel like an 8-bit byte is a pretty natural choice if
youre designing a binary computer in an English-speaking country.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2023/03/06/possible-reasons-8-bit-bytes/
作者:[Julia Evans][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lkxed/
[1]: https://social.jvns.ca/@b0rk/109976810279702728
[2]: https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
[3]: https://en.wikipedia.org/wiki/IBM_System/360
[4]: https://www.youtube.com/watch?v=9oOCrAePJMs&t=140s
[5]: https://en.wikipedia.org/wiki/EBCDIC
[6]: https://en.wikipedia.org/wiki/Intel_8008
[7]: https://archive.computerhistory.org/resources/text/2009/102683240.05.02.acc.pdf
[8]: https://archive.computerhistory.org/resources/access/text/2013/05/102702492-05-01-acc.pdf
[9]: https://en.wikipedia.org/wiki/36-bit_computing
[10]: https://en.wikipedia.org/wiki/Binary-coded_decimal
[11]: https://commons.wikimedia.org/wiki/File:IBM-650-panel.jpg
[12]: http://creativecommons.org/licenses/by-sa/3.0/
[13]: https://upload.wikimedia.org/wikipedia/commons/a/ad/IBM-650-panel.jpg
[14]: https://en.wikipedia.org/wiki/Nibble
[15]: https://retrocomputing.stackexchange.com/questions/7937/last-computer-not-to-use-octets-8-bit-bytes
[16]: https://poly.nomial.co.uk/
[17]: https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACgwEknsUQ08tQQKgU2AdxA8+I6eAyEoEqb3mK8VMAqWSNakHsx9Iywxj6Ea-c0oBKUy-xpUWYGc-D9kcftCQo-URgEZRQERSMnKkiTSTDFLQjw62NlMBorRP5krNjwDP58fMztE04kdKsRFBQqoqoQyUcRVhl6tLdCwVaonXBO2s0Cwb6UPGEPXmiPPLHhIrne2Y9q8a6lcpAp9edo+r7tkW3c5WPtOj4TyQv9G5jlO5saMAibPOeIoppm9oAPEEU2C0-EBaFoThAAHoUGx-mA8FYgfNESgIFUrNDYVtCBBttg8LiUPR0VCYWhyD0Wp0slYACIASQAamTIORFqtuucQAzGTQ2OTaD9BN8Soo6Uy8PzWQ46oImI4aSB6QA5ZTy9EuVQjPLq3q6kQmAD21Beome0qQMHgkDIhHCYVEfCQ9BVbGNRHAiio5vIltg8Ft9stXg99B5MPdFK9tDAFqg-rggcIDui1i23KZfPd3WjPuoVoDCiDjv4gjDErYQA
[18]: http://www.chebucto.ns.ca/~af380/z-80-h.htm
[19]: https://en.wikipedia.org/wiki/Carry-lookahead_adder
[20]: https://web.archive.org/web/20170403014651/http://archive.computerhistory.org/resources/text/IBM/Stretch/pdfs/Buchholz_102636426.pdf

View File

@ -1,348 +0,0 @@
[#]: subject: "NixOS Series #4: Things To Do After Installing NixOS"
[#]: via: "https://itsfoss.com/things-to-do-after-installing-nixos/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
NixOS Series #4: Things To Do After Installing NixOS
======
After installation, you will notice that NixOS is quite different from general-purpose Linux distributions.
Of course, as one of the [advanced Linux distributions][1], it may not feel right at home to most new users.
If you do not know [why you should use NixOS][2], and trying it out of curiosity, it is vital to know who it is for before proceeding.
While I assume you installed the distro already, if it is your first time, I suggest [installing NixOS on a virtual machine][3].
### 1. Update packages
Updates would always be there even if you used the latest ISO for the installation. So why not start by updating the packages?
To upgrade packages, first, you will have to check for updates in added channels:
```
nix-channel --update
```
And then, use the following command to install those updates (if any):
```
sudo nixos-rebuild switch --upgrade
```
That's it! It will take care of the rest.
### 2. Change hostname in NixOS
If you try the traditional way of [changing the hostname][4] (using the `hostnamectl` command), it will throw the following error:
![error changing hostname in nixos][5]
With NixOS, you can change the hostname easily using its main config file, which you can access using the following command:
```
sudo nano /etc/nixos/configuration.nix
```
In this config file, look for the following line:
```
networking.hostName = "nixos";
```
And change it to:
```
networking.hostName = "Your_Hostname";
```
For example, I changed my hostname to `itsFOSS`:
```
networking.hostName = "itsFOSS";
```
![change hostname in NixOS][6]
Now, [save changes and exit from the nano][7] text editor.
To take effect from the change you made to hostname, execute the following command:
```
sudo nixos-rebuild switch
```
And finally, reopen the terminal, and the change in hostname should reflect.
### 3. Setup Flatpak
I know what you might be thinking. The Nix package manager already offers a plethora of packages. So, why do you need Flatpak?
Installing what you need could be a bit time-consuming for first-time users. So, Flatpak should make things convenient for you.
[Setting up Flatpak][8] is not the same as you do on Ubuntu.
To setup Flatpak, you will have to make changes to the `configuration.nix` file, which can be accessed using the following:
```
sudo nano /etc/nixos/configuration.nix
```
[Go to the end of the line in nano][9] and add the following line before the `}`:
```
services.flatpak.enable = true;
```
![setup flatpak on nixos][10]
Save changes by pressing `Ctrl + O`, hit enter and exit by `Ctrl + X`.
Next, rebuild and switch to the new config file using the following command:
```
sudo nixos-rebuild switch
```
And finally, add the Flathub repository to the system using the following command:
```
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
```
Want to know what exactly is a Flatpak package? You can refer to our article on it:
### 4. Enable garbage collection
NixOS is known for being immutable, and there is a strong reason why.
Whenever you upgrade a package, the old package won't be removed. Just the symlinks of the old package will be given to the latest version.
And doing that, you will collect unnecessary trash from your system.
But removing every old generation will falsify the purpose of NixOS.
So, in that case, you can configure your system to remove garbage packages weekly.
To do that, first, open the nix configuration file:
```
sudo nano /etc/nixos/configuration.nix
```
And add the following line at the end of the config file before `}`:
```
# Automatic Garbage Collection
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 7d";
};
```
![enable automatic garbage collection in NixOS][11]
Save changes and exit from the nano text editor.
To activate the garbage collection, rebuild and switch to the new config file:
```
sudo nixos-rebuild switch
```
If you are not sure whether the garbage collector is running fine in the background, you can list active timers using the following command:
```
systemctl list-timers
```
![][12]
And as you can see, the Nix garbage collector is running as expected and shows 5 days left for the next cleanup.
### 5. Install your favorite software
I mean this is the only reason why we use computers. "To use our favorite software," and if there's none, we make it happen!
The best place to look for packages is the [Nix package search][13] which can be accessed using any of your preferred browsers.
- Search package
- Select the package
- Click on `nix-env` and copy the given command for `NixOS`
- Execute that command, and that's it
You can check our [NixOS package management][14] guide to get all the details.
Let me give you a quick recap here. For example, here, I want to install Librewolf, so I went with the following:
![search packages for nixos][15]
**But if you want to install services like SSH or plex, the above method won't work**.
For that, you will have to look into `NixOS options` situated at the top of the page.
So let's say I want to install OpenSSH, so I have to follow the given steps:
- Go to `NixOS options`
- Search the name of the service
- Get the name of the service and paste it to the `configuration.nix` by changing its value to `true`
![Search the service for nixos][16]
```
services.openssh.enable = true
```
![enable openssh on nixos][17]
After adding the line to the config file, rebuild the service:
```
sudo nixos-rebuild switch
```
### 6. Enable auto-update in NixOS (optional)
Some users prefer to have auto-updates enabled, whereas others can update packages at their convenience.
So it is all up to you.
**To enable auto-update**, first open the `configuration.nix` file:
```
sudo nano /etc/nixos/configuration.nix
```
Next, add the following line at the end of the config file before `}`:
```
# Auto system update
system.autoUpgrade = {
enable = true;
};
```
![enable auto system update in nixos][18]
Save changes and exit from the nano.
To enable the auto-update, you will have to rebuild and switch to that file using the following:
```
sudo nixos-rebuild switch
```
You can also check the NixOS upgrade timer using the following command:
```
systemctl list-timers
```
![auto upgrade timer in nixos][19]
And as you can see, the `nixos-upgrade.service` is running in the background as intended!
### 7. Reduce swapiness
If you are utilizing the swap partition, you may want to reduce the swapiness value.
Swapiness is nothing but the value of how aggressively you want to use the swap partition (or memory), which ranges from 0 to 100.
The lesser the swapiness, the more your system will use the physical memory (RAM), whereas a swap partition is nothing but a bit of part of your storage drive.
Also, storage drives are relatively slower than RAM, so you should reduce the swapiness if possible.
To check the default swapiness of your system, use the following:
```
cat /proc/sys/vm/swappiness
```
![check swapiness of linux system][20]
And for most Linux distributions, it is set to `60`.
I would recommend you lower this value to `10`.
To do that, first, open the configuration file using the following command:
```
sudo nano /etc/nixos/hardware-configuration.nix
```
And add the following line at the end of the line before `}`:
```
boot.kernel.sysctl = { "vm.swappiness" = 10;};
```
![reduce swapiness in nixos][21]
Save changes and exit from the text editor.
Now, rebuild the config and switch to it using the following:
```
sudo nixos-rebuild switch
```
And now, you can check the swapiness again and it should reflect the change:
```
cat /proc/sys/vm/swappiness
```
![reduce swapiness in NixOS][22]
That's it!
### Wrapping Up
If you follow these points right after installing NixOS for the first time, you should get a good user experience.
Sure, there can be a few other things depending on your requirements. But, I think the above-mentioned things are the most essential or common things to do.
For the next part of this series, I shall discuss setting up the home manager on NixOS, which should be helpful for a system with multiple users.
💬 _What do you first do after installing NixOS? Let me know your thoughts._
--------------------------------------------------------------------------------
via: https://itsfoss.com/things-to-do-after-installing-nixos/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/advanced-linux-distros/
[2]: https://itsfoss.com/why-use-nixos/
[3]: https://itsfoss.com/install-nixos-vm/
[4]: https://itsfoss.com/change-hostname-ubuntu/
[5]: https://itsfoss.com/content/images/2023/02/error-changing-hostname-in-nixos.png
[6]: https://itsfoss.com/content/images/2023/02/change-hostname-in-NixOS.png
[7]: https://linuxhandbook.com/nano-save-exit/?ref=its-foss
[8]: https://itsfoss.com/flatpak-guide/
[9]: https://linuxhandbook.com/beginning-end-file-nano/?ref=its-foss
[10]: https://itsfoss.com/content/images/2023/02/setup-flatpak-on-nixos.png
[11]: https://itsfoss.com/content/images/2023/02/enable-automatic-garbage-collection-in-NixOS.png
[12]: https://itsfoss.com/content/images/2023/02/list-active-timers-in-nixos.png
[13]: https://search.nixos.org/packages?ref=its-foss
[14]: https://itsfoss.com/nixos-package-management/
[15]: https://itsfoss.com/content/images/2023/02/search-packages-for-nixos.png
[16]: https://itsfoss.com/content/images/2023/02/Search-the-service-for-nixos.png
[17]: https://itsfoss.com/content/images/2023/02/enable-openssh-on-nixos.png
[18]: https://itsfoss.com/content/images/2023/02/enable-auto-system-update-in-nixos.png
[19]: https://itsfoss.com/content/images/2023/02/auto-upgrade-timer-in-nixos.png
[20]: https://itsfoss.com/content/images/2023/02/check-swapiness-of-linux-system.png
[21]: https://itsfoss.com/content/images/2023/02/reduce-swapiness-in-nixos.png
[22]: https://itsfoss.com/content/images/2023/02/reduce-swapiness-in-NixOS.png

View File

@ -0,0 +1,295 @@
[#]: subject: "How to Install CRI-O (Container Runtime) on Ubuntu 22.04"
[#]: via: "https://www.linuxtechi.com/install-crio-container-runtime-on-ubuntu/"
[#]: author: "James Kiarie https://www.linuxtechi.com/author/james/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Install CRI-O (Container Runtime) on Ubuntu 22.04
======
CRI-O is an opensource and lightweight container runtime for Kubernetes. It is an implementation of the Kubernetes Container Runtime Interface (CRI) using Open Container Initiative (OCI) compatible runtimes. Its a perfect alternative to Docker when running Kubernetes.
In this guide, we will demonstrate how to install CRI-O on Ubuntu 22.04 LTS step by step.
##### Prerequisites
Before you start out, here is what you need:
- An instance of Ubuntu 22.04 with SSH access
- A sudo user configured on the instance
- Fast and stable internet connectivity
With that out of the way, let us get started out.
### Step 1: Update the system and Install dependencies
Right off the bat, log into your server instance and update the package lists as follows.
```
$ sudo apt update
```
Once the local package index has been updated, install the dependencies as follows.
```
$ sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
```
### Step 2: Add CRI-O repository
To install CRI-O, we need to add or enable its repository on Ubuntu. But first, you need to define the variables based on the operating systems and the CRI-O version that you want to install.
As such, define the variables as shown below.
```
$ export OS=xUbuntu_22.04
$ export CRIO_VERSION=1.24
```
Once that is done, run the following set of commands to add the CRI-O Kubic repository.
```
$ echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /"| sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
$ echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.list
```
Thereafter, import the GPG key for the CRI-O repository
```
$ curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION/$OS/Release.key | sudo apt-key add -
$ curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key add -
```
This yields the following output as shown below.
Once again update the package index to synchronize the system with the newly added CRI-O Kubic repositories.
```
$ sudo apt update
```
### Step 3: Install CRI-O On Ubuntu 22.04
With the repositories added, install CRI-O and the runtime client using the APT package manager.
```
$ sudo apt install cri-o cri-o-runc -y
```
Once installed, start and enable the CRI-O daemon.
```
$ sudo systemctl start crio
$ sudo systemctl enable crio
```
Next, verify if the CRI-O service is running:
```
$ sudo systemctl status crio
```
You should get the following output which shows that the CRI-O service is running as expected.
### Step 4: Install CNI Plugins For CRI-O
Next, you need to install the CNI (Container Network Interface) as well as the CNI plugins. Keep in mind that the loopback and bridge configurations are enabled and sufficient for running pods using CRI-O.
Therefore, to install the CNI plugins, run the following command.
```
$ sudo apt install containernetworking-plugins -y
```
Once installed, edit the CRI-O configuration file
```
$ sudo nano /etc/crio/crio.conf
```
Uncomment network_dir & plugin_dirs section and also add /usr/lib/cni/ under plugin_dirs section.
Save the changes and exit the configuration file.
Next, restart the CRIO service.
```
$ sudo systemctl restart crio
```
### Step 5: Install CRI-O tools
In addition, you also need to install the cri-tools package which provides the crictl command-line utility which is used for interacting and managing containers and pods.
To do so, run the command:
```
$ sudo apt install -y cri-tools
```
Once installed, confirm the version of crictl and RunTimeVersion as follows.
```
$ sudo crictl --runtime-endpoint unix:///var/run/crio/crio.sock version
```
Be sure to also check if CRI-O is ready to deploy pods using the following command:
```
$ sudo crictl info
```
The crictl command provides an autocompletion feature that lets you autocomplete commands by pressing the TAB key. To enable command completion run the following command.
```
$ sudo su -
# crictl completion > /etc/bash_completion.d/crictl
```
Then reload the current bash session.
```
# source ~/.bashrc
```
To use the auto-completion feature, you will need to log out or start a new terminal session. Then simply type the crictl command and press the TABkey to view all the options.
```
$ crictl
```
### Step 6: Create a Pod using crictl utility
Up to this point, CRI-O is fully installed and configured and ready to spin up a pod. In this section, we will create an Apache web server inside a pod and confirm if it is serving requests.
First, we are going to set up a pod sandbox or an isolated environment using a pod configuration file as follows.
```
$ sudo nano apache_sandbox.json
```
We will then add the following configuration to the file.
```
{
    "metadata": {
        "name": "apache-sandbox",
        "namespace": "default",
        "attempt": 1,
        "uid": "hdishd83djaidwnduwk28bcsb"
    },
    "linux": {
    },
    "log_directory": "/tmp"
}
```
Save and exit. Next create the pod using the following command. This prints out  long alphanumeric number which is the pod ID.
```
$ sudo crictl runp apache_sandbox.json
```
To confirm that the pod has been created, run the command.
```
$ sudo crictl pods
```
To retrieve more information about the created pod, run the command:
```
$ sudo crictl inspectp --output table 05ba2f0704f22
```
This prints out the ID, Name, UID, Namespace, date of creation, internal pod IP among other details.
### Step 7: Create a container inside a pod
In section we are going to create an Apache web server container inside the pod. So, use the crictl utility to pull an Apache web server image from Docker Hub.
```
$ sudo crictl pull httpd
```
You can verify the image pulled as shown.
```
$ sudo crictl images
```
Next, we are going to define a container configuration file for the Apache web server.
```
$ sudo nano container_apache.json
```
Copy and paste the following code.
```
{
  "metadata": {
      "name": "apache"
    },
  "image":{
      "image": "httpd"
    },
  "log_path":"apache.0.log",
  "linux": {
  }
}
```
Save and exit the configuration file.
Finally, to attach the container to the sand box pod created earlier, run the command:
```
$ sudo crictl create 05ba2f0704f22 container_apache.json apache_sandbox.json
```
This outputs a large alphanumeric ID to the terminal.. Take note of this ID.
Finally, use the ID to start the Apache web server container as follows.
```
$ sudo crictl start 37f4d26510965452aa918f04d629f5332a1cd398d4912298c796942e22f964a7
```
To check the container status, run the command:
```
$ sudo crictl ps
```
To verify that the Apache web server is running, send a HTTP request to the web server using the curl command and the pods internal ID.
```
$ curl -I 10.85.0.2
```
The following output confirms that the web server is running.
##### Conclusion
Thats all from this, guide. We have successfully installed CRI-O on Ubuntu 22.04 and gone ahead to create a pod and container. Your comments and feedback are welcome.
Also Read: How to Install Docker on Ubuntu 22.04 / 20.04 LTS
--------------------------------------------------------------------------------
via: https://www.linuxtechi.com/install-crio-container-runtime-on-ubuntu/
作者:[James Kiarie][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linuxtechi.com/author/james/
[b]: https://github.com/lkxed/

View File

@ -0,0 +1,285 @@
[#]: subject: "NixOS Series #5: How to set up home-manager on NixOS?"
[#]: via: "https://itsfoss.com/home-manager-nixos/"
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
NixOS Series #5: How to set up home-manager on NixOS?
======
Before publishing this, I explained how to [install and remove packages in NixOS][1] for a single-user system.
But if you are running multiple users, there is an excellent way to cater needs of every user separately.
And in this guide, I will walk you through how you can set up a home manager on NixOS and how it can be used to install packages.
If you are new here, some resources discussed in this series include:
- [Reasons to use nixOS][2]
- [Installing NixOS on a virtual machine][3]
- [Things to do after installing NixOS][4]
### Setup home-manager on NixOS
In this guide, I will walk you through 2 ways to set up a home manager:
- Standalone home manager (uses separate config file)
- As a nix module (using it inside `configuration.nix` file)
So let's start with the standalone option.
#### Standalone installation of home-manager
If you are using a stable channel of NixOS, you can use the following command to configure the home manager:
```
nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.11.tar.gz home-manager
```
While writing this guide, the stable release is `22.11`.
And **if you are on an unstable channel**, use the following:
```
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
```
The following steps will remain the same whether you use stable or unstable.
Once done, update the channels:
```
nix-channel --update
```
And finally, use the following command to install the home manager:
```
nix-shell '<home-manager>' -A install
```
🛠️ While installing, it may throw the following error:
![building error while installing home manager][5]
Reboot your system and use the installation command again, and it will start the installation.
Once done, it will show the location of the standalone installation of the home manager:
![location of home manager in NixOS][6]
#### Installing home-manager as a NixOS module
⚠️
You will need sudo privileges if you choose to use the home manager as a NixOS module.
If you are on a stable channel (while writing, it is 22.11), you can use the following command to add the stable channel of the home manager:
```
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.11.tar.gz home-manager
```
And **if you are using unstable or the master channel**, use the following:
```
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
```
Once you are done adding a channel by using any of one command shown above, update the channel using the following:
```
sudo nix-channel --update
```
Next, open the `configuration.nix` file using:
```
sudo nano /etc/nixos/configuration.nix
```
And add the following line inside the `imports []`:
```
<home-manager/nixos>
```
![install home-manager as NixOS module][7]
Now, jump to the end of the line and add the following before `}`:
```
home-manager.users.{username} = { pkgs, ... }: {
home.packages = [ ];
};
```
![syantax for home-manager module in NixOS config file][8]
The above line was added to facilitate installing and removing packages I will show you next.
Now, [save changes and exit from the nano][9] text editor.
Next, rebuild the config and make a switch:
```
sudo nixos-rebuild switch
```
But if you are using stable release and use the above command, it will throw the error saying :
🛠️ **error: The option `home-manager.users.user.home.stateVersion' is used but not defined:**
![error: The option `home-manager.users.user.home.stateVersion' is used but not defined.][10]
To solve this issue, you will have to add the `home.stateVersion` in your home manager block.
While writing, I'm running 22.11, so the whole home manager block would look like this:
```
home-manager.users.{username} = { pkgs, ... }: {
home.stateVersion = "22.11";
home.packages = [ ];
};
```
![how to solve The option `home-manager.users.user.home.stateVersion' is used but not defined.][11]
Save changes and exit from the nano text editor by pressing `Ctrl + O`, hitting enter and `Ctrl + X`.
Now, try to rebuild the config and make the switch again, and that should solve the issue.
### How to install packages using home-manager on NixOS
Now that you have home-manager installed, how to install packages with it:
#### Using a standalone install of Home-manager
First, open the configuration file by using the following:
```
nano /home/$USER/.config/nixpkgs/home.nix
```
Jump to the end of the line and add the following code block before `}`:
```
home.packages = [];
```
Now, all you have to do is write the package's name between those two braces.
For example, if I want to install **htop**, I will have to enter the following:
```
home.packages = [pkgs.htop];
```
Yes, you will have to usually append the name of the package with `pkgs.`
But if you want to get away with using `pkgs.` using every time you install a new package, change the syntax of the code block as shown:
```
home.packages = with pkgs; [];
```
And now, you are no longer required to use `pkgs.` for every installation:
```
home.packages = with pkgs; [htop];
```
For example, here, I wanted to install **htop, firefox, and LibreOffice** so my home block would look like this:
![install multiple packages using home-manager on NixOS][12]
Once you are done adding your favorite packages, save the config file and use the following command to install packages:
```
home-manager switch
```
#### Using the NixOS module
First, open the `configuration.nix` file using the following command:
```
sudo nano /etc/nixos/configuration.nix
```
In the configuration part, I've already added the home manager block, so all it is left is to add the name of the package inside `home.packages = [  ];` in the shown format:
```
home.packages = [ pkgs.package_name ];
```
💡
I've mentioned how you can get away with using
```
pkgs.
```
before the package name in the above section (installing packages on the standalone home manager).
For example, if I want to [install htop][13], Firefox, and LibreOffice, then I will add:
```
pkgs.htop pkgs.firefox pkgs.libreoffice
```
And my home manager block would look like this:
![install multiple packages in home-manager as a NixOS module][14]
Now, save changes and exit from the text editor.
Next, rebuild the config and make a switch using the following command:
```
sudo nixos-rebuild switch
```
That's it! The packages will be installed in no time.
### 'Tis the end
I think you should go with the standalone installation, as you are not required to use the superuser privileges. Also, having separate config files for separate users is quite convenient if you run a system with multiple users.
So unless you want one file for every purpose, I see no other reason to use the module option.
With this, I conclude the NixOS beginner series. I hope it gets you a good enough platform to get familiar with this unique Linux distribution.
💬 _How did you like the NixOS series? Is there something else we should cover for NixOS beginners? Please provide your valuable feedback._
--------------------------------------------------------------------------------
via: https://itsfoss.com/home-manager-nixos/
作者:[Sagar Sharma][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/sagar/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/nixos-package-management/
[2]: https://itsfoss.com/why-use-nixos/
[3]: https://itsfoss.com/install-nixos-vm/
[4]: https://itsfoss.com/things-to-do-after-installing-nixos/
[5]: https://itsfoss.com/content/images/2023/02/building-error-while-installing-home-manager.png
[6]: https://itsfoss.com/content/images/2023/02/location-of-home-manager-in-NixOS.png
[7]: https://itsfoss.com/content/images/2023/02/install-home-manager-as-NixOS-module.png
[8]: https://itsfoss.com/content/images/2023/02/syantax-for-home-manager-module-in-NixOS-config-file.png
[9]: https://linuxhandbook.com/nano-save-exit/?ref=itsfoss.com
[10]: https://itsfoss.com/content/images/2023/02/The-option--home-manager.users.user.home.stateVersion--is-used-but-not-defined..png
[11]: https://itsfoss.com/content/images/2023/02/how-to-solve-The-option--home-manager.users.user.home.stateVersion--is-used-but-not-defined..png
[12]: https://itsfoss.com/content/images/2023/02/install-multiple-packages-using-home-manager-on-NixOS.png
[13]: https://itsfoss.com/use-htop/
[14]: https://itsfoss.com/content/images/2023/02/install-multiple-packages-in-home-manager-as-a-NixOS-module.png

View File

@ -0,0 +1,121 @@
[#]: subject: "A 5-minute tour of the Fediverse"
[#]: via: "https://opensource.com/article/23/3/tour-the-fediverse"
[#]: author: "Bob Murphy https://opensource.com/users/murph"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
A 5-minute tour of the Fediverse
======
People want to communicate over the internet as easily as they do in real life, with similar protections but, potentially, farther reach. In other words, people want to be able to chat with a group of other people who aren't physically in the same location, and still maintain some control over who claims ownership of the conversation. In today's world, of course, a lot of companies have a lot to say about who owns the data you send back and forth over the world wide web. Most companies seem to feel they have the right to govern the way you communicate, how many people your message reaches, and so on. Open source, luckily, doesn't need to own your social life, and so appropriately it's open source developers who are delivering a social network that belongs, first and foremost, to you.
The "Fediverse" (a portmanteau of "federated" and "universe") is a collection of protocols, servers, and users. Together, these form networks that can communicate with one another. Users can exchange short messages, blog-style posts, music, and videos over these networks. Content you post is federated, meaning that once one network is aware of your content, it can pass that content to another network, which passes it to another, and so on.
Most platforms are run by a single company or organization, a single silo where your data is trapped. The only way to share with others is to have them join that service.
Federation allows users of different services to inter-operate with one another without creating an account for each shared resource.
Admins for each service instance can block other instances in case of egregious issues. Users can likewise block users or entire instances to improve their own experience.
### Examples of Fediverse platforms
Mastodon is a Fediverse platform that has gotten a lot of attention lately, and it's focused on microblogging (similar to [Twitter][1]). Mastodon is only one component of the Fediverse, though. There's much, much more.
- Microblogging: Mastodon, Pleroma, Misskey
- Blogging: Write.as, Read.as
- Video hosting: Peertube
- Audio hosting: Funkwhale
- Image hosting: Pixelfed
- Link aggregator: Lemmy
- Event planning: mobilizon, gettogether.community
### History of the Fediverse
In 2008, Evan Prodromou created a microblogging service called identi.ca using the Ostatus protocol and status.net server software. A few years later, he changed his service to use a new protocol, called pump.io. He released the Ostatus protocol to the Free Software Foundation, where it got incorporated into GNU/social. In this form, the fediverse continued along for several years.
In March 2016, Eugen Rochco (Gargron) created Mastodon, which used GNU/social with an interface similar to a popular Twitter interface called Tweetdeck. This gained some popularity.
![The Fediverse includes Pixelfed, Mastodon, Misskey, Plume, Nextcloud, Castopod, Bookwyrm, and much more.][2]
In 2018, a new protocol called ActivityPub was accepted as a standardized protocol by the W3C. Most Fediverse platforms have adopted it. It was authored by Evan Prodromou, Christine Lemmer-Weber, and others, and it expanded upon the previous services to provide a better and more flexible protocol.
### What does the Fediverse look like?
The Fediverse, being made of any application using the ActivityPub protocol, is pretty diverse in appearance. As you might imagine, a microblogging platform has different requirements than a video sharing service.
It can be intimidating to wander into the great unknown, though. Here are some screenshots of my favorite federated services:
The Mastodon web client has a simplified view, as well as the advanced view, the simplified default view shows a single column of the Home feed, with options on the right to view more.
![The Mastodon web client features a central panel for activity on your curated network.][3]
The Advanced Web Interface, shown below, has the home timeline, local timeline, federated timeline, as well as a user's profile. When users first start, the easier one-column view is the default.
![The advanced Mastodon interface has several columns.][4]
Pixelfed has an interface focused around displaying images and videos:
![Pixelfed's interface features thumbnails of photographs.][5]
Peertube is for sharing videos:
![Peertube's interface features thumbnails of videos you can watch.][6]
Mobilizon is an event planning site, with plans for Fediverse integration:
![The Mobilizon interface helps you plan events.][7]
### Switch to open source social
Ready to start? Check out fediverse.info for a nice video explanation and a subject-based way to find (self-selected) other users.
Go to [fedi.tips][8] for a comprehensive guide on how to get started, how to migrate your data, and more.
Mastodon has several great entry points:
- [Joinmastodon.org][9]: The largest list of Mastodon servers
- [Joinfediverse.wiki][10]: Great information on different fediverse services and instances
- [Fedi.garden][11]: A well-curated list of instances
For help deciding which instance to join (assuming you don't want to spin up your own just yet), visit [fediverse.party/en/portal/servers][12].
Are you a data nerd? Visit [the-federation.info][13] for stats, monitoring service, and a data-driven look at the known Fediverse.
### Get federated
The Fediverse is a way to use the social media in an individualized way, either by choosing an instance with a community that suits your needs, or running your own server, and making it exactly the way you want. It avoids the advertising, algorithms, and other unpleasantries that plague many social networks.
If you are looking for a community that better suits your needs than the big silos, take a look, the Mastodon and the Fediverse may be a good fit for you. Get federated today.
You can find me at [@murph@hackers.town][14] on the Fediverse.
--------------------------------------------------------------------------------
via: https://opensource.com/article/23/3/tour-the-fediverse
作者:[Bob Murphy][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/murph
[b]: https://github.com/lkxed/
[1]: https://opensource.com/article/22/11/switch-twitter-mastodon
[2]: https://opensource.com/sites/default/files/2023-02/100000010000045A000004B08541865BBD9D13DE.webp
[3]: https://opensource.com/sites/default/files/2023-02/10000001000005AB000004DB07D4A02485D90B14.webp
[4]: https://opensource.com/sites/default/files/2023-02/10000001000008DE000004569A05D60180F4348D.webp
[5]: https://opensource.com/sites/default/files/2023-02/10000001000004CA00000617FD573CC873BD98E0.webp
[6]: https://opensource.com/sites/default/files/2023-02/10000001000007BE0000048AA0BCF8E824246BCD.webp
[7]: https://opensource.com/sites/default/files/2023-02/100000010000066100000466B5FCB59017E118D7.webp
[8]: https://fedi.tips
[9]: https://joinmastodon.org
[10]: https://joinfediverse.wiki
[11]: https://fedi.garden
[12]: https://fediverse.party/en/portal/servers
[13]: https://opensource.com/the-federation.info
[14]: https://hackers.town/@murph

View File

@ -0,0 +1,206 @@
[#]: subject: "Ubuntu 23.04 “Lunar Lobster”: Best New Features"
[#]: via: "https://www.debugpoint.com/ubuntu-23-04-features/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Ubuntu 23.04 “Lunar Lobster”: Best New Features
======
**Introducing the latest Ubuntu 23.04 “Lunar Lobster” release, packed with new features and improvements.**
Ubuntu 23.04, code-named “Lunar Lobster”, is the first short-term release of 2023, and it will be supported for nine months until January 2024. This release is about improving Ubuntus core backend and progress work by adopting new packages and technology. In a way, many changes are being baselined as a preparation for next years LTS release (Ubuntu 24.04).
The development cycle is almost complete. As of publishing this, a beta freeze is imminent. So, its a good time to explore this releases new features.
But before that, a quick look at the upcoming milestones.
- Beta freeze: March 27, 2023
- Beta release: March 30, 2023
- Release candidate: April 13, 2023
- Final release: April 20, 2023
![Ubuntu 23.04 Lunar Lobster Daily Live desktop][1]
### Ubuntu 23.04: New Features
#### New desktop installer
Ubuntus new Rust-based desktop installer is finally ready to be experienced in this release. The work was undergone for more than two years. After many obstacles and critical bugs are fixed, its now stable enough to be released in the official version. From this release onwards, the good ol Ubiquity is replaced by the brand new installer, as shown in the below set of images.
![New Ubuntu Installer - main page][2]
![Partition summary page][3]
![Appearance Changes][4]
![User information page][5]
However, as I heard from some sources, the older Uqiuity continues to stay (until next year). But I am not sure entirely how the old installer will kick off. Because the default live medium launches the new installer.
That being said, if you compare it to the older one, a few changes to the new installer. First of all, the look and feel are more modern compared to old ubiquity dialogues and widget controls.
The summary details about partitioning are now present as a separate page instead of a pop-up box.
In addition, Ubuntu 23.04 now asks for the dark/light mode options before installation. I am not sure about the necessity of this since Ubuntu already has some onboarding steps defined in a separate app.
#### GNOME 44 Desktop
Ubuntu 23.04 desktop version features GNOME 44. This release of GNOME 44 is bringing a bunch of long pending updates. For example, in this release, you experience the image preview in the native file picker dialog. Furthermore, the Files gets the long-awaited missing feature, i.e. expanded folder (or tree view) view natively. You can enable it using the settings shown below.
![New expandable folder view][6]
![Settings to enable tree view][7]
Other key changes in GNOME 44 include Files now supporting file creation while pasting image data, an improved accessibility settings page for better navigation and a much improved GNOME Web browser.
You can learn more about GNOME 44 release on my feature highlights page: [GNOME 44 best features][8].
#### Minimal ISO image
In a surprise move, the Ubuntu team is [introducing][9] an official minimal ISO image (less than 200MB) in this release. Once released, you can use this minimal ISO image to create custom Ubuntu Linux. As of publishing this, we are yet to get the daily build ISO for this minimal image.
However, the Xubuntu team [already released][10] a minimal ISO image which I tried here. Likewise, all the official flavours are expected to get their own minimal ISO files.
More information to arrive on this in the coming days.
#### More Snap and less Flatpak
A few Snap and Flatpak-related vital changes are coming up, and you should be prepared for that.
Firstly, the push for more Snap packages is evident as the official Telegram app for desktops is now Snap in Ubuntu.
Furthermore, Ubuntu plans to release a Steam desktop client as Snap, which is [currently under testing][11]. Snap desktop client is available as native deb and Flatpak packages today. The Steam Snap is expected to arrive by the end of this year and not in this release.
Alongside this, default Flatpak and Flathub integration is now officially [removed][12] from all the supported official Ubuntu flavours. This decision created quite several “discussions” on the web.
So, Ubuntu MATE & Kubuntu wont ship Flatpak/Flathub by default from this release onwards. However, you can always install it with [just a few steps][13].
#### New Applications
The default application stack of Ubuntu 23.04 is upgraded as usual. However, some key changes that you might notice.
Firstly, LibreOffice might look a bit different. The LibreOffice team recently changed the default icon themes, and it looks awesome in the Ubuntu GNOMEs desktop context.
The LibreOffice 7.5 included in this release arrives with an improved bookmark module for Writer, new number formats in Calc spreadsheets, new table design styles in Impress and many more.
You can read more about [LibreOffice 7.5 features here][14].
![New LibreOffice Icons][15]
Summary of other applications in Ubuntu 23.04:
- [Firefox 111][16] (Snap)
- LibreOffice 7.5
- Transmission 3.0
- Shotwell image viewer 0.30
#### Official Flavours
A piece of good news for all educators and students. Edubuntu is [officially coming up][17] from the 23.04 release onwards. Its another addition to the official Ubuntu flavours list. Edubuntu will likely feature a larger ISO file (around 5 GB) with all the education-related FOSS software installed. I will have a separate article for the review of this flavour.
In addition, all the respective flavours get their below desktop versions.
- Kubuntu with [KDE Plasma 5.27][18]
- Xubuntu with [Xfce 4.18][19]
- Ubuntu MATE 23.04 with MATE desktop 1.26.1
- Lubuntu 23.04 with [LXQt 1.2][20]
- Ubuntu Budgie with Budgie desktop version 10.7
Ubuntu Budgie 23.04 is bringing some exciting features such as edge tiling, hot corners, etc.
#### Kernel & Toolchain updates
As of writing this, the daily build copy has the Linux Kernel 6.1. However, before the Kernel freeze (April 6, 2023) the current mainline Kernel 6.2 will likely arrive in Ubuntu 23.04. Linux Kernel 6.2 improves support for GPU, CPU, ports, and Rust updates.
At the core, Python 3.11 is now available out-of-the-box in Ubuntu 23.04. You dont need to [install Python 3.11][21] anymore separately. Its worth mentioning that Python 3.12 release is due this year and currently undergoing multiple RC testing.
Other toolchain updates are as follows.
- GCC 13
- GlibC 2.37
- Ruby 3.1
- golang 1.2
- LLVM 16
#### New Wallpapers for Ubuntu 23.04
A desktop release never completes with some new cool wallpapers. After the successful [wallpaper competition][22], the winners are selected for default wallpapers featuring the “Lunar & Lobster”.
Heres the default one. And the rest of them you can find [here][23].
![Ubuntu 23.04 Lunar Lobster Default Wallpaper][24]
### Download
The daily build ISO files are present in the below links for Ubuntu desktop and flavours.
Note that you should not use these as main driver. They have some bugs (at least I found some) and are not entirely stable yet.
Ubuntu FlavourLink to .iso image(s) Daily build |
| Ubuntu 23.04 Desktop(GNOME) | [https://cdimage.ubuntu.com/ubuntu/daily-live/pending/][25] |
| Xubuntu 23.04 | [https://cdimage.ubuntu.com/xubuntu/daily-live/current/][26] |
| Ubuntu MATE 23.04 | [https://cdimage.ubuntu.com/ubuntu-mate/daily-live/current/][27] |
| Ubuntu Kylin 23.04 | not available |
| Lubuntu 23.04 | [https://cdimage.ubuntu.com/lubuntu/daily-live/current/][28] |
| Kubuntu 23.04 | [https://cdimage.ubuntu.com/kubuntu/daily-live/current/][29] |
| Ubuntu Budgie 23.04 | [https://cdimage.ubun][30][tu.com/ubuntu-budgie/daily-live/current/][30] |
| Ubuntu Unity 23.04 | [https://cdimage.ubuntu.com/ubuntu-unity/daily-live/current/][31] |
| Edubuntu 23.04 | [https://cdimage.ubuntu.com/edubuntu/daily-live/current/][32] |
### Wrapping Up
In conclusion, the new Ubuntu 23.04 release promises to offer desktop users an even smoother and more seamless experience.
From improved security features to enhanced productivity tools & apps, this update will surely delight Ubuntu enthusiasts & fans. Whether youre a seasoned user or new to the Ubuntu ecosystem, this release is worth checking out.
Ubuntu 23.04 releases on April 20, 2023.
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/ubuntu-23-04-features/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://www.debugpoint.com/wp-content/uploads/2023/03/Ubuntu-23.04-Lunar-Lobster-Daily-Live-desktop.jpg
[2]: https://www.debugpoint.com/wp-content/uploads/2023/03/New-Ubuntu-Installer-main-page.jpg
[3]: https://www.debugpoint.com/wp-content/uploads/2023/03/Partition-summary-page.jpg
[4]: https://www.debugpoint.com/wp-content/uploads/2023/03/Appearane-changes.jpg
[5]: https://www.debugpoint.com/wp-content/uploads/2023/03/User-information-page.jpg
[6]: https://www.debugpoint.com/wp-content/uploads/2023/02/New-expandable-folder-view.jpg
[7]: https://www.debugpoint.com/wp-content/uploads/2023/02/Settings-to-enable-tree-view.jpg
[8]: https://www.debugpoint.com/gnome-44/
[9]: https://debugpointnews.com/ubuntu-mini-iso-announcement/
[10]: https://www.debugpoint.com/xubuntu-minimal/
[11]: https://discourse.ubuntu.com/t/steam-call-for-testing/34575
[12]: https://debugpointnews.com/ubuntu-flavours-flatpak/
[13]: https://www.debugpoint.com/how-to-install-flatpak-apps-ubuntu-linux/
[14]: https://www.debugpoint.com/libreoffice-7-5/
[15]: https://www.debugpoint.com/wp-content/uploads/2023/03/New-LibreOffice-Icons.jpg
[16]: https://debugpointnews.com/firefox-111/
[17]: https://discourse.ubuntu.com/t/announcing-edubuntu-revival/32929
[18]: https://www.debugpoint.com/kde-plasma-5-27/
[19]: https://www.debugpoint.com/xfce-4-18-review/
[20]: https://www.debugpoint.com/lxqt-1-2-0-features/
[21]: https://www.debugpoint.com/install-python-3-11-ubuntu/
[22]: https://debugpointnews.com/ubuntu-23-04-wallpaper-competition/
[23]: https://discourse.ubuntu.com/t/lunar-lobster-23-04-wallpaper-competition/33132
[24]: https://www.debugpoint.com/wp-content/uploads/2023/03/Ubuntu-23.04-Lunar-Lobster-Default-Wallpapers.jpg
[25]: https://cdimage.ubuntu.com/ubuntu/daily-live/pending/
[26]: https://cdimage.ubuntu.com/xubuntu/daily-live/current/
[27]: https://cdimage.ubuntu.com/ubuntu-mate/daily-live/current/
[28]: https://cdimage.ubuntu.com/lubuntu/daily-live/current/
[29]: https://cdimage.ubuntu.com/kubuntu/daily-live/current/
[30]: https://cdimage.ubuntu.com/ubuntu-budgie/daily-live/current/
[31]: https://cdimage.ubuntu.com/ubuntu-unity/daily-live/current/
[32]: https://cdimage.ubuntu.com/edubuntu/daily-live/current/

View File

@ -0,0 +1,140 @@
[#]: subject: "8 steps to refurbish an old computer with Linux"
[#]: via: "https://opensource.com/article/23/3/refurbish-old-computer-linux"
[#]: author: "Howard Fosdick https://opensource.com/users/howtech"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
8 steps to refurbish an old computer with Linux
======
We live in a remarkable era. It wasn't so long ago we were all chained to the "upgrade treadmill," forced to buy expensive new personal computers every few years.
Today, with the benefit of open source software, you can break out of that cycle. One way is to [refurbish old computers][1] and keep them in service. This article tells you how.
### 1. Grab an old PC
Maybe you have an old computer lying unused in the basement or garage. Why not put it to use?
Or you can get an old machine from a friend, family member, or Craigslist ad. Many electronics recycling centers will let you poke around and take a discarded machine if it fits your fancy. Be sure to grab more than one if you can, as you may need parts from a couple abandoned PCs to build one good one.
Look at the stickers on the front of the machines to make sure you're selecting good refurbishing candidates. Items with Window 7 and 8 logos run Linux quite well. Extended support ended for 8.1 this January, so I'm seeing a lot of those getting dumped.
Many of these Windows computers offer perfectly good hardware. They're only being trashed due to planned obsolescence because they can't run Windows 11. They run open source software just fine.
### 2. Identify and clean everything
Before you open up your "new" machine to see what you've got, be sure to ground yourself by touching something metal. Even a shock so slight you don't feel it can destroy delicate circuitry.
You'll instantly see if any parts are missing. Many people take out their disks or sometimes the memory before recycling a computer. You'll either have to acquire more than a single box to cover this, or you'll need to buy a part or two to make it whole.
Before proceeding further, it's important to give the machine a thorough cleaning. Pay special attention to the CPU complex, the fans, and all surfaces. Remember that you can't rub electronics without risking damage, so use compressed air for cleaning.
### 3. Ensure all hardware works
You'll want to verify that all hardware works prior to installing any software. Don't skimp on the testing! It's a huge waste of your time if you find out, for example, that your computer has a transient memory error at a later time because you ran only a short ram test before going to next steps. I find it convenient to run time-consuming tests overnight.
Most computers have hardware-specific diagnostics built in. You usually access these either through the boot-time UEFI/BIOS panels or by pressing a PF key while booting. If your machine doesn't include testing tools, try [Ultimate Boot Disk][2], which provides tons of useful testing utilities.
Be sure you test all components thoroughly:
- Memory
- Disk
- CPU and Motherboard
- Peripherals (USB ports, sound, microphone, keyboard, display, fans, etc)
If you find problems, download my free [Quick Guide to Fixing Hardware][3]. That plus some searching online enables you to fix just about anything.
### 4. Prepare the disk
You've assessed your hardware and have gotten it into good working order. If your computer came with a hard disk drive (HDD), the next step is to ready that for use.
You need to completely wipe the disk because it could contain illegally obtained movies, music, or software. To thoroughly wipe an HDD, run a tool like [DBAN][4]. After running that, you can rest assured the disk is completely clean.
If you have a solid state disk (SSD), the situation is a bit trickier. Disk-wipe programs designed to cleanse hard disks don't work with SSDs. You need a specialized _secure erase_ program for an SSD.
Some computers come with an secure erase utility in their UEFI/BIOS. All you have to do is access the boot configuration panels to run it.
The other option is the website of the disk manufacturer. Many offer free downloads for secure erase utilities for their SSDs.
Unfortunately, some vendors don't provide a secure erase utility for some of their consumer drives, while others supply only a Windows executable. For an SSD, [Parted Magic's][5] secure erase function is the best option.
### 5. Booting, data storage, and backups
Your disk strategy for your refurbished computer must address three needs: booting, data storage, and backups.
A few years ago, if your refurbishing candidate contained a disk, it was always a hard drive. You'd wipe it with DBAN, then install your favorite Linux distribution, and use it as both your boot and storage device. Problem solved.
Today's technology offers better options. These eliminate the slow hard disk access that was previously one of the downsides of using older equipment.
One option is to buy one of the new low-end SSDs that have become available. These now offer the SATA and external USB interfaces that work with mature computers.
Prices have plummeted. I recently bought a 480 gig SSD/SATA drive for $25. That's so inexpensive that, even if your old computer came with a hard drive included, you might prefer to buy a new SSD anyway. It boots and accesses data so much faster.
The lightweight 2.5" SSDs also solve the mounting dilemmas one sometimes faced with old desktops. With a single screw you can attach them almost anywhere. No more messing with rails, cages, and all the other goofy proprietary parts companies used to mount their heavy 3.5" hard drives.
An alternative to an SSD is to boot off a [USB memory stick][6]. Thumb drives now offer enough space to host any operating system you prefer, while leaving some storage space for your data. Beyond speed, you gain flexibility by keeping your system on a portable device.
So consider installing your operating system to a fast SSD or USB and booting and running it from that.
What about other drives? I like to use any hard drive that came with the computer as a backup disk for my boot SSD. Or employ it as mass storage.
I usually remove the optical drives you find in old desktops. Since USB sticks are faster and hold more data, few people use them anymore. Most now stream their films, music, and software programs instead of collecting them on optical media.
Removing the optical drive frees up an extra set of disk connectors. It also opens up lots of space in the cabinet and improves air flow. This can make a big difference if you're dealing with small footprint desktops with slimline or mini-tower cases.
Finally, take a few minutes to decide on your backup strategy. You'll need to back up two separate things: your data and the operating system.
Will you back up to a second drive inside the PC, a detachable storage device, or cloud services? Your decision helps determine whether you'll need a second disk in your refurbished computer.
### 6. Select and install software
Different people have different needs that drive their software selection. Here are some general guidelines.
If your computer has an Intel i-series processor and at least 4 GB of memory, it can comfortably run nearly any Linux distribution with any [desktop environment (DE)][7].
With between two and four gigabytes of memory, install a Linux with a [lightweight interface][8]. This is because high-end display graphics is a big consumer of memory resources. I've found that Linux distros with a DE like XFCE, LXDE, and LXQt work well.
If you only have a gigabyte of memory, go for an "ultra-light" Linux distribution. This should probably also be your choice if you have an old dual-core CPU or equivalent.
I've used both [Puppy Linux][9] and [AntiX][10] with great results on such minimal hardware. Both employ lightweight windows managers for their user interface instead of full desktop environments. And both come bundled with apps selected specifically to minimize resource use.
### 7. Browse the web efficiently
Web pages have grown dramatically in the past five years. Over half the computer resource many popular websites require is now consumed by advertisements and trackers. So when web surfing, block all those ads and trackers. If you can off-load ad blocking from your browser to your VPN, that's ideal. And don't let those auto-run videos run without your explicit permission.
Look around to see what browser works best for your equipment. Some are designed with a multi-threading philosophy, which is great if your PC can support it. Others try to minimize overall resource usage. Many people aren't aware that there are [quite a few][11] capable yet minimalist Linux browsers available. In the end, pick the browser that best matches both your equipment and your web surfing style.
### 8. Have fun
Whether you want to make use of an old computer sitting in your basement, help the environment by [extending the computer life cycle][12], or just find a free computer, refurbishing is a worthy goal.
Anyone can succeed at this. Beyond investing your time, the cost is minimal. You're sure to learn a bit while having fun along the way. Please share your own refurbishing tips with everyone in the comments section.
--------------------------------------------------------------------------------
via: https://opensource.com/article/23/3/refurbish-old-computer-linux
作者:[Howard Fosdick][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/howtech
[b]: https://github.com/lkxed/
[1]: https://opensource.com/article/22/10/obsolete-computer-linux-opportunity
[2]: https://www.ultimatebootcd.com/
[3]: http://rexxinfo.org/howard_fosdick_articles/quick_guide_to_fixing_pc_hardware/Quick_Guide_to_Fixing_Computer_Hardware.html
[4]: https://sourceforge.net/projects/dban/
[5]: https://partedmagic.com/
[6]: https://opensource.com/article/20/4/first-linux-computer
[7]: https://opensource.com/article/20/5/linux-desktops#default
[8]: https://opensource.com/article/20/5/linux-desktops#lightweight
[9]: https://puppylinux-woof-ce.github.io/
[10]: https://antixlinux.com/
[11]: https://opensource.com/article/19/7/open%20source-browsers
[12]: https://opensource.com/article/19/7/how-make-old-computer-useful-again

View File

@ -0,0 +1,118 @@
[#]: subject: "A Screenshot Tour & Walkthrough of New Ubuntu Installer"
[#]: via: "https://www.debugpoint.com/new-ubuntu-installer/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
A Screenshot Tour & Walkthrough of New Ubuntu Installer
======
**Screenshot tour & highlights of the new Ubuntu desktop installer Subiquity.**
Ubuntu developers have worked on the new Rust-based Ubuntu installer for over two years. The goal was to replace the good old ubiquity installer with a modern application. The primary reason is code maintainability, while Rust provides a better alternative.
However, the installer never made it to the final release until now. The new installer debuts in the Ubuntu 23.04 “Lunar Lobster” release (upcoming).
In this article, we will walk you through the new Ubuntu installer “subiquity” and show you how to install Ubuntu with ease.
### Introduction to the New Ubuntu Installer
If you compare it with the current installer, the new Ubuntu installer has undergone a complete redesign visually. The new installer is more user-friendly and intuitive, making it easier for users to install Ubuntu. The installer also features improved language support, partitioning options, and a more streamlined installation process.
As of the current version, there are total 8 steps before installation starts. A “preview/next” based wizard will guide you through the installation process.
From the LIVE medium, upon selecting the “try or install ubuntu” from the grub menu, the new installer launches. On the first screen, you need to select the language.
If you are seeing it for the first time, you might notice the look and feel is now more “flat” alongside control buttons and widgets. This design aligns with the current Ubuntu default theme.
![New Ubuntu installer - First Screen][1]
So, once you select the language, you get two options. To start the installation, you can select the “Install Ubuntu” option. Or, you can “Try Ubuntu”, which will take you straight to the live desktop.
You can also launch the installer from the left dock icon later.
![Option to try or install][2]
Lets go ahead and install.
On the second page, you need to select your keyboard layout. You also have the option to auto-detect the keyboard.
![Detect Keyboard Layout][3]
The installer will ask you to connect to the internet on the next installation page. Functionality-wise, this is also common with the earlier Ubiquity installer.
![Connecting to internet][4]
The following screen lets you choose the type of Ubuntu install you want to perform. You can go either for “Normal” installation or choose the “Minimal” option. Also, you have options to install the proprietary packages.
![Choose the type of install][5]
The partitioning page is very nice and clean. It offers more flexible disk partitioning options. Furthermore, you can also choose to install Ubuntu alongside another operating system or erase the entire disk and install Ubuntu as the sole operating system. You can also choose to manually partition the disk if you prefer.
If you are using in an unformatted disk, you can create a partition table. Also, you can add partitions, delete them and assign mount points for installation.
Its really good to see a simpler approach for complex settings (compared to the Anaconda installer).
![Partition page 1][6]
![Partition page 2][7]
A summary page will give you an overview of the complete partition information before it has been written to disk. Once you hit install, the changes will be written to disk.
The new installer will take you through a few additional pages, such as location and user information.
![Select yout time zone][8]
The new Ubuntu installer makes it easy to set up your user account. You can enter your name, username, and password. You can also choose to set active directory if you are using the device in your local LAN setup or you are setting it up for your organization.
![User information][9]
There is an additional new page to select light and dark themes for your Ubuntu desktop. I am not entirely sure why this setting is needed for installation, but it should have been in the welcome app.
![Choose light or dark theme][10]
And finally, the installation starts with some feature highlights of the release.
![Installation is in progress][11]
In the end, you get a sleek completion message showing that it has been installed.
![Installation complete][12]
After the restart, you will need to perform some post-installation setup tasks. The existing onboarding app makes it easy to set up your system by guiding you through the process. You can set up your online accounts and privacy settings and perform other tasks as needed.
### Conclusion
Overall the new installer remains almost the same functionally. However, with improved looks and under-the-hood performance, updates for Rust are visible. I think the old Ubiquity was a little slower in performance, and sometimes it took a couple of minutes while doing partitions. This has been significantly improved in the new installer.
Its a great addition to the [Ubuntu 23.04 release][13].
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/new-ubuntu-installer/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://www.debugpoint.com/wp-content/uploads/2023/03/New-Ubuntu-installer-First-Screen.jpg
[2]: https://www.debugpoint.com/wp-content/uploads/2023/03/Option-to-try-or-install.jpg
[3]: https://www.debugpoint.com/wp-content/uploads/2023/03/Detect-Keyboard-Layout.jpg
[4]: https://www.debugpoint.com/wp-content/uploads/2023/03/Connecting-to-internet.jpg
[5]: https://www.debugpoint.com/wp-content/uploads/2023/03/Choose-the-ype-of-install.jpg
[6]: https://www.debugpoint.com/wp-content/uploads/2023/03/Partition-page-1.jpg
[7]: https://www.debugpoint.com/wp-content/uploads/2023/03/Partition-page-2.jpg
[8]: https://www.debugpoint.com/wp-content/uploads/2023/03/Select-yout-time-zone.jpg
[9]: https://www.debugpoint.com/wp-content/uploads/2023/03/User-information.jpg
[10]: https://www.debugpoint.com/wp-content/uploads/2023/03/Choose-light-or-dark-theme.jpg
[11]: https://www.debugpoint.com/wp-content/uploads/2023/03/Installation-is-in-progress.jpg
[12]: https://www.debugpoint.com/wp-content/uploads/2023/03/Installation-complete.jpg
[13]: https://www.debugpoint.com/ubuntu-23-04-features/

View File

@ -0,0 +1,223 @@
[#]: subject: "Terminal Basics #6: Delete Files and Folders in Linux"
[#]: via: "https://itsfoss.com/delete-files-folders-linux/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Terminal Basics #6: Delete Files and Folders in Linux
======
In the earlier chapters of the Terminal Basics series, you learned to [create new files][1] and directories (folders).
Let's now see how you can delete files and folders in the Linux terminal.
### Deleting files
To remove files, you can use the rm command in the following fashion:
```
rm filename_or_path
```
You won't see any output if the file is successfully deleted.
Here's an example where I removed one of the files named `new_file`. When I list the directory contents, you can see that `new_file` no longer exists.
![Removing files in Linux terminal][2]
You can also remove multiple files in the same command:
```
rm file1 file2 file3
```
Let me show an example of deleting two files in a single command.
![Deleting multiple files in single rm command][3]
#### 🏋Exercise file deletion
Let's practice what you just learned. Create a directory named practice_delete and switch to it:
```
mkdir practice_delete && cd practice_delete
```
Now create a few empty files:
```
touch file1 file2 file3
```
Delete the file3:
```
rm file3
```
Now, let's do something extra. Run this command and change the permission on file2:
```
chmod u-w file1 file2
```
Try deleting file2 now:
```
rm file2
```
Do you see a message '**remove write protected file**'? That's because you removed the write permission (for modification) from this file.
You can **press Y or enter key to confirm the deletion or N to deny the removal.**
If you don't want to see this message and still delete it, you can use the force delete option `-f`. Try it by deleting `file1`:
```
rm -f file1
```
Here's a replay of all the above examples to help you:
![Deleting files in Linux terminal][4]
> 🚧 There is no trash bin in the Linux command line. Once the file is deleted, you cannot undo the action to bring it back from the trash bin as you do in the graphical file manager. For this reason, be extra careful while deleting the files.
#### Remove but with caution
The lack of trash bin makes the deletion a permanent jobs of sort. This is why you should be careful about what files are you deleting.
There is an interactive mode with option `-i`. With this, you'll be asked to confirm the deletion.
```
rm -i filename
```
This is helpful when you are deleting several files based on a certain pattern.
Here's an example where I am interactively deleting all the files that match file_ pattern in their name. I delete some and keep some in the interactive mode.
![Deleting files in interactive mode][5]
> 💡 I advise switching to the directory where the files are located and then removing them. This helps in reducing any potential caused by a typo in file path.
### Deleting directories
There is a dedicated rmdir command to remove directories in Linux.
```
rmdir dir_name
```
However, it can only delete empty directories. If the directory has any files or subdirectories in it, the rmdir command will throw error.
```
[email protected]:~/practice_delete$ rmdir dir2
rmdir: failed to remove 'dir2': Directory not empty
```
And that makes it less useful in most cases.
So, how do you delete a non-empty folder then? Well, you use the same rm command that you used earlier for removing files.
Yes, the same rm command but with the recursive option `-r`:
```
rm -r dir_name
```
#### 🏋Exercise folder deletion
Let's practice what you learned.
Switch to practice_delete folder if you are not already there. Now, create two directories dir1 and dir2.
```
mkdir dir1 dir2
```
Create a file in dir2:
```
touch dir2/file
```
Now try deleting the directories using the rmdir command:
```
rmdir dir1
```
```
rmdir dir2
```
Since the dir2 is not empty, rmdir command will fail. Instead, use the rm command with recursive option:
```
rm -r dir2
```
Here's a replay of all the above command examples to help you out:
![Deleting folders in Linux][6]
> 💡 The interactive deletion mode is even more helpful while deleting a directory with the recursive option of the rm command:
```
rm-ri dir_name
```
So, you learned to delete files and folders both using Linux commands. It's time to practice some more.
### Test your knowledge
Prepare a directory tree that looks like this:
```
.
├── dir1
│   ├── file1
│   ├── file2
│   └── file3
├── dir2
├── dir3
└── file
```
Basically, you create a file named file and three directories dir1, dir2 and dir3 in the current directory (practice_delete). And then you create files file1, file2 and file3 in dir1.
Now do the following:
- Delete `file2`.
- Switch to the `dir3` and force delete the file named `file` in the upper directory.
- Delete all the contents of dir1 but not the directory itself.
- List the contents of the `dir`.
I encourage you to discuss the practice questions in the [It's FOSS community forum][7].
This is going good. You have learned several basic things like switching directories, checking contents of directory, creating and deleting files and directories. In the next chapter, you'll learn about copying files and folders in the terminal. Stay tuned!
--------------------------------------------------------------------------------
via: https://itsfoss.com/delete-files-folders-linux/
作者:[Abhishek Prakash][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lkxed/
[1]: https://itsfoss.com/create-files/
[2]: https://itsfoss.com/content/images/2023/03/delete-files-linux-terminal.png
[3]: https://itsfoss.com/content/images/2023/03/remove-multiple-files-linux-terminal.png
[4]: https://itsfoss.com/content/images/2023/03/file-delete-example.svg
[5]: https://itsfoss.com/content/images/2023/03/interactive-delete-example.svg
[6]: https://itsfoss.com/content/images/2023/03/folder-delete-example.svg
[7]: https://itsfoss.community/?ref=itsfoss.com

View File

@ -0,0 +1,102 @@
[#]: subject: "3 surprising things Linux sysadmins can do with systemd"
[#]: via: "https://opensource.com/article/23/3/3-things-you-didnt-know-systemd-could-do"
[#]: author: "Alan Smithee https://opensource.com/users/alansmithee"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
3 surprising things Linux sysadmins can do with systemd
======
When it first started out, there was a lot of press about systemd and its ability to speed up boot time. That feature had a mostly-universal appeal (it's less important to those who don't reboot), so in many ways, that's the reputation it still has today. And while it's true that systemd is the thing that launches services in parallel during startup, there's a lot more to it than that. Here are three things you may not have realized systemd could do but should be taking advantage. Get more tips from our new downloadable eBook, **[A pragmatic guide to systemd][1]**.
### 1. Simplify Linux ps
If you've ever used the `ps` or even just the `top` command, then you know that your computer is running hundreds of processes at any given moment. Sometimes, that's exactly the kind of information you need in order to understand what your computer, or its users, are up to. Other times, all you really need is a general overview.
The `systemd-cgtop` command provides a simple view of your computer's load based on the cgroups (control groups) tasks have been arranged into. [Control groups][2] are important to modern Linux, and are essentially the support structures underneath containers and Kubernetes (which in turn are why the cloud scales the way it does), but also they're useful constructs on your home PC. For instance, from the output of `systemd-cgtop`, you can see the load of your user processes as opposed to system processes:
```
Control Group Proc+ %CPU Memory Input/s Output/s
/ 183 5.0 1.6G 0B 3.0M
user.slice 4 2.8 1.1G 0B 174.7K
user.slice/user-1000.slice 4 2.8 968.2M 0B 174.7K
system.slice 65 2.2 1.5G 0B 2.8M
```
You can also view just your userspace processes, or just your userspace processes and kernel threads.
This isn't a replacement for `top` or `ps` by any means, but it's an additional view into your system from a different and unique angle. And it can be vital when running containers, because containers use cgroups.
### 2. Linux cron
[Cron][3] is a classic component of Linux. When you want to schedule something to happen on a regular basis, you use cron. It's reliable and pretty well integrated into your system.
The problem is, cron doesn't understand that some computers get shut down. If you have a cronjob scheduled for midnight, but you turn your computer off at 23:59 every day, then your cronjob never runs. There's no facility for cron to detect that there was a missed job overnight.
As an answer to that problem, there's the excellent [anacron][4], but that's not quite as integrated as cron. There's a lot of setup you have to do to get anacron running.
A second alternative is systemd timers. Like cron, it's already built in and ready to go. You have to write a unit file, which is definitely more lines than a one-line crontab entry, but it's also pretty simple. For instance, here's a unit file to run an imaginary backup script 30 minutes after startup, but only once a day. This ensures that my computer gets backed up, and prevents it from trying to backup more than once daily.
```
[Unit]
Description=Backup
Requires=myBackup.service
[Timer]
OnBootSec=30min
OnUnitActiveSec=1d
[Install]
WantedBy=timers.target
```
You can, of course, intervene and prompt a job to run with . Thanks to the `OnUnitActiveSec` directive, systemd doesn't attempt to run a job you've manually activated.
### 3. Run Linux containers
Containers make starting up a complex service really easy. You can run a [Mattermost][5] or Discourse server in mere minutes. The hard part, in some cases, is managing and monitoring the containers once you have them running. Podman makes it easy to manage them, but what do use to manage Podman? Well, [you can use systemd][6].
Podman has a built-in command to generate unit files so your containers can be managed and monitored by systemd:
```
$ podman generate systemd --new --files --name example_pod
```
All you have to do then is start the service:
```
$ systemctl --user start pod-example_pod.service
```
As with any other service on your computer, systemd ensures that your pod runs no matter what. It logs problems, which you can view with `journalctl` along with your other essential logs, and you can monitor its activity within cgroups using `systemd-cgtop`.
It's no [Kubernetes platform][7], but for one or two containers that you just want to have available on a reliable and predictable basis, Podman and systemd are an amazing pair.
### Download the systemd eBook
There's a lot more to systemd, and you can learn the basics, along with lots of useful and pragmatic tips, from author [David Both][8] in his new complimentary **[pragmatic guide to systemd][1]**.
--------------------------------------------------------------------------------
via: https://opensource.com/article/23/3/3-things-you-didnt-know-systemd-could-do
作者:[Alan Smithee][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/alansmithee
[b]: https://github.com/lkxed/
[1]: https://opensource.com/downloads/pragmatic-guide-systemd-linux
[2]: https://www.redhat.com/sysadmin/cgroups-part-four?intcmp=7013a000002qLH8AAM
[3]: https://opensource.com/article/17/11/how-use-cron-linux
[4]: https://opensource.com/article/21/2/linux-automation
[5]: https://opensource.com/education/16/3/mattermost-open-source-chat
[6]: https://www.redhat.com/sysadmin/podman-run-pods-systemd-services?intcmp=7013a000002qLH8AAM
[7]: https://www.redhat.com/en/technologies/cloud-computing/openshift/aws?intcmp=7013a000002qLH8AAM
[8]: https://opensource.com/users/dboth

View File

@ -0,0 +1,61 @@
[#]: subject: "Open source tools for mind mapping"
[#]: via: "https://opensource.com/article/23/3/open-source-mind-mapping"
[#]: author: "Amrita https://opensource.com/users/amrita42"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Open source tools for mind mapping
======
In today's world and social media, many people don't have the patience to read lengthy textual content. Visuals are a great way to capture your audience's attention span.
Did you know that research at 3M Corporation concluded that visuals are processed 60,000 times faster than text? Visuals are more impactful than words and enhance creative thinking and memory.
### A picture is worth a thousand words
I looked at some of the common [Git commands][1]. I used Git commands as the main topic; each sub-topic is a Git command syntax with a definition. For this, I used Wisemapping.
![A git command mind map][2]
Whether you knew what a [mind map][3] was before or not, now that you've seen a mind map, you can now understand the concept.. That's the power of visuals.
### How do you create a mind map?
- Start with the main topic and place it in the middle of your drawing board.
- Create sub-topics and link them to the main topic.
- You can add details to each sub-topic, such as definitions, examples, etc.
### 3 open source tools you can use to create a mind map
Take a look at these three open source tools to create a visual of your idea:
- [Wisemapping][4]
- [Freeplane][5]
- [Semantik][6]
Wikipedia defines a mind map as a diagram to visually organize information into a hierarchy, showing relationships among pieces of the whole. Mind mapping starts with a central theme and then builds relations. It is a visual way to structure thoughts and create impactful presentations.
You can use mind maps in your work. For example, I used a mind map to show a high-level overview of features planned for a project. With these excellent open source mind mapping applications, it's easy to get started visualizing your next project. Try mapping your mind with open source.
--------------------------------------------------------------------------------
via: https://opensource.com/article/23/3/open-source-mind-mapping
作者:[Amrita][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/amrita42
[b]: https://github.com/lkxed/
[1]: https://opensource.com/downloads/cheat-sheet-git
[2]: https://opensource.com/sites/default/files/2023-03/mindmap.jpg
[3]: https://opensource.com/article/21/12/open-source-mind-mapping-drawio
[4]: https://www.wisemapping.com/
[5]: https://opensource.com/article/19/1/productivity-tool-freeplane
[6]: https://waf.io/semantik.html

View File

@ -1,148 +0,0 @@
[#]: subject: "Learn everything about computers with this Raspberry Pi kit"
[#]: via: "https://opensource.com/article/21/9/raspberry-pi-crowpi2"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "XiaotingHuang22"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Learn everything about computers with this Raspberry Pi kit 用树莓派了解关于计算机的一切
======
CrowPi 是一个超棒的树莓派项目系统,安装在一个笔记本电脑般的外壳里。
![老师还是学习者?][1]
我喜欢历史,也喜欢计算机,因此相比于计算机如何变成个人配件,我更喜欢听它在成为日常家用电器前的有关电脑运算的故事。 [我经常听到的一个故事][2] 是关于很久以前(反正在计算机时代算久远了)的计算机是如何的基础却又让人感到很舒服。事实上,它们基础到对于一个好奇的用户来说,弄清楚如何编程是相对简单的事情。看看现代计算机,它具有面向对象的编程语言、复杂的 GUI 框架、网络 API、容器等但愈发令人担忧的是对于那些没有接受过任何专门培训的人计算行业的工具正变得越来越难懂无法为任何未经专门培训的人所用。
从 Raspberry Pi 在 2012 年发布之日起,它就一直被定位为一个教育平台。 一些第三方供应商通过附加组件和培训套件支持 Pi以帮助所有年龄段的学习者探索编程、物理计算和开源。 然而,直到最近,很大程度上还是要由用户来弄清楚市场上的所有部件如何组合在一起,直到我最近买了 CrowPi。
![CrowPi ——不只是一个笔记本电脑][3]
CrowPi 不是一个笔记本电脑。
(Seth Kenlon, [CC BY-SA 4.0][4])
### 隆重介绍 CrowPi2
乌鸦是非常聪明的鸟。 他们识别并记住面孔,模仿听到的声音,解决复杂的谜题,甚至使用工具来完成任务。 CrowPi 使用乌鸦作为其徽标和同名词是恰当的,因为这个设备提供了无限探索、实验、教育还有最重要的,乐趣的机会。
设计本身很巧妙:它看起来像笔记本电脑,但远不止于此。 当你从外壳中取出蓝牙键盘时,它会显示一个隐藏的电子设备工坊,配有 LCD 屏幕、16 个按钮、刻度盘、RFID 传感器、接近传感器、线路板、扬声器、GPIO 连接、LED 阵列等等。 _而且都是可编程的。_
顾名思义,该装置本身完全由 Raspberry Pi 供电,牢固地固定在外壳底部。
![crowpi pi板[5]
CrowPi 的 Pi板
(Seth Kenlon, [CC BY-SA 4.0][4])
默认情况下,你应该用电源适配器为设备充电,包装附带一个壁式适配器,你可以将其插入外壳,而不是直接为 Pi 供电。 您还可以使用插入外部微型 USB 端口的电池电源。 电脑外壳内甚至还有一个抽屉,方便你存放电池。 存放电池时有一根 USB 线从电池抽屉中弹出并插入机箱电源端口,因此你不会产生这是一台“普通”笔记本电脑的错觉。 然而,这样一台设备能够有如此美观的设计已经很理想了!
### 首次启动系统
CrowPi2 提供一张安装了 Raspbian 系统,卡上贴有 **System** 的标签,不过它同时还提供一张装载了 [RetroPie][6] 的 microSD 卡。 作为一个负责任的成年人(咳咳),我自然是先启动了 RetroPie。
RetroPie 总是很有趣CrowPi2 附带两个 SNES 风格的游戏控制器,确保你能获得最佳的复古游戏体验。
令人赞叹不已的是,实际启动系统的过程同样有趣,甚至可以说更有趣。 它的登录管理器是一个自定义项目中心快速链接到一些编程体验项目、Python 和 Arduino IDE、Scratch、 Python 体验游戏、Minecraft 等。 你也可以选择退出项目中心,只使用桌面。
![CrowPi 中心][7]
The CrowPi 中心.
(Seth Kenlon, [CC BY-SA 4.0][4])
对于习惯使用 Raspberry Pi 或 Linux 的人来说CrowPi 桌面很熟悉,不过它也足够基础,所以很容易上手。 左上角有应用程序菜单,桌面上有快捷图标,右上角有网络选择和音量控制的系统托盘等等。
![CrowPi 桌面][8]
CrowPi 桌面.
(Seth Kenlon, [CC BY-SA 4.0][4])
CrowPi 上提供了很多东西选择,所以你可能很难决定从哪里开始。 对我来说主要分为四大类编程、物理电子学、Linux 和游戏。
盒子里有一本使用说明,所以你才知道你需要怎样进行连接(例如,键盘是电池供电的,所以它有时确实需要充电,它和鼠标总是需要一个 USB 适配器)。 虽然说明书很快就能读完,但这一例子也充分体现了 CrowPi 团队是如何认真对待说明书的。
![CrowPi 文档][9]
CrowPi 文档.
(Seth Kenlon, [CC BY-SA 4.0][4]
### 编程
如果你热衷于学习如何编码,在 CrowPi 上有很多途径助你成功。你应该从中选择你觉得最满意的路径。
#### 1\. Scratch
[Scratch][10] 是一个简单的视觉编码应用程序,可让你像拼 [Lego pieces 乐高拼块][11] 一样将代码块组合在一起,制作出游戏和互动故事。 这是开启编程之旅最简单的方法,我曾见过年仅 8 岁的孩子会花数小时思考自己设计的游戏的最佳算法。 当然,它不仅适合孩子们!成年人也可以从中获得很多乐趣。 不知道从哪里开始? 包装盒中有一本 99 页的小册子(打印在纸张上),其中包含 Scratch 课程和项目供你尝试。
#### 2\. Java 和 Minecraft
Minecraft 不是开源的(虽然有 [几个开源项目][12] 复刻了它),但它有足够的可用资源,因此也经常被用来教授编程。 Minecraft 是用 Java 编写的CrowPi 同时装载有 [Minecraft Pi Edition][13] 和 [BlueJ Java IDE][14] ,如此可使学习 Java 变得比以往更容易、更有趣。
#### 3\. Python 和 PyGame
CrowPi 上有几个非常有趣的游戏,它们是用 Python 和 [PyGame game engine PyGame 游戏引擎)][15] 编写的。 你可以玩游戏,然后查看源代码以了解游戏的运行方式。 CrowPi 中包含 Geany、Thonny 和 [Mu][16] 编辑器,因此您可以立即开始使用 Python 进行编程。 与 Scratch 一样,包装盒中有一本包含课程的小册子,因此你可以学习 Python 基础知识。
### 电子器件
隐藏在键盘下的物理电子工坊本质上是一系列 Pi Hats附着在上的硬件。 为了让你可以认识所有的组件CrowPi 绘制了一张中英双语的折叠图进行详细的说明。 除此之外还有很多示例项目可以帮助你入门。 以下是一张小清单:
* **你好** 当你与 CrowPi 说话时LCD 屏幕上打印输出“你好”。
* **入侵警报**使用接近传感器发出警报。
* **远程控制器** 让你能够使用远程控制(是的,这个也包含在盒子里)来触发 CrowPi 上的事件。
* **RGB 俄罗斯方块** 让你可以在 LED 显示屏上玩俄罗斯方块游戏。
* **语音识别**演示自然语言处理。
* **超声波音乐** 利用距离传感器和扬声器创建简易版的特雷蒙琴(世上唯一不需要身体接触的电子乐器)。
这些项目仅仅是入门级别而已,因为你还可以在现有的基础上搭建更多东西。 当然,还有更多内容值得探索。 包装盒里还有网络跳线、电阻器、LED 和各种组件,这样你闲暇时也可以了解 Pi 的 GPIO (通用输入输出端口)功能的所有信息。
不过我也发现了一个问题:示例项目的位置有点难找。 找到演示很容易(它们就在 CrowPi 中心上),但源代码的位置并不是很容易被找到。 我后来发现大多数示例项目都在 `/usr/share/code` 中,你可以通过文件管理器或终端进行访问。
![CrowPi 外围设备][17]
CrowPi 外围设备
(Seth Kenlon, [CC BY-SA 4.0][4])
### Linux
Raspberry Pi 上运行 Linux 系统。 如果你一直想更深入了解 Linux那么 CrowPi 同样会是一个很好的平台。 你可以探索 Linux 桌面、终端以及几乎所有 Linux 或开源应用程序。 如果你多年来一直在阅读有关开源的文章,并准备深入研究开源操作系统,那么 CrowPi 会是你想要的平台(当然还有很多其他平台也可以)。
### 游戏
包装盒中包含的 **RetroPie** SD 卡意味着你可以重新启动,切换为复古游戏机并任意玩各种老式街机游戏。 它跟 Steam Deck 并不完全相同,但也是一个有趣且令人振奋的小游戏平台。 因为它配备的不是一个而是两个游戏控制器,所以它非常适合多人合作的沙发游戏。 最重要的是,你不仅可以在 CrowPi 上玩游戏,还可以制作自己的游戏。
### 配备螺丝刀
自我坐下开始使用 CrowPi2 以来已经大约两周,但我还没有通关所有项目。 有很多个晚上,我不得不强迫自己停下摆弄它,因为即使我厌倦了一个项目,我也会不可避免地发现还有其他东西可以探索。 文章的最后做个总结,我在盒子里找到了一个特别的组件,这个组件让我马上知道 CrowPi 和我就是天造地设:它是一把不起眼的小螺丝刀。 盒子上的保修标签不存在作废。 CrowPi 希望你去修补、拆解、探索和学习。 它不是笔记本电脑,甚至也不是 Pi 而是一个便携、低功耗、多样化和开源的学习者工具包。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/9/raspberry-pi-crowpi2
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[XiaotingHuang22](https://github.com/XiaotingHuang22)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/osdc-lead-teacher-learner.png?itok=rMJqBN5G (Teacher or learner?)
[2]: https://opensource.com/article/21/8/my-first-programming-language
[3]: https://opensource.com/sites/default/files/crowpi-not-laptop.jpeg (CrowPi more than a laptop)
[4]: https://creativecommons.org/licenses/by-sa/4.0/
[5]: https://opensource.com/sites/default/files/crowpi-pi.jpeg (crowpi pi board)
[6]: https://opensource.com/article/19/1/retropie
[7]: https://opensource.com/sites/default/files/crowpi-hub.png (CrowPi hub)
[8]: https://opensource.com/sites/default/files/crowpi-desktop.png (CrowPi desktop)
[9]: https://opensource.com/sites/default/files/crowpi-docs.jpeg (CrowPi docs)
[10]: https://opensource.com/article/20/9/scratch
[11]: https://opensource.com/article/20/6/open-source-virtual-lego
[12]: https://opensource.com/alternatives/minecraft
[13]: https://www.minecraft.net/en-us/edition/pi
[14]: https://opensource.com/article/20/7/ide-java#bluej
[15]: https://opensource.com/downloads/python-gaming-ebook
[16]: https://opensource.com/article/18/8/getting-started-mu-python-editor-beginners
[17]: https://opensource.com/sites/default/files/crowpi-peripherals.jpeg (CrowPi peripherals)

View File

@ -1,114 +0,0 @@
[#]: subject: "A Guide to Find the Right Debian ISO for Download"
[#]: via: "https://www.debugpoint.com/download-debian-iso/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "robsean"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
一篇找到合适的 Debian ISO 的下载指南
======
**Linux 初学者可能会被官方的 Debian 下载 ISO 的页面所压垮。这篇指南旨在简化下载体验。**
对于 Debian 初学者来说,安装 Debian 可能会是一次艰难的经历。官方的下载页面包含一些链接,以至于到底需要下载哪个令人困惑。
我准备这篇指南来帮助你直接从下载页面下载恰当的 Debian ISO 文件。
总的来说,你可以将 Debian ISO 文件分为两大类。它们是 “自由” 和 “非自由” 。
### 关于 “自由” 和 “非自由” Debian 镜像之间的一些注意事项
- Debian “非自由” 镜像涉及 Debian 操作系统的安装镜像,它包含不遵循 Debian 自由软件包包指南的软件包。
- “非自由” 软件包包含的软件是专有的、受版权保护的或受许可限制的这些软件包禁止用户修改或分发代码。Debian 工程提供这些 “非自由” 镜像作为用户的一种可选下载项,这些用户需要依靠专有的设备驱动程序或固件来使用特定的硬件设备或软件包
- “自由” 版本的 Debian ,仅包含开源和可自由分发的软件包,这意味着用户有修改、分发和他人共享的自由,而没有任何法律和道德上的约束。
Debian 12 Bookworm 正在开发 (即将发布),非自由固件软件包将正式包含在主 ISO 文件中。因此,这篇指南将分为两个部分。
### 下载: Debian 12 Bookworm
这里是一份下载 Debian ISO 版本 12 Bookworm 的简单的表格 (当前上不稳定,正在测试)。
| **描述** | **最大 ISO 体积** | **选择此 ISO ,如果** | **ISO 下载****链接****(amd64)** |
| :- | :- | :- | :- |
| > 最小的体积> 非常适合最基础的安装 | 700 MB | 你想下载基础的软件包,然后不使用因特网来安装 | [iso-cd][1] |
| > 完整的 DVD 体积 | 5 GB | 你想先下载所有的东西,然后开始安装,它非常适合离线安装 | [iso-dvd][2] |
### 下载: Debian 11 Bullseye
#### 自由的 ISO 文件 (没有专有软件包)
下面的 ISO 镜像是 “**自由的**” 镜像,这意味着他们不包含很多针对固件的专有软件包。
| **描述** | **最大 ISO 体积** | **选择此 ISO ,如果** | **ISO 下载****链接****(amd64)** |
| :- | :- | :- | :- |
| > 最小的体积 (网络安装 CD)> 安装软件包时,需要联通因特网 | 500 MB | 你有稳定高速的因特网,希望较少的初始下载 | [iso-cd][3] [torrent][4] |
| > 完整的 CD 体积> 由附属的 CD 1、2 和 3 组成> 对于最基础的安装,你只需要 CD 1 | 700 MB | 你希望下载基础的软件包,然后不使用因特网来安装它们 | [iso-cd][5] [torrent][6] |
| > 完整的 DVD 体积> 由附属的 DVD 1、2 和 3 组成> 对于最基础的安装,你只需要 DVD 1 | 5 GB | 你想先下载所有的东西,然后开始安装,这是离线安装的最理想方式 | [iso-dvd][7] [torrent][8] |
#### 非自由的 ISO 文件 (带有专有软件包)
如果你有特殊的硬件例如Wi-Fi 、蓝牙等等 你可能会希望从下面的表中获取 **“非自由”** 版本的软件包。
| **类型** | **镜像种类** | **选择此 ISO ,如果** | **ISO 下载链接 (amd64)** |
| :- | :- | :- | :- |
| 非自由 | 完整的 CD 、DVD | 你想要减少工作量,并希望 Debian 能够在所有受支持的硬件上工作 | [cd-dvd][9]_(转到非自由目录)_ |
| 非自由 | 完整的 CD 、DVD (LIVE) 独立的桌面环境软件包 | 你想要减少工作量Debian 能够工作,并且带有一个 LIVE 系统。LIVE 系统也提供完整的安装 | [cd-dvd-live][9]_(转到非自由目录)_ |
### 其它的架构
#### 针对 Debian 11 Bullseye:
- [arm64][10]
- [armel][11]
- [armhf][12]
- [i386][13]
- mips (不可用)
- [mips64el][14]
- [mipsel][15]
- [ppc64el][16]
- [s390x][17]
所有的镜像,下载链接: [单击这里][18]
### 较旧的版本 (Debian 10 Buster)
如果你需要一些针对 Debian Buster 10 的镜像,访问这个 [页面][19] 。
### 总结
对新用户来说,如果想要从官方网站上下载 Debian ISO 镜像,网站的信息可能太过冗余。因此,我以一种恰当的格式总结下载链接。我希望这篇文章有助于你找到适合于你系统的目标 Debian ISO 镜像。
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/download-debian-iso/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://cdimage.debian.org/cdimage/bookworm_di_alpha2/amd64/iso-cd/
[2]: https://cdimage.debian.org/cdimage/bookworm_di_alpha2/amd64/iso-dvd/
[3]: https://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/
[4]: https://cdimage.debian.org/cdimage/release/current/amd64/bt-cd/
[5]: https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/
[6]: https://cdimage.debian.org/debian-cd/current/amd64/bt-cd/
[7]: https://cdimage.debian.org/cdimage/release/current/amd64/iso-dvd/
[8]: https://cdimage.debian.org/cdimage/release/current/amd64/bt-dvd/
[9]: https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/
[10]: http://ftp.debian.org/debian/dists/bullseye/main/installer-arm64/current/images/
[11]: http://ftp.debian.org/debian/dists/bullseye/main/installer-armel/current/images/
[12]: http://ftp.debian.org/debian/dists/bullseye/main/installer-armhf/current/images/
[13]: http://ftp.debian.org/debian/dists/bullseye/main/installer-i386/current/images/
[14]: http://ftp.debian.org/debian/dists/buster/main/installer-mips64el/current/images/
[15]: http://ftp.debian.org/debian/dists/bullseye/main/installer-mipsel/current/images/
[16]: http://ftp.debian.org/debian/dists/bullseye/main/installer-ppc64el/current/images/
[17]: http://ftp.debian.org/debian/dists/bullseye/main/installer-s390x/current/images/
[18]: https://cdimage.debian.org/cdimage/
[19]: https://www.debian.org/releases/buster/debian-installer/