I’m looking to make a live OS that is not an installer, instead carrying a more traditional format and tooling useful at boot after auto login.
General reading:
nixos-generators: A tool for generating various formats and using a custom configuration.nix. The generated media (awss, do, iso, etc) is all geared towards installation.
That last one seems like it should work, but it doesn’t seem to function as advertised. For example, it says:
It is easy to add your own packages and configuration changes to the image.
OK, let’s do that. Let’s make a minimal ISO with some file in /opt. Just to start with something familiar, let’s do it in docker first. I added to a typical dockertools a pathsToLink with /opt and the path includes my new deriviation:
And building with nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=nixos.nix. Can run in qemu, auto logs in (where is that config? Q for another day), and no /opt/. The package isn’t even in /nix/store.
We can add more “normal” packages and see they are available in /run/current-system/sw/, but how do I get a top level /opt? I’ll be studying build.isoImage for now.
Docker images are the odd one out, nix packages in general cannot write to root, that’s just not how nix works. The docker tooling specifically builds images with the packages unrolled into root, since those aren’t really NixOS systems, and the whole NixOS system concept makes no sense in containers because their filesystems are immutable anyway.
I have no idea why your package is missing from the nix store though.
If you want to create a /opt, you’ll need to use system.activationScripts (or systemd.tmpfiles) to create it at boot, and copy/symlink some files to it. That’s how all files outside the nix store come into existence on NixOS.
For creating such a toolbox ISO (that also allows installation) I am currently playing with the “official” approach to build a custom NixOS ISO as described in the manual (with slight changes to adjust it to flakes).
Over time my plans did shift and now I want a more generic toolbox. For that I will probably add the related tooling over the next week, though I need to identify what I actually need, as another goal is, to keep the resulting image below 2 GiB.
(if you’re following along at home you probably want -kvm in the qemu command line)
And after boot:
[nixos@nixos:~]$ ls /opt
ls: cannot access '/opt': No such file or directory
[nixos@nixos:~]$ ls /run/current-system/sw/opt
this_file_is_in_opt
So yeah, not a fix.
@TLATER Yes, your suggestion is a fine workaround. Thank you for pointing out that field and the options search! So much I feel like I’m not learning a language (prims and norms) but a cookbook (libs and solution de jure), this will help.