-
-
Notifications
You must be signed in to change notification settings - Fork 153
improve all-formats module: support customizing and creating formats + add tests + add readme #256
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
Conversation
While the `all-formats.nix` module allows to import all formats at once, it lacks an interface to customize formats or add formats. This is fixed by adding the top-level option `formatConfigs` (attrsOf deferredModule). All format modules created under `config.formatConfigs` are mapped so their outputs are available under `config.formats` which has also been moved to the top-level (previously `config.system.formats`). Done: - add option `formatConfigs` - move option `system.formats` -> `formats` - add test for customizing a format
| nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem { | ||
| modules = [self.nixosModules.my-machine]; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a dumb question: if I nixos-rebuild --flake .#my-machine what does this build? Just some kind of store path with the nixos-system in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and this isn't changed by the all-formats module.
README.md
Outdated
| packages.x86_64-linux = | ||
| self.nixosConfigurations.my-machine.config.formats; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clear if there is only one machine defined per flake. Is there a convenient way you know of to "namespace" these formats so I could do something like nix build .#machine1.vm and nix build .#machine2.virtualbox?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, not sure if it's right or not, but looks like the way I've kind of done this before without violating the flakes package schema is to make an unstructured output:
outputs { ... }: {
...
my-machine = nixpkgs.lib.getAttrs ["vm" "virtualbox"] self.nixosConfigurations.my-machine.config.formats;
};
Which then can then be used:
nix build .#my-machine.vm # build the qemu vm
nix build .#my-machine.virtualbox # build the virtualbox vm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clear if there is only one machine defined per flake. Is there a convenient way you know of to "namespace" these formats so I could do something like nix build .#machine1.vm and nix build .#machine2.virtualbox?
Defining packages outputs is not necessary. You can just simply:
nix build .#nixosConfigurations.machine1.config.formats.vm
...or
nix build .#nixosConfigurations.machine2.config.formats.virtualbox
Creating an unstructured output is another way how to achieve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Via 34bbb3e I now removed the misleading packages output from the example flake and for the nix build commands use the more explicit referencing.
|
I used comments to ask a couple questions, but I've tried out your branch and it seems to work well for me. This seems really cool, and would be very helpful for how I use Work for a future PR, but I'm thinking it would still be useful to have a helper function to wrap up some of this boilerplate. I'm thinking something that took a configuration module and then automatically injected the |
Remove the packages flake output
Making a flake-parts module sounds like a good way to achieve what you describe. |
|
alright, finally had some time to test this, looks pretty nice! |
|
This seems to work great! I'm not really super experienced with Nix but is there any way to get the image filename path like the |
this is now taken care of in #263 |
While the
all-formats.nixmodule (introduced via #241) allows to import all formats at once, it lacks an interface to customize formats or add formats.This is fixed by adding the top-level option
formatConfigs(attrsOf deferredModule).All format modules created under
config.formatConfigsare mapped so their outputs are available underconfig.formatswhich has also been moved to the top-level (previouslyconfig.system.formats).Done:
all-formatsmodule vianixosModulesformatConfigs(pre-populated with all existing formats)system.formats->formatsOpen questions:
Using in a Flakebe removed now, as the new sectionUsing as a nixos-modulesupports all its features and should be simpler to use (no need to call a function for each format etc.)?