Disko-install with unattended installation results in error: stack overflow: max-call-depth exceeded (source: flakeOutPaths)
Hello, I am trying to get a setup where I can create an offline ISO installer with the disko-install command out of an existing NixOS configuration. I did this by making the NixOS configuration (which is what I want the target system configuration to be) import the installer/cd-dvd/installation-cd-base.nix module as well as the necessary imports/dependencies mentioned in the "Using disko-install in an offline installer" section at the bottom of https://github.com/nix-community/disko/blob/master/docs/disko-install.md. I did things this way because I didn't want to have a separate NixOS config that was just responsible for installing other NixOS systems.
I'll give a minimal viable example to reproduce the problem:
Here's my flake.nix:
{
description = "Test Flake";
inputs = {
# Using Determinate Nix package manager instead of regular Nix
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/*";
# Stable Nix Packages
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*";
# Declaratively manage filesystems
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
...
} @ inputs: {
nixosConfigurations = {
"basic-installer" = nixpkgs.lib.nixosSystem {
modules = [./os_configs/basic-installer.nix];
specialArgs = {
inherit inputs self;
};
};
};
packages.x86_64-linux = {
basicInstaller = self.nixosConfigurations.basic-installer.config.system.build.isoImage;
};
};
}
Here's my basic-installer.nix (which is also my target nixos configuration)
{
lib,
self,
modulesPath,
pkgs,
inputs,
...
}: let
flakeOutPaths = let
collector = parent:
map (
child:
[child.outPath]
++ (
if child ? inputs && child.inputs != {}
then (collector child)
else []
)
) (lib.attrValues parent.inputs);
in
lib.unique (lib.flatten (collector self));
nixosConfig = self.nixosConfigurations.basic-installer;
dependencies =
[
nixosConfig.config.system.build.toplevel
nixosConfig.config.system.build.diskoScript
nixosConfig.config.system.build.diskoScript.drvPath
nixosConfig.pkgs.stdenv.drvPath
nixosConfig.pkgs.perlPackages.ConfigIniFiles
nixosConfig.pkgs.perlPackages.FileSlurp
(nixosConfig.pkgs.closureInfo {rootPaths = [];}).drvPath
]
++ flakeOutPaths;
in {
imports = [
inputs.disko.nixosModules.disko
"${modulesPath}/installer/cd-dvd/installation-cd-base.nix"
"${self}/os_modules/simple_disko.nix"
];
config = {
environment.etc."install-closure".source = let
closureInfo = pkgs.closureInfo {rootPaths = dependencies;};
in "${closureInfo}/store-paths";
nixpkgs.hostPlatform = {system = "x86_64-linux";};
};
}
And here's my disko.nix:
{...}: {
disko.devices = let
in {
disk = {
main = {
type = "disk";
device = "/dev/vda";
content = {
type = "gpt";
partitions = {
ESP = {
label = "boot";
type = "EF00";
size = "512M";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = ["umask=0077"];
};
};
root = {
name = "root";
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
};
};
};
};
};
}
Building my configuration via nix build .#basicInstaller resulted in the error trace:
error:
… while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:37:12:
36|
37| strict = derivationStrict drvAttrs;
| ^
38|
… while evaluating derivation 'nixos-25.05.20250808.fc756aa-x86_64-linux.iso'
whose name attribute is located at «https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.807900%2Brev-fc756aa6f5d3e2e5666efcf865d190701fef150a/01988d58-8b55-7bfb-ac55-b5c925dfb95b/source.tar.gz?narHash=sha256-eogqv6FqZXHgqrbZzHnq43GalnRbLTkbBbFtEfm1RSc%3D»/pkgs/stdenv/generic/make-derivation.nix:480:13
… while evaluating attribute 'sources' of derivation 'nixos-25.05.20250808.fc756aa-x86_64-linux.iso'
at «https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.807900%2Brev-fc756aa6f5d3e2e5666efcf865d190701fef150a/01988d58-8b55-7bfb-ac55-b5c925dfb95b/source.tar.gz?narHash=sha256-eogqv6FqZXHgqrbZzHnq43GalnRbLTkbBbFtEfm1RSc%3D»/nixos/lib/make-iso9660-image.nix:100:3:
99|
100| sources = map (x: x.source) contents;
| ^
101| targets = map (x: x.target) contents;
… while evaluating the option `system.build.toplevel':
… while evaluating definitions from `/nix/store/xxf0rs99papz2a4w4y346mi97yb49r5m-source/nixos/modules/system/activation/top-level.nix':
… while evaluating the option `system.systemBuilderArgs':
… while evaluating definitions from `/nix/store/xxf0rs99papz2a4w4y346mi97yb49r5m-source/nixos/modules/system/activation/activatable-system.nix':
… while evaluating the option `system.activationScripts.etc.text':
… while evaluating definitions from `/nix/store/xxf0rs99papz2a4w4y346mi97yb49r5m-source/nixos/modules/system/etc/etc-activation.nix':
… while evaluating definitions from `/nix/store/xxf0rs99papz2a4w4y346mi97yb49r5m-source/nixos/modules/system/etc/etc.nix':
… while evaluating the option `environment.etc.install-closure.source':
… while evaluating definitions from `/nix/store/k8dkglcnfh9c849vfywfjm2hzbpm4n0s-source/os_configs/basic-installer.nix':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: stack overflow; max-call-depth exceeded
at /home/tarun/tarun-nixos/os_configs/basic-installer.nix:11:7:
10| collector = parent:
11| map (
| ^
12| child:
This error seems to come from the flakeOutPaths variable in installer.nix. When I comment out that code and stop appending it to the dependencies, then that error goes away. Could this be due to a cycle error? I.e. in the process of collecting the child inputs, it finds a child input whose inputs loop back to a parent, and so it never finishes collecting the inputs because it just cycles over and over.
Interestingly enough, when I comment out the flakeOutPaths code, I still get a different yet similar error: infinite recursion encountered. This error seems to be happening because of the line: nixosConfig.config.system.build.toplevel.
Given the setup that I'm going for, which changes should I make to make things work out?