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

Read configuration once only #341

Merged
merged 25 commits into from
Nov 14, 2024
Merged

Read configuration once only #341

merged 25 commits into from
Nov 14, 2024

Conversation

shivaraj-bh
Copy link
Member

@shivaraj-bh shivaraj-bh commented Nov 8, 2024

Before

⌨️  Preparing to develop project: .
❄️  nix --version️
❄️  nix --extra-experimental-features nix-command show-config --json️
❄️  nix eval '.#om.develop' --json️
❄️  nix eval '.#om.health' --json️
✅ Nix environment is healthy.

🍾 Welcome to the omnix project

After

❯ just run develop
❄️  nix --version️
❄️  nix --extra-experimental-features nix-command show-config --json️
❄️  nix eval '.#om' --json️
⌨️  Preparing to develop project: .
✅ Nix environment is healthy.

🍾 Welcome to the omnix project

Notice that we only evaluate the om config once in: nix eval '.#om' --json️

@shivaraj-bh shivaraj-bh changed the title PoC: Demonstrate reusing om config in om develop Reuse OmConfig Nov 11, 2024
@shivaraj-bh shivaraj-bh changed the title Reuse OmConfig Reuse OmConfig; OmConfig represents whole om flake output Nov 11, 2024
@shivaraj-bh shivaraj-bh marked this pull request as ready for review November 12, 2024 11:24
@srid srid mentioned this pull request Nov 12, 2024
@srid
Copy link
Member

srid commented Nov 12, 2024

omnix-common now exports two (instead of one) public functions. Why do we need two rather one? If we do need two, when should we use one over the other? What is the difrerence between them? I also ask, because the code comment does not clarify this for me.

image

image

@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Nov 13, 2024

omnix-common now exports two (instead of one) public functions. Why do we need two rather one? If we do need two, when should we use one over the other? What is the difrerence between them? I also ask, because the code comment does not clarify this for me.

image

image

get_sub_configs is for cases like om.templates. It is also used in om.develop, but I guess we could use get_referenced_for there. And get_referenced_for is when it makes sense for user to pick one amongst many possible sub-configs.

@srid
Copy link
Member

srid commented Nov 13, 2024

Do I understand correctly that one is same as other, except for returning multiple (instead of one) keys?

In that case, shouldn't get_referenced_for be defined in terms of (using) get_sub_configs since the latter is a superset of the former?

@shivaraj-bh
Copy link
Member Author

Yes, but there is also that get_referenced_for requires the type T, that it is converting to, have a Default defined, but that is not the case in get_sub_config.

@srid
Copy link
Member

srid commented Nov 13, 2024

I mean, why can't get_referenced_for be simply defined as (roughly) get_sub_configs().get("default").unwrap_or_default() instead of the 28 line function body that it presently is?

@srid
Copy link
Member

srid commented Nov 13, 2024

Ah, the confusion is to do with reference field complect'ing with these functions. Hmm, need to rethink the types here ...

@srid
Copy link
Member

srid commented Nov 13, 2024

Basically, I think pub config: BTreeMap<String, BTreeMap<String, serde_json::Value>>, should be newtype'd as separate struct, with its own impl methods that operate just on the BTreeMap without regard to other fields (like reference).

Decoupled from OmConfig, basically, so these two types and their operations can be reasoned about independently.

Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

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

I've tested this locally and it works. And I'm glad that this simplifies the code by consolidating config in one place, and getting rid of qualified_attr.rs (it really was complicated solution to begin with!).

Could you do the decoupling mentioned in comments? Then it can be merged.

@shivaraj-bh
Copy link
Member Author

I've tested this locally and it works. And I'm glad that this simplifies the code by consolidating config in one place, and getting rid of qualified_attr.rs (it really was complicated solution to begin with!).

Could you do the decoupling mentioned in comments? Then it can be merged.

I did the decoupling, although not super happy with the name Config for pub config: BTreeMap<String, BTreeMap<String, serde_json::Value>> , but couldn’t think of anything better.

flake_url: url.without_attr(),
reference,
config,
flake_url: flake_url.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

This changed the semantics. flake_url should be without attr.

image

I'll try to fix this, but I do find get_sub_config_under to be rather hard to understand (hence less confident of making these changes). I guess the low-levelness of Rust is to blame in large part, forcing us to spend extra effort trying to keep things simple.

@srid srid changed the title Reuse OmConfig; OmConfig represents whole om flake output Read configuration once only Nov 14, 2024
@srid srid merged commit 4ef869e into main Nov 14, 2024
5 checks passed
@srid srid deleted the reuse-om-config branch November 14, 2024 17:18
shivaraj-bh added a commit that referenced this pull request Nov 15, 2024
srid pushed a commit that referenced this pull request Nov 15, 2024
`om develop`: Use `FlakeUrl` without attrs for fetching `OmConfig`

As was the case before #341
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