Help needed in building a distro based on NixOS

Greetings everyone!

This is my first post and I hope I am posting it in the right section. I want to create a new distro, based on NixOS. Regarding the same, I have many questions, but let me start with a few basic ones:

  1. How do I build a default NixOS ISO, similar to the one we can download from the website. I understand the code is available here and here.

  2. Once I can build the default ISO, I will try to change the parts that I need.

  3. How do I copy files in /etc/skel or any other folder in the ISO when building it? The purpose is to copy configuration files in the distro’s ISO

  4. How can I install flatpaks inside the iso? (or run any other command for the ISO) Note, I am not talking about installing flatpaks after installing the iso, but to bake them in the ISO itself. In other words, run

flatpak install flathub org.kde.kleopatra -y

During the ISO build process, so when the user will install the ISO, the Flatpak will already be there.

Answer to any of these questions will be appreciated. Thanks in advance.

2 Likes

The NixOS manual has a section on building ISOs for Live systems:

1 Like

Hi wamserma,

Thanks for your reply. I tried it, and I was able to build an ISO. But it was not the one which is distributed publically. The one I got only booted in a terminal. It did not launch gnome and Calamares like the public ISO does.

Do let me know if there is any way to find out how the NixOS team is generating the ISO that they publically distribute.

Thanks.

I recently created a customized spin of NixOS like this:

  • having a module that makes use of the already liked installation CD module and my flakes configurations
  • having an installer which installs a template of the flake with a few custom settings
  • building the ISO via nixos-generators module
    nix build .#nixosConfigurations.dr460nixed-desktop.config.formats.install-iso
    

I don’t know whether this is following best practices, it works well for my use case however.

Building custom iso is easy:

  1. Install NixOS
  2. Configure it how you like by writing configuration.nix
  3. Reuse your configuration when building an iso: Creating a NixOS live CD - NixOS Wiki

How can I install flatpaks inside the iso?

I don’t think it’s possible. Use nix instead

2 Likes

Thank you everyone for your helpful answers.

I am coming from an imperative background and have some experience in building Fedora distributions. In Fedora, we create a mock chroot and then modify the iso as needed using a kickstart file.

I understand that NixOS is declarative. Towards the same, I have the following questions/observations:

  1. I am OK with not installing flatpaks in the ISO. I will miss the permissions, but it’s not a dealbreaker for me.

  2. During the customization of the ISO, certain files need to be copied into some of the chroot folders, such as:
    /etc/skel

/etc/xdg/autostart
/etc/xdg/xfce4/

/usr/local/bin

/usr/share/

/var/lib/

So, how can I copy my own custom files and folders inside the ISO when building it, in folders shown above? Or in general, how to copy files/folders inside the ISO? What are the best practices?

Thanks again.:pray:t4:

So, how can I copy my own custom files and folders inside the ISO when building it, in folders shown above? Or in general, how to copy files/folders inside the ISO?

You add them to your configuration.nix. For configs in /etc you do something like this:

environment.etc = {
  autostart.source = ./autostart;
  skel.source = ./skel;
  xfce4.source = ./xfce4;
};

Though it’s better to use specialised options instead.

As for /usr/local/bin and /usr/share/ - there’re no such directories in NixOS. For installing software you should use Declarative Package Management.

For manipulating state (/var/lib/) you probably need oneshot systemd services.

What are the best practices?

Basically you do this: Help needed in building a distro based on NixOS - #6 by misuzu

The resulting iso will only contain a bootloader and a nix store, everything else will be created by the activation script on boot according to your configuration.nix. This approach makes it possible to have really cool things like Erase your darlings.

1 Like