diff --git a/sources/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md b/sources/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md deleted file mode 100644 index 84e476823c..0000000000 --- a/sources/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md +++ /dev/null @@ -1,166 +0,0 @@ -Martin translating - -NixOS Linux Lets You Configure Your OS Before Installing -============================================================ - -![NixOS](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/configuration.jpg?itok=IjKuFz05 "NixOS") -Configuration is key to a successful installation of NixOS.[Creative Commons Zero][4]Pixabay - -I’ve been using Linux for a very long time. Over the years, I’ve been incredibly happy with how the open source landscape has evolved. One particular area that has come quite a long way is the installation of various distributions. Once upon a time, installing Linux was a task best left to those who had considerable tech skills. Now, if you can install an app, you can install Linux. It’s that simple. And that, my friends, is a very good thing—especially when it comes to drawing in new users. The fact that you can install the entire Linux operating system faster than a Windows user can run an update says quite a bit. - -But every so often, I like to see something different—something that might remind me from where I came. That’s exactly what happened when I came into [NixOS][9]. To be quite honest, I had assumed this would be just another Linux distribution that offered the standard features, with the KDE Plasma 5 interface. - -Boy was I wrong. - -After [downloading the ISO image][10], I figured up [VirtualBox][11] and created a new virtual machine, using the downloaded image. Once the VM booted, I found myself at a Bash login instructing me that the root account had an empty password and how to start a GUI display manager (Figure 1). - -### [nixos_1.jpg][5] - -![First contact](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_1.jpg?itok=VkGTO2Tg "First contact") - -Figure 1: The first contact with NIXOS might be a bit jarring for some.[Used with permission][1] - -“Okay,” I thought, “let’s fire this up and see what happens.” - -Once the GUI was up and running (KDE Plasma 5), I didn’t see the usual “Install” button. Turns out, NixOS is one of those fascinating distributions that has you configure your OS before you install it. Let’s take a look at how that is done. - -### Pre-install configuration - -The first thing you must do is create a partition. Since the NixOS installer doesn’t include a partition tool, you can fire up the included GParted application (Figure 2) and create an EXT4 partition. - -### [nixos_2.jpg][6] - -![Partitioning](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_2.jpg?itok=nta-bl-S "Partitioning") - -Figure 2: Partitioning the drive before installation.[Used with permission][2] - -With your partition created, mount it with the command  _mount /dev/sdX /mnt _ (Where sdX is the location of your newly created partition). - -You now must generate a configuration file. To do this, issue the command: - -``` -nixos-generate-config --root /mnt -``` - -The above command will create two files (found in the  _/mnt/etc/nixos_ directory): - -* configuration.nix — The default configuration file. - -* hardware-configuration.nix — The hardware configuration (this is not to be edited). - -Issue the command  _nano /mnt/etc/nixos/configuration.nix_ . Within this file, we need to take care of a few edits. The first change is to set the option for the boot loader. Look for the line: - -``` -# boot.loader.grub.device = “/dev/sda”; # or “nodev” for efi only -``` - -Remove the # sign at the beginning of the line to uncomment this option (making sure /dev/sda is the name of your newly created partition). - -Within the configuration file, you can also set your timezone and add packages to be installed. You will see a commented out sample for package installation that looks like: - -``` -# List packages installed in system profile. To search by name, run: - -# nix-env -aqP | grep wget - -# environment.systemPackages = with pkgs; [ - -# wget vim - -# ]; -``` - -If you want to add packages, during installation, comment out that section and add the packages you like. Say, for instance, you want to add LibreOffice into the mix. You could uncomment the above section to reflect: - -``` -# List packages installed in system profile. To search by name, run: - -nix-env -aqP | grep wget - -environment.systemPackages = with pkgs; [ - -libreoffice wget vim - -]; -``` - -You can find the exact name of the package by issuing the command  _nix-env -aqP | grep PACKAGENAME _ (where PACKAGENAME is the name of the package you’re looking for). If you don’t want to issue the command, you can always search the [NixOS packages database.][12] - -After you’ve added all the necessary packages, there is one more thing you must do (if you want to be able to log into the desktop. I will assume you’re going to stick with the KDE Plasma 5 desktop. Go to the bottom of the configuration file and add the following before the final } bracket: - -``` -services.xserver = { - - enable = true; - - displayManager.sddm.enable = true; - - desktopManager.plasma5.enable = true; - -}; -``` - -You can find out more options for the configuration file, within the [NixOS official documentation][13]. Save and close the configuration file. - -### Installation - -Once you have your configuration exactly how you like it, issue the command (as the root user) nixos-install. Depending upon how many packages you’ve included for installation, the time it takes to complete this task will vary. When it does complete, you can then issue the command reboot and you will (when the reboot completes) be greeted by the KDE Plasma 5 login manager (Figure 3). - -### [nixos_3.jpg][7] - -![KDE Plasma 5](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_3.jpg?itok=DdsB5opR "KDE Plasma 5") - -Figure 3: The KDE Plasma 5 login manager.[Used with permission][3] - -### Post-install - -One of the first two things you’ll need to do is give the root user a password (issue the command  _passwd_  to change the default) and add a standard user. This is done as you would with any Linux distribution. Log in as the root user and then, at a terminal window, issue the command: - -``` -useradd -m USER -``` - -Where USER is the name of the user you want to add. Next give the user a password with the command: - -``` -passwd USER -``` - -Where USER is the name of the user just added. You will be prompted to type and verify the new password. You can then log into NixOS as that standard user. - -Once you have NixOS installed and running, you can then add new packages to the system, but not via the standard means. If you find you need to install something new, you have to go back to the configuration file (which is now located in  _/etc/nixos/_ ), add the packages in the same location you did prior to installation, and then issue the command (as root): - -``` -nixos-rebuild switch -``` - -Once the command completes, you can then use the newly installed packages. - -### Enjoy NixOS - -At this point, NixOS is up and running, with all the software you need and the KDE Plasma 5 desktop interface. Not only have you installed Linux, but you’ve installed a Linux distribution customized to meet your exact needs. Enjoy the experience and enjoy NixOS. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/learn/intro-to-linux/2017/10/nixos-linux-lets-you-configure-your-os-installing - -作者:[JACK WALLEN][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/jlwallen -[1]:https://www.linux.com/licenses/category/used-permission -[2]:https://www.linux.com/licenses/category/used-permission -[3]:https://www.linux.com/licenses/category/used-permission -[4]:https://www.linux.com/licenses/category/creative-commons-zero -[5]:https://www.linux.com/files/images/nixos1jpg -[6]:https://www.linux.com/files/images/nixos2jpg -[7]:https://www.linux.com/files/images/nixos3jpg -[8]:https://www.linux.com/files/images/configurationjpg -[9]:https://nixos.org/ -[10]:https://nixos.org/nixos/download.html -[11]:https://www.virtualbox.org/wiki/Downloads -[12]:https://nixos.org/nixos/packages.html -[13]:https://nixos.org/nixos/manual/index.html#ch-configuration diff --git a/translated/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md b/translated/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md new file mode 100644 index 0000000000..fde6029f6e --- /dev/null +++ b/translated/tech/20171013 NixOS Linux Lets You Configure Your OS Before Installing.md @@ -0,0 +1,165 @@ +让我们和 NixOS Linux 一起在安装前配置 OS +============================================================ + +![NixOS](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/configuration.jpg?itok=IjKuFz05 "NixOS") + +配置是成功安装 NixOS 的关键。[Creative Commons Zero][4]Pixabay + +我用 Linux 有些年头了。在这些年头里我很有幸见证了开源的发展。各色各样的发行版在安装方面的努力,也是其中的一个比较独特的部分。以前,安装 Linux 是个最好让有技术的人来干的任务。现在,只要你会装软件,你就会安装 Linux。简单,并且,不是我吹,在吸引新用户方面效果拔群。事实上相较于 Windows 你可以更快的完成整个 Linux 操作系统的安装,更新也更快点。 + +即使很频繁,我也乐得见到其中有所不同——让我知道我从哪来,要干啥。[NixOS][9] 在这方面就做的别具一格。讲真,我原来也就把它当作另一个提供标准特性和 KDE Plasma 5 界面的 Linux 发行版。 + +好像也没什么不对。 + +[下载 ISO 映像][10]后,我启动了 [VirtualBox][11] 并用下载的镜像创建了个新的虚拟机。VM 启动后,出来的是 Bash 的登录界面,界面上指导我用空密码去登录 root 账号,以及我该如何启动 GUI 显示管理器(图 1)。 + +### [nixos_1.jpg][5] + +![First contact](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_1.jpg?itok=VkGTO2Tg "First contact") + +图 1: 与 NixOS 的初次接触可能不是太和谐。[使用许可][1] + +“好吧”我这样想着,“打开看看吧!” + +GUI 启动和运行(KDE Plasma 5)时,我没找到喜闻乐见的“安装”按钮。原来,NixOS 是一个在安装前需要你配置的发行版,真有趣。那就让我们瞧瞧它是如何做到的吧! + +### 安装前配置 + +你需要做的第一件事是建分区。由于 NixOS 安装程序不包含分区工具,你得用自带的 GParted (图 2)来创建一个 EXT4 分区。 + +### [nixos_2.jpg][6] + +![Partitioning](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_2.jpg?itok=nta-bl-S "Partitioning") + +图 2: 安装前的分区。[使用许可][2] + +创建好分区,然后用命令 _mount /dev/sdX /mnt _ 挂载。(请自行替换 sdX 为你新创建的分区)。 + +你现在需要创建一个配置文件。命令如下: + +``` +nixos-generate-config --root /mnt +``` + +上面的命令会创建两个文件(存放在目录 _/mnt/etc/nixos_ 中): + +* configuration.nix — 默认配置文件。 + +* hardware-configuration.nix — 硬件配置(无法编辑) + +通过命令 _nano /mnt/etc/nixos/configuration.nix_ 打开文件。其中有一些需要编辑的地方得注意。第一个改动便是设置启动选项。找到行: + +``` +# boot.loader.grub.device = “/dev/sda”; # or “nodev” for efi only +``` + +删除行首的 # 使该选项生效(确保 /dev/sda 与是新建分区一致)。 + +通过配置文件,你可以设置时区和追加要安装的软件包。来看一个被注释掉的安装包的示例: + +``` +# List packages installed in system profile. To search by name, run: + +# nix-env -aqP | grep wget + +# environment.systemPackages = with pkgs; [ + +# wget vim + +# ]; +``` + +如果你想要添加软件包,并在安装时安装它们,那就取消掉这段注释,并添加你需要的软件包。举个例子,比方说你要把 LibreOffice 加进去。示例详见下方: + +``` +# List packages installed in system profile. To search by name, run: + +nix-env -aqP | grep wget + +environment.systemPackages = with pkgs; [ + +libreoffice wget vim + +]; +``` + +你可以通过输入命令 _nix-env -aqP | grep PACKAGENAME _ 来寻找确切的包名(PACKAGENAME 为你想要找的软件包)。如果你不想输命令,你也可以检索 [NixOS 的软件包数据库][12]。 + +在你把所有的软件包都添加完后,你还有件事儿需要做(如果你想要登录到桌面的话,我觉得你还得折腾下 KDE Plasma 5 桌面)。翻到配置文件的末尾并在最后的 } 符号前,追加如下内容: + +``` +services.xserver = { + + enable = true; + + displayManager.sddm.enable = true; + + desktopManager.plasma5.enable = true; + +}; +``` + +在 [NixOS 官方文件][13] 中,你能找到配置文件中更多的选项。保存并关掉配置文件。 + +### 安装 + +在你按照自己的需求完善好配置之后,使用命令(需要 root 权限) nixos-install。完成安装所需要的时间,会随着你加入的软件包多少有所区别。安装结束后,你可以使用命令重启系统,(重启之后)迎接你的就是 KDE Plasma 5 的登录管理界面了(图 3)。 + +### [nixos_3.jpg][7] + +![KDE Plasma 5](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/nixos_3.jpg?itok=DdsB5opR "KDE Plasma 5") + +图 3: KDE Plasma 5 登录管理界面[使用许可][3] + +### 安装后 + +你要首先要做的两件事之一便是给 root 用户设个密码(通过输入命令 _passwd_ 来修改默认的密码),以及添加一个标准用户。做法和其它的 Linux 发行版无二。用 root 用户登录,然后在终端输入命令: + +``` +useradd -m USER +``` + +将 USER 替换成你想要添加的用户名。然后通过下面的命令给用户设上密码: + +``` +passwd USER +``` + +同样的将 USER 替换成你添加的用户。然后会有提示引导你填写并验证新密码。然后,你就能用标准用户登录 NixOS 啦。 + +NixOS 在你安装并运行后,你可以为系统添加新的软件包,但并非通过寻常的方式。如果你发现你需要安装些新东西,你得回到配置文件(位置就是 _/etc/nixos/_ ),找到之前安装时添加软件包的位置,运行以下命令(需要 root 权限): + +``` +nixos-rebuild switch +``` + +命令执行结束后,你就能使用新安装的软件包了。 + +### Enjoy NixOS + +现在,NixOS 已经带着所有你想安装的软件和 KDE Plasma 5 桌面运行起来了。要知道,你所做的不仅仅只是安装了个 Linux 发行版,关键是你自定义出来的发行版非常符合你的需求。所以好好享受你的 NixOS 吧! + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/learn/intro-to-linux/2017/10/nixos-linux-lets-you-configure-your-os-installing + +作者:[JACK WALLEN][a] +译者:[martin2011qi](https://github.com/martin2011qi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/jlwallen +[1]:https://www.linux.com/licenses/category/used-permission +[2]:https://www.linux.com/licenses/category/used-permission +[3]:https://www.linux.com/licenses/category/used-permission +[4]:https://www.linux.com/licenses/category/creative-commons-zero +[5]:https://www.linux.com/files/images/nixos1jpg +[6]:https://www.linux.com/files/images/nixos2jpg +[7]:https://www.linux.com/files/images/nixos3jpg +[8]:https://www.linux.com/files/images/configurationjpg +[9]:https://nixos.org/ +[10]:https://nixos.org/nixos/download.html +[11]:https://www.virtualbox.org/wiki/Downloads +[12]:https://nixos.org/nixos/packages.html +[13]:https://nixos.org/nixos/manual/index.html#ch-configuration