NixOS question (Edit: Answered) 

So I’m flailing at NixOS trying to do anything slightly-beyond-basic and that’s where the docs end…
How do I just like, define some shit. That I can then use elsewhere. This feels like a very basic question.

Basically I have some config in users/myuser.nix and hosts/myhost.nix, and then fragments/i3config.nix etc, and these are included into a colmena host config in flake.nix.
I want to create a file hosts/myhost/myuser.nix, and set some things in there that can be referenced elsewhere, that are most likely to need changing per user per host. Something like userconfig.backgroundUrl = “blah.jpg”;
And then be able to use that from multiple other files for different window managers as an example.

Am I completely misunderstanding the patterns here?
#NixOS

Follow

re: NixOS question 

@s0 hello!
you got the pattern right :3
but there is a gotcha

when you have a module like
```nix
{ config, … ... }:

{
imports = [ ../flip/flap.nix ];

services.flipnap.flipklox = "whateverer";
}
```
nixpkgs//[lib/modules.nix:489](github.com/ckiee/nixpkgs/blob/) is actually transforming your syntax sugar into the "proper" module structure:
```nix
{ config, … ... }:

{
imports = [ ../flip/flap.nix ];

config = {
services.flipnap.flipklox = "whateverer";
};
}
```

`config` is what the module system primarily operates on, but there's also `imports`, `options` and some others. you can't or have to very carefully use `config` from those since the value of `config` might not be known. getting to how this actually plays out in practice, if you want to define an option you wanna add:
```nix
{ config, lib, ... }:

{
imports = [ ../flip/flap.nix ];

options = {
my.species = lib.mkOption {
type = lib.types.str;
description = "the user's species";
default = "blbebelbebolbloblbbocsblobcat..kitty.🐱.";
};
};
config = { services.flipnap.flipklox = "whateverer"; };
}
```

then `config.my.species` should work globally

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.