| 7 Nov 2023 |
@janik0:matrix.org | In reply to @antifuchs:asf.computer what are people's thoughts on rime.cx? it seems down, isn't allowlisted in restricted mode by default & ... does http:// URLs only, for a thing that's essentially trust-on-first-use? Is that considered safe? 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 so I have to admit I didn't use it yet. | 22:00:09 |
mib 🥐 | In reply to @janik0:matrix.org
Heyo 👋 I have a flake with two outpus, one is nixosModules and the other one is a lib output. And in the lib output I deine some functions that I would like to use in the nixosModules. The flake looks something like this:
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: {
nixosModules = rec {
myModule = import ./nixos;
default = myModule;
};
lib = ./lib;
};
}
and I'm not quite sure how the wiring for this would work. I looked at the nixpkgs flake which does lib = lib.extend(some over complicated looking stuff) Can someone point me in the right direction?
do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like
outputs = { self, nixpkgs }: {
nixosModules = rec {
default = myModule;
}
}
| 22:02:58 |
mib 🥐 | In reply to @janik0:matrix.org
Heyo 👋 I have a flake with two outpus, one is nixosModules and the other one is a lib output. And in the lib output I deine some functions that I would like to use in the nixosModules. The flake looks something like this:
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: {
nixosModules = rec {
myModule = import ./nixos;
default = myModule;
};
lib = ./lib;
};
}
and I'm not quite sure how the wiring for this would work. I looked at the nixpkgs flake which does lib = lib.extend(some over complicated looking stuff) Can someone point me in the right direction?
* do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like (woops one moment hit enter too soon)
outputs = { self, nixpkgs }: {
nixosModules = rec {
default = myModule;
}
}
| 22:03:05 |
@janik0:matrix.org | In reply to @antifuchs:asf.computer what are people's thoughts on rime.cx? it seems down, isn't allowlisted in restricted mode by default & ... does http:// URLs only, for a thing that's essentially trust-on-first-use? Is that considered safe? * 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. | 22:03:18 |
mib 🥐 | * do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like (woops one moment hit enter too soon)
outputs = { self, nixpkgs }: let
lib = import ./lib;
in {
nixosModules = rec {
myModule = import ./nixos { inherit lib; };
default = myModule;
};
inherit lib;
}
| 22:03:33 |
mib 🥐 | * do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like
outputs = { self, nixpkgs }: let
lib = import ./lib;
in {
nixosModules = rec {
myModule = import ./nixos { inherit lib; };
default = myModule;
};
inherit lib;
}
| 22:03:38 |
mib 🥐 | * do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like
outputs = { self, nixpkgs }: let
lib = import ./lib;
in {
nixosModules = rec {
myModule = import ./nixos { inherit lib; };
default = myModule;
};
inherit lib;
}
| 22:03:52 |
CRTified | In reply to @mib:kanp.ai
do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like
outputs = { self, nixpkgs }: let
lib = import ./lib;
in {
nixosModules = rec {
myModule = import ./nixos { inherit lib; };
default = myModule;
};
inherit lib;
}
Or you use self.lib in the module | 22:03:57 |
mib 🥐 | In reply to @crtified:crtified.me Or you use self.lib in the module do you have to pass self down then or is that "automatic"? | 22:04:35 |
CRTified | What exactly do you mean with "pass down"? If the module is in a separate file, you'll likely have to pass it in some way, but if it's in the same file it is also in the scope, so you don't need to pass it | 22:05:29 |
mib 🥐 | I'm talking about myModule - same way im passing in lib. | 22:05:49 |
CRTified | Oh no, not in that way | 22:05:57 |
CRTified | Give me a sec, I'll try to write a quick example | 22:06:07 |
CRTified | https://gist.github.com/CRTified/69f83b3c1eef037413a400566e583cd3 | 22:15:11 |
CRTified | Here you go | 22:15:14 |
CRTified | Both versions are in that flake 🙂 | 22:16:01 |
@janik0:matrix.org | In reply to @mib:kanp.ai
do you actually want to refer to your lib or die you mean to import it first?
if import, then just import it in a let in and pass it to both your modules and lib. something like
outputs = { self, nixpkgs }: let
lib = import ./lib;
in {
nixosModules = rec {
myModule = import ./nixos { inherit lib; };
default = myModule;
};
inherit lib;
}
I think this works, but I also need pass in the nixpkgs lib and the magic nixosModules config attribute somehow | 22:16:05 |
CRTified | * https://gist.github.com/CRTified/69f83b3c1eef037413a400566e583cd3 Note that the externalModule.nix contains a function taking self which returns the usual module (which is a function in config, lib, ...) | 22:17:35 |
CRTified | tbh, I don't know whether the let/inherit approach or the higher-order-function approach is better, but nix evaluates slow either way, so I'd say that it makes sense to use what the user can actually use 🙂 | 22:19:44 |
@janik0:matrix.org | In reply to @crtified:crtified.me https://gist.github.com/CRTified/69f83b3c1eef037413a400566e583cd3 Note that the externalModule.nix contains a function taking self which returns the usual module (which is a function in config, lib, ...) thank you for this ❤️ | 22:20:48 |
CRTified | In reply to @janik0:matrix.org thank you for this ❤️ Oh, if you need the proper name for that concept: It's a Closure - more obvious with the external module | 22:42:46 |
@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 a module which gives necessary meta information to generate something like a octodns config. | 22:49:11 |
@janik0:matrix.org |  Download image.png | 22:49:25 |
CRTified | oh, dns name manipulation might come handy once in a while 🙂 | 22:49:53 |
mib 🥐 | In reply to @janik0:matrix.org 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 a module which gives necessary meta information to generate something like a octodns config. Nice idea! I hope you share it once you're done! :) | 22:53:15 |
mib 🥐 | In reply to @janik0:matrix.org I think this works, but I also need pass in the nixpkgs lib and the magic nixosModules config attribute somehow dunno about closure approach but you could merge them; nixpkgs.lib // (import ./lib) | 22:54:06 |
mib 🥐 | * dunno about closure approach but you could merge them; lib = nixpkgs.lib // (import ./lib) | 22:54:28 |
mib 🥐 | In reply to @crtified:crtified.me https://gist.github.com/CRTified/69f83b3c1eef037413a400566e583cd3 Ah, yeah, so it is either the inherit (because external file) or inlining a closure. I prefer passing an attribute set to generate the module since the actual module is in another file, but to each their own :) (also makes it easier if you e.g. have a bunch of modules) | 22:57:17 |
mib 🥐 | Thanks for the example though! :) always nice to see alternative ways of solving issues ^^ | 22:57:47 |
mib 🥐 | * you could merge them; lib = nixpkgs.lib // (import ./lib). Works with both closure and passing the attributeset, but you'll probably want a let in regardless | 22:58:39 |