[#]: 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