Skip to content
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

Make darwin/home/nixosModules not be set when no modules are present #89

Closed
wants to merge 1 commit into from

Conversation

JumpIn-Git
Copy link

@JumpIn-Git JumpIn-Git commented Mar 11, 2025

Right now, if you use blueprint in a flake, the outputs darwin/home/nixosModules will be set to a empty attribute if there are no modules, this can be easily fixed with lib.mkIf. This error also exists with darwin/system/nixosConfigurations, and using lib.mkIf will make those lines quite long, I don't have a solution for that currently.

Any idea's on the latter are welcome!

@JumpIn-Git
Copy link
Author

Why do the check's complain about uncommited changes, I had that too...

@JumpIn-Git JumpIn-Git marked this pull request as draft March 11, 2025 20:32
@JumpIn-Git JumpIn-Git marked this pull request as ready for review March 12, 2025 09:16
@JumpIn-Git
Copy link
Author

JumpIn-Git commented Mar 12, 2025

What does nixosConfigurations = lib.mapAttrs (_: x: x.value) (hostsByCategory.nixosConfigurations or { }); do? Why is the mapAttrs needed? I would like to usee a helper function to shorten it:

  # If arr = modules 
  # and args = {nixosModules = "nixos"}
  # it should eval to
  # [(
  #   lib.mkIf (arr ? "nixos") {nixosModules = modules.nixos;}
  # )];
  mapTo = arr: {...} @ args:
    lib.mkMerge (
      let
        names = lib.attrNames args;
      in
        builtins.map (n: let
          v = args.${n};
        in
          lib.mkIf (
            arr ? ${v}
          ) # If args = {nixosModules = "nixos";}, check arr.nixos exists
          
          {${n} = arr.${v};})
        names
    );

(needs testing)

Right now, if you use blueprint in a flake, the outputs
darwin/home/nixosModules will be set to a empty attribute if there are
no modules, this can be easily fixed with `lib.mkIf`. This error also
exists with darwin/system/nixosConfigurations, and using `lib.mkIf` will
make those lines quite long, I don't have a solution for that currently.
@zimbatm
Copy link
Member

zimbatm commented Mar 12, 2025

It's tricky to have the top-level attrset be composed like that. The last time I tried, I hit infinite recursion issues. Probably because it makes the attrset less lazy.

@zimbatm
Copy link
Member

zimbatm commented Mar 12, 2025

To solve this, probably the solution is to move from a model where blueprint is the flake output, to one where blueprint generates and instance, that then gets converted to a flake output. And then have all the references to "flake" or "self" point to the blueprint instance. The flake output is then a conversion that takes the blueprint and converts is to a "clean" flake output.

image

@JumpIn-Git
Copy link
Author

JumpIn-Git commented Mar 12, 2025

I thought my solution worked, but is doesnt... this is way more complicated then I thought

@JumpIn-Git JumpIn-Git marked this pull request as draft March 12, 2025 15:31
@JumpIn-Git
Copy link
Author

Closing, as I cant find a solution, made a issue: #92

@JumpIn-Git JumpIn-Git closed this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants