| 7 Nov 2023 |
@janik0:matrix.org | In reply to @crtified:crtified.me Oh, if you need the proper name for that concept: It's a Closure - more obvious with the external module * I'll look into that later. I gave myself the challenge of getting a deeper understating of the nix lang and nixos module system so I'm Implementing a dns libary and module which gives necessary meta information to generate something like a octodns config. | 22:58:46 |
@janik0:matrix.org | In reply to @mib:kanp.ai Nice idea! I hope you share it once you're done! :) of course, how else would I get people to do free qa :D | 23:00:57 |
@antifuchs:asf.computer | In reply to @janik0:matrix.org I would try to avoid anything relying on a extra piece of infrastructure that is potentially a single point of failure so the whole proxy thing seems quite meh I find the approach https://github.com/snowfallorg/thaw is taking nice but I have to admit I didn't use it yet. Ooooh, that does look pretty excellent! I’m skeptical of the proxy approach too, and I even more dislike having transitive deps inject those into my system dependencies… so today I switched from Eza to lsd (: | 23:37:47 |
| 9 Nov 2023 |
Fabián Heredia | Hi, a friend just released a very small flake-parts module extension around perSystem in case someone wants to give it a try :3
https://github.com/vic/fp-nm-ws | 05:38:57 |
| @bootstrapper:matrix.org changed their display name from snick to Ido Samuelson. | 06:33:38 |
kraem | In reply to @antifuchs:asf.computer Ooooh, that does look pretty excellent! I’m skeptical of the proxy approach too, and I even more dislike having transitive deps inject those into my system dependencies… so today I switched from Eza to lsd (: out of curiosity. what's the extra transitive dep you're thinking of? zlib? :) | 21:00:23 |
@antifuchs:asf.computer | I was pulling eza into my system definition flake, and it started using the proxy on its flake inputs for some reason | 21:17:29 |
@antifuchs:asf.computer | So now that flake was using the proxy; I noticed because my hydra builds were failing in the sandbox | 21:17:59 |
@antifuchs:asf.computer | Turns out I like lsd more (: | 21:18:15 |
kraem | ah i see :) | 21:39:47 |
| 10 Nov 2023 |
| @atka:matrix.org left the room. | 07:35:14 |
Industrial | Hello. I'm trying to do this:
nixosConfigurations = {
langhus = inputs.nixpkgs.lib.nixosSystem {
inherit system;
inherit pkgs;
modules = [
(import ./features/system/networking {
options = {
hostname = "langhus";
};
})
./features/system/bluetooth
./features/system/boot
With the help of ChatGPT to try to get my modules configurable. I want to use them in different ways on different hosts | 13:21:37 |
Industrial | { lib, ... }:
{
options = {
hostname = lib.mkOption {
type = lib.types.str;
default = "langhus";
description = "Hostname for the system";
};
};
config = {
networking.hostName = options.hostname;
networking.networkmanager.enable = true;
};
}
This is the networking module.
I'm getting error: undefined variable 'options'. | 13:22:12 |
Industrial | How do I pass the options to my module correctly? | 13:22:56 |
Industrial | Hmm. It works if I remove the options = {}. | 13:24:03 |
mib 🥐 | ah, well that's a simple issue. when you do import ./some/expr.nix { some = "options"; }, you first import ./some/expr.nix, which could be anything (in this case what you showed) and then you pass it the attribute set { some = "options"; }. If you really want to do what you're doing, you'd need
{ options }:
{ lib, ... }:
{
networking.hostName = options.hostname;
/* ... etc */
}
| 13:25:04 |
mib 🥐 | my point is that you're misusing the modules system. | 13:25:54 |
mib 🥐 | * ah, well that's a simple issue. when you do import ./some/expr.nix { some = "options"; }, you first import ./some/expr.nix, which could be anything (in this case what you showed) and then you pass it the attribute set { some = "options"; }. If you really want to do what you're doing, you'd need
{ options }:
{ lib, ... }:
{
networking.hostName = options.hostname;
networking.networkmanager.enable = true;
}
| 13:26:19 |
Industrial | Ok, I should re-read https://nixos.wiki/wiki/NixOS_modules then :) | 13:27:18 |
mib 🥐 | * my point is that you're misusing the modules system. ideally you could import like this instead import ./features/system/networking { hostname = "langhus"; } and then have your networking expression be
{ hostname, ... }:
{ lib, ... }: {
networking = {
networkmanager.enable = true;
hostName = hostname;
};
}
... but you might want to rethink your approach to configuring your hosts altogether. :)
| 13:28:13 |
Industrial | I now did this:
{pkgs, options, ...}:
{
imports = [];
options = {
hostname = pkgs.lib.mkOption {
type = pkgs.lib.types.str;
default = "langhus";
description = "Hostname for the system";
};
};
config = {
networking.hostName = options.hostname;
networking.networkmanager.enable = true;
};
}
with
(import ./features/system/networking {
inherit system;
inherit pkgs;
options = {
hostname = "langhus";
};
})
That worked.
This is the complete config by the way: https://github.com/Industrial/nixos-dotfiles/blob/main/flake.nix | 13:33:02 |
mib 🥐 | im pretty sure that completely breaks the modules system fyi..... but uh, i guess it does work lol | 13:37:44 |
Industrial | Oh :< I shouldn't use that with flakes then? | 13:42:23 |
Industrial | I just wanted reusable bits of config per program so I could keep program specific stuff in the same directory and also be able to pick features/programs for different computers I have. | 13:42:56 |
mib 🥐 | you're essentially bypassing the modules system when you're importing it like that | 13:44:04 |
mib 🥐 | if you e.g. wanted to get config from some other module, you'd be unable to since you can't see the fully built config (the config variable that modules usually have access to) | 13:44:35 |
Industrial | Okay | 13:46:38 |
mib 🥐 | if you wanna go about it like this, you could e.g. have a bunch of modules (like you do), but define a top-level configuration option for all your stuff, i.e.
nixosConfigratuinon = {
langhus = lib.nixosSystem {
modules = [
/* all your modules */
# ...
# and then a host-specific module
./hosts/langhus
];
};
};
then ./hosts/langhus/default.nix:
{ ... }: {
options.config = {
hostname = "langhus"; /* although tbh you should just set `networking.hostName` and if you need to refer to it elsewhere use `config.networking.hostName` */
/* etc */
};
}
| 13:47:06 |
mib 🥐 | * if you wanna go about it like this, you could e.g. have a bunch of modules (like you do), but define a top-level configuration option for all your stuff, i.e.
nixosConfigratuinon = {
langhus = lib.nixosSystem {
modules = [
./hosts/langhus
/* the rest of your modules */
];
};
};
then ./hosts/langhus/default.nix:
{ ... }: {
options.config = {
hostname = "langhus"; /* although tbh you should just set `networking.hostName` and if you need to refer to it elsewhere use `config.networking.hostName` */
/* etc */
};
}
| 13:47:56 |
mib 🥐 | * if you wanna go about it like this, you could e.g. have a bunch of modules (like you do), but define a top-level configuration option for all your stuff, i.e.
nixosConfigratuinon = {
langhus = lib.nixosSystem {
modules = [
./hosts/langhus
/* the rest of your modules */
];
};
};
then ./hosts/langhus/default.nix:
{ ... }: {
options.custom = {
hostname = "langhus"; /* although tbh you should just set `networking.hostName` and if you need to refer to it elsewhere use `config.networking.hostName` */
/* etc */
};
}
then your networking is imported just like all the other ones, but defined as
{ config, ... }: {
networking.networkmanager.enable = true;
networking.hostName = config.custom.hostname;
}
| 13:49:22 |