Follow

i have this excerpt in my bio that reads that i talk and do tech mostly but i never really do so fwiw i did spend my half my day reading up and playing with the nix expression language in a repl and moved my configuration to nix flakes.

docs: nixos.org/manual/nix/stable/#c

the language is certainly interesting and i think going through the spec makes understanding the config part of the system a whole lot easier, even if like in my case i haven't quite pieced everything together as a whole.

so one thing that bugged me was seeing so many people have configs like this,

```
{ config, nixpkgs, ... }: {
foo.bar = true;
}
```

but `config` and `nixpkgs` would not be used?? and reading about ellipsis in functions in the docs didn't help me any better because i was told that adding `config` there would somehow unpack the values into the scope when the docs say no such thing? so lo and behold with some testing it turned out that none of that was true and `{ ... }` works just as well!

· · Web · 1 · 0 · 0

i might be completely wrong about certain things but with where i'm at, it seems like the modules i've been using in nix flakes are just functions!

function expressions in nix can go something like this:

```
# argument: expression
a: a + 1
a: b: a + b
{ a, b }: a + b
```

the default nixos configuration starts with something like this:

```
{ config, pkgs, ... }:
{
imports = [
# etc.
];
}
```

and not until reading this spec did i realise that these were just functions! the ellipsis is just a special syntax that allows you to pass a set with additional attributes to the function. and figuring this out is how i ended up with modules for my nix flakes that were basically just this:

```
{ ... }: {
foo.bar = true;
}
```

but then i was curious how i could assign a `bar` to `foo` without defining it first :blobcatcoffee: and well, more set magic!

```
{ a.b = "c"; a.d = "e"; }.a
# returns { b = "c"; d = "e"; }
```

so modules are functions that just return sets of sets!

that's pretty much where i've landed at but i haven't felt this happy or even been able to properly geek out over something in a long while now. i've been so burned out by my job and even a month now unemployed it's taken me this long to actually be able to do something :patcat:

next i suppose is to figure out the significance of the sets being returned by these modules and how they're being pieced together to define the whole system configuration.

figuring out how to add conditionals to my config would also be pretty great. i've been thinking for example how i could have a `nvidia.nix` module and source it for multiple builds but only have the module enable persistence if i have GNOME enabled or something so i could get it to work with my hybrid intel/nvidia system on wayland.

that's all, fedi :blobcatnight: henpy dafne.

okie more nixxy updates from yesterday~ i was actually in the serenityos rabbit hole for most of the day but i did get conditionals working somewhat. my `nvidia.nix` module looks something like this now:

```
{ config, lib, ... }:
let
baseCfg = { ... };
in {
config = lib.mkMerge [
baseCfg
(lib.mkIf config.blabla.enable { ... })
];
}
```

i don't actually remember why i thought making this portable would be a good idea? especially considering that bus ids should be per-device. at least in doing this i realised the significance of “let expressions”. things declared in a set aren't actually variables so the following actually ends up with the error `error: undefined variable 'baseCfg'`:

```
{ config, lib, ... }:
{
baseCfg = { ... };
config = lib.mkMerge [
baseCfg
(lib.mkIf config.blabla.enable { ... })
];
}
```

i'm not sure why previous attempts at this didn't work though, where instead of returning a set with `config` i just returned the `mkMerge` but hmm 🤔

using conditionals for my `gnome.nix` would be more sensible however, like having it set `nixpkgs.config.firefox.enableGnomeExtensions = true;` if and only if i have `firefox` installed. to do that, i figured i could use the following snippet:

```
builtins.elem pkgs.firefox config.environment.systemPackages
```

this would check if `pkgs.firefox` is contained in the `config.environment.systemPackages` list. throwing that in a `mkIf` however did not work, leading to the infamous infinite recursion error:

```
error: infinite recursion encountered
```

so somehow this is okay:

```
lib.mkIf config.blah.enable { ... }
```

while the following is not:

```
lib.mkIf (builtins.elem pkgs.firefox config.environment.systemPackages) { ... }
```

don't they both not evaluate to booleans? i can't wrap my head around it. anyhow that's my mission today and that should help me resolve much of my struggles.

oh but actually one more thing, getting the gnome extensions website to work on nixos is a lesson in PAIN. all that should be necessary is to set the following up:

```
nixpkgs.config.firefox.enableGnomeExtensions = true;
```

this however only seems to work with the packages `firefox` and `firefox-wayland` but not `firefox-devedition-bin`. trying the following did not help either:

```
nixpkgs.config.firefox-devedition-bin.enableGnomeExtensions = true;
```

i tried googling it and looked up the nix discord history but no ball. some poor fella asked the question about 6 times and was consistently ghosted.

so i suppose another chore is to figure out if there's an index for all these `nixpkgs.config` options so i don't actually have to dig in the repo. kind of like search.nixos.org/options but for nix packages instead of just nixos.

i don't think i've had to do so much reading for any one technology before :blobnotlike:

i didn't pour much time into this today. in fact i think i completely wasted an entire day and am feeling terrible about it :drake_dislike: but i've decided i'll just throw a bone at the nixos discord and see if someone could do the thinking for me instead :drake_like:

@dafne
>some poor fella asked the question about 6 times and was consistently ghosted

this is why i hate instant messaging as a "help platform" vs like, a forum or issue tracker

easy for messages to get lost in the spam and then ignored

@haskal yeah, even though discord threads are a thing now the platform remains too fast paced compared to say, a company slack. threads only pop up on discord after very long conversations too and someone has to go through the effort of naming it and whatnot. i'm not a fan either, but generally my questions even on forums are ghosted 🤷‍♀️ also i have severe anxieties over issue trackers unless i am 100% sure something is a bug, which means a deep-dive of the issue which by then i've already found a workaround for. i reported a few such issues with fixes on github and some took ages to resolve anyway 🤦‍♀️

Sign in to participate in the conversation
Serenity Laboratories

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!