Flake usage/understanding - installation

Hello,

I wish to give a try to NixOs (I’ve never used it before). But before that I’m trying to learn as much as I can. I come from ArchLinux.

I sometimes spend some on reddit/unixporn and a lot of people using NixOs seeam to be using flakes in their dotfiles.

I’m trying to understand the concept of it. From what I understand and don’t:

  • It’s purpose is mostly used when installing NixOs (am I right ? can it be used once NixOs has been installed to setup the environment (ex: softwares/packages) ?)
  • If flakes aren’t meant to setup the desired packages and configurations once NixOs has been installed would the home-manager be a better fit for managing my environment (packages + configurations) ?
  • How does one use it/install/deploy it ? I’ve search for nix install but nothing about flake ?

More generally speaking, is NixOs “cleaner” than other distributions ? From what I’ve read and my research, since most of the configuration contains the packages to install, it seems to be very easy to keep track of the installed packages and then be able to uninstall unused packages ? Is my observation correct ?

Thank you very much in advance for any help

Hello !

Installing a NixOS system from flake is only one of many things flakes were designed for.

You can use a flake to install your system, and use home-manager to manage your environment.

To setup a NixOS system from flakes, I think this book is good: Enabling NixOS with Flakes | NixOS & Flakes Book (you might want to read the previous chapters)

Yes, but one usually don’t “uninstall” packages. They can be removed from the list of things to install in the next generation instead.

2 Likes

Hello,

Thank you for taking the time to answer me with all the details.

Installing a NixOS system from flake is only one of many things flakes were designed for.

Are there any more detailed ressources on this subject ?

They can be removed from the list of things to install in the next generation instead.

What do you mean by “the next generation” ? Do you mean the next version ?

To setup a NixOS system from flakes, I think this book is good: Enabling NixOS with Flakes | NixOS & Flakes Book (you might want to read the previous chapters)

Thank you for the link

You can use a flake to install your system, and use home-manager to manage your environment.

Is this pargraph the right one ? Especially on how to install/build/deploy the home-manager configuration ? (ex. from a git repository)

Thank you very much in advance for all your help

Think of flakes as a starting point into a Nix codebase.

e.g. in NodeJS projects, you might call npm run ... and it will look at a package.json for details on how to work with the codebase. Or in Rust, a Rust codebase is managed with cargo which uses cargo.toml.

What a Nix flake provides is essentially a declaration of dependencies, a declaration of outputs the project provides (such as NixOS configurations, or packages, and some other things).

What makes NixOS unique is that it’s built around the Nix package manager. The Nix package manager is unique in that it doesn’t install packages globally, but instead each package is stored in an isolated way. – The Nix package manager allows for all kinds of neat use cases because of this; but it’s also very unusual compared to what other system package managers traditionally do.

A common example of a benefit is that e.g. since NixOS’s system configuration is built as a Nix package… it’s easy to “roll back” to previous versions of a system configuration. (Each build of the configuration is stored separately from each other, and the system boots from the latest one; or it’s easy to “roll back” by just selecting a previous build of the configuration).

The effect is loosely comparable to different versions of a Docker image. You might run a Docker image of ubuntu:latest, and then pull a more recent version of ubuntu:latest, but the two versions are available to run. The older image doesn’t get “replaced”, but the tag “ubuntu:latest” instead refers to a different image.

e.g. if you install NixOS and that uses Gnome DE, then you change the configuration file to use Xfce, then applying this configuration involves building a new NixOS ‘generation’ & having the system use this. (“version” is another word that would make sense, sure, but “version” more usefully refers to the version of software being used).

2 Likes

Flakes are an experimental feature of Nix @CoreDump, and as a beginner you don’t need to worry about them. I would recommend learning the Nix expression language first and building some packages like GNU Hello on your Arch system. If you already know how to program, Learn X in Y Minutes provides a quickstart guide to learning the Nix language. Once you feel comfortable with the basic Nix concepts, you can install NixOS in a virtual machine (for example, NixOS provides a VirtualBox demo ready-to-go) and see if it seems “cleaner” to you. After you get comfortable with standard Nix, the tradeoffs associated with various experimental features will be easier to understand and evaluate for your use-case.

2 Likes

@rgoulter @nat-418

Sorry for the long wait and thank you very much for all your great help.

I took some time to look into further research while reading your answers. I feel I have gathered a lot more knowledge now.

Thank you very much

1 Like