Skip to content

feat: Add nixosConfig option to nixosGenerate #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
pkgs ? null,
lib ? nixpkgs.lib,
nixosSystem ? nixpkgs.lib.nixosSystem,
nixosConfig ? { },
format,
system ? null,
specialArgs ? {},
Expand Down Expand Up @@ -100,7 +101,7 @@
formatModule
]
++ modules;
};
} // nixosConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed. You can use the modules parameter to pass in your customizations. Also would needs to use imports so it merges correctly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, meant to explain further in PR. I've tried passing through my nixosConfiguration as a module, and I get the following error:

nix build -L .\#packages.MTX-SRV
error:
       … while evaluating the attribute 'config.system.build."${(image).config.formatAttr}"'

         at /nix/store/5z81la6av4j0ckp0w1949lxiwjyyykks-source/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);while calling the 'seq' builtin

         at /nix/store/5z81la6av4j0ckp0w1949lxiwjyyykks-source/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Could not load a value as a module, because it is of type "configuration", in file /nix/store/5z81la6av4j0ckp0w1949lxiwjyyykks-source/flake.nix. If you do intend to import this configuration, please only import the modules that make up the configuration. You may have to create a `let` binding, file or attribute to give yourself access to the relevant modules.
       While loading a configuration into the module system is a very sensible idea, it can not be done cleanly in practice.

I thought my PR might be a good starting point to get this working.

The source is here

Copy link
Member

@Mic92 Mic92 Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want to generate for your nixos configuration than import nixos-generators.nixosModules.all-formats in your nixos configuration and than reference
nixosConfigurations.my-machine.config.formats.proxmox instead. One cannot import a nixos systems like that as a module. There is an example for that in the README.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, okay. Should I close the PR? It would be nice to be able to pass a nixosConfiguration to nixosGenerate, but I understand (as a maintainer) if you'd rather keep the current functionality.

in
image.config.system.build.${image.config.formatAttr};
}
Expand Down