Stream: nix

Topic: Passing arguments to flake


view this post on Zulip Stephen (Dec 13 2023 at 01:14):

I am taking inspiration from nix-systems work, but am struggling.

I am trying to use a similar format to define user names, and host names so that I can pass them in as flake inputs and reference in all files as such.

I have tried with local and remote files and flakes, but am not sure how to get the string out.

view this post on Zulip Srid (Dec 13 2023 at 01:16):

I think you are looking for: https://github.com/NixOS/nix/issues/5663

Right now, only the nix-systems approach is possible.

view this post on Zulip Srid (Dec 13 2023 at 01:17):

https://discourse.nixos.org/t/flake-how-to-have-a-literal-value-input-no-url-file-path/36035

view this post on Zulip Stephen (Dec 13 2023 at 01:19):

I am following the nix-systems approach, but replacing system name with other names.

view this post on Zulip Stephen (Dec 13 2023 at 01:21):

I access system fine as a value, but if I try to access host, no bueno. I keep getting this is a set, not a string errors. And don't know how to get value as a string

view this post on Zulip Stephen (Dec 13 2023 at 01:22):

For example if I try something like ${hosts} = nixpkgs.lib.nixosSystem {}

view this post on Zulip Stephen (Dec 13 2023 at 01:23):

Where hosts is an input hosts.url = "path:./hosts.nix;
hosts.flake = false;

view this post on Zulip Stephen (Dec 13 2023 at 01:24):

And hosts.nix contains ["hostname"]

view this post on Zulip Stephen (Dec 13 2023 at 01:24):

I have tried mixing up hosts.nix format as well, and also making it a flake in a gitlab repo (I get same error)

view this post on Zulip Stephen (Dec 13 2023 at 01:25):

I have tried inheriting and importing hosts as well

view this post on Zulip Srid (Dec 13 2023 at 01:29):

Is there a way to reproduce your problem? Difficult to help without seeing full context.

view this post on Zulip Stephen (Dec 13 2023 at 01:32):

No, I think I understand why now.
You can see current commit here which is a bad attempt: https://gitlab.com/stephenandary/flakes/-/tree/flakes/machines?ref_type=heads

view this post on Zulip Stephen (Dec 13 2023 at 01:33):

In the nix-systems examples there are still let-in statements

view this post on Zulip Stephen (Dec 13 2023 at 01:34):

I did not have that, I can try something like that, but I dont think it would play out how I want

view this post on Zulip Srid (Dec 13 2023 at 01:37):

${(import hosts).name} = ...

view this post on Zulip Stephen (Dec 13 2023 at 01:40):

No bueno, but that atleast changed error to is a list instead of set haha. Thanks Srid. I can try to tinker with formats based on this


Last updated: Nov 15 2024 at 12:33 UTC