-
Notifications
You must be signed in to change notification settings - Fork 44
feat: impure option for passing --impure to Nix commands
#99
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
base: main
Are you sure you want to change the base?
Conversation
Adds a new `impure` configuration option that allows users to pass `--impure` to appropriate Nix commands. Useful for cases like including runtime metadata, outside of the flake, in a system derivation.
|
Hello @cmacrae, I actually don't really like to add this What do you think about this? I'm wondering what are the kind of values you want to get at deploy time. Using |
|
Sure, totally understand and respect your standpoint. I don't think any self-respecting user of Nix ever feels too comfortable passing So, I had actually originally implemented this as a As for your question concerning runtime config from Pulumi, I'll do my best to demonstrate what I've cooked up. Certainly eager to hear if there's an alternative approach that I haven't thought of/I'm not aware of. So, I have a private Pulumi Component Resource library which I developed to deploy NixOS EC2 instances. As part of its parameters, you point it at a flake config, which simply gets switched to in the userdata, once switched to, comin takes over. here, return Output.all(**all_outputs).apply(
lambda resolved: json.dumps(
{
"configName": self.config_name,
"stack": self.stack,
"region": self.region,
"project": self.project,
"secretArn": resolved.get("secretArn", self.secret_arn),
"parameters": {
**static_params,
**{k: resolved[k] for k in param_outputs},
},
},
indent=2,
)
)As you can see, this includes some standard metadata: flake config name, stack, region, project, etc., as well as arbitrary I then have a very simple NixOS module that flake-housed configs load to be able to then reference these in their configuration, like so: networking.hostName = lib.mkOverride 100 "${config.metadata.configName}-${config.metadata.stack}";This allows for composing NixOS instances based on the deployment scenario. For example, differing configuration between stacks representing environments. Or when dynamically composing many machines that are largely the same, but have slight differences, you only need one correlating I understand I could generate such metadata and have it get pushed to git, then use that as an input, but it doesn't really fit my architecture and I would personally find that a little clunky. What do you think? Is there some other, obvious solution that I'm missing? I'd be very happy to be shown another way :) |
I guess you should still be able to find it in your local git reflog (excepting if you git gc).
I'm wondering if this secret is written to your Nix store, which is world readable.
Ok, I totally understand you want to preserve your exiting architecture! |
Good idea 👍 If I were to resurrect that, does it sound like an implementation you'd be more inclined to accept than the current
It's not, I'm aware of the implications of secrets management in Nix. This is just the ARN of an AWS SecretsManager secret that each instance (if it has secrets defined) gets created. There's then a
🙏 Yeah, I definitely see what you're getting at. It's perhaps something I'll revisit in the future, but this is working very nicely for me for now :) |
Yes, having a list of options provided to the Nix evaluation would be nice. (And if required later, the same could be achieved for the building part.) |
Adds a new
impureconfiguration option that allows users to pass--impureto appropriate Nix commands. Useful for cases like including runtime metadata, outside of the flake, in a system derivation.Hey @nlewo 👋 thanks for creating and sharing comin with the world! Hoping this is a feature you'd be happy to accept.
I needed impure evaluation for how I'm approaching the provisioning of my systems: I wanted a way of passing through metadata from my provisioning source (Pulumi) to my NixOS configuration. In my case, I template EC2 userdata, creating an
/etc/nixos/metadata.jsonfile with interpolated values from the Pulumi program. This then gets read in by a NixOS module usingbuiltins.fromJSON (builtins.readFile "/etc/nixos/metadata.json")so i can then use it throughout configuration, referring to values likeconfig.metadata.foo.Of course, since
/etc/nixos/metadata.jsonis outside my flake, I needed the--impureflag. I've been using this over the past week and it works nicely :) Let me know what you think