!SgYlXivkogarTVcnZO:nixos.org

Nix Flakes

896 Members
181 Servers

Load older messages


SenderMessageTime
10 Nov 2023
@industrial:matrix.orgIndustrial
{ 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:matrix.orgIndustrialHow do I pass the options to my module correctly?13:22:56
@industrial:matrix.orgIndustrial Hmm. It works if I remove the options = {}. 13:24:03
@mib:kanp.aimib 🥐

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:kanp.aimib 🥐my point is that you're misusing the modules system.13:25:54
@mib:kanp.aimib 🥐 *

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:matrix.orgIndustrialOk, I should re-read https://nixos.wiki/wiki/NixOS_modules then :)13:27:18
@mib:kanp.aimib 🥐 *

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:matrix.orgIndustrial 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:kanp.aimib 🥐im pretty sure that completely breaks the modules system fyi..... but uh, i guess it does work lol13:37:44
@industrial:matrix.orgIndustrialOh :< I shouldn't use that with flakes then?13:42:23
@industrial:matrix.orgIndustrialI 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:kanp.aimib 🥐you're essentially bypassing the modules system when you're importing it like that13:44:04
@mib:kanp.aimib 🥐 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:matrix.orgIndustrialOkay13:46:38
@mib:kanp.aimib 🥐

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:kanp.aimib 🥐 *

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:kanp.aimib 🥐 *

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
@industrial:matrix.orgIndustrial
In reply to@mib:kanp.ai

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;
}
Seems like I can't define options.custom = {} nor custom = {} in the ./hosts/langhus/default.nix.
14:01:46
@industrial:matrix.orgIndustrial Should I use pkgs.lib.mkOption there? 14:03:46
@mib:kanp.aimib 🥐 When you're doing options you're making an option, so use mkOption 14:09:45
@mib:kanp.aimib 🥐 When you're configuring them ie custom = {}, just set them as you'd normally do. 14:10:15
@petrichor:envs.net@petrichor:envs.net If you just want to put a value somewhere to share with other modules, you can do lib.custom = { hostname = "langhus"; }; for example 14:19:56
@mib:kanp.aimib 🥐 * When you're configuring them a'la custom = {}, just set them as you'd normally do. 15:15:12
@industrial:matrix.orgIndustrialOh. okay :D16:27:32
@pfz4:zettoit.eupaul / pfz4 joined the room.16:46:06
11 Nov 2023
@ngn999:matrix.org@ngn999:matrix.org changed their profile picture.07:14:18
@ngn999:matrix.org@ngn999:matrix.org changed their profile picture.07:14:26
@orowith2os:fedora.imOro (any/all) changed their display name from Dallas Strouse (she/her) 🧑‍🏫 to Rika (she/her).14:29:47
@brian:bmcgee.ie@brian:bmcgee.ie joined the room.19:53:06

Show newer messages


Back to Room ListRoom Version: 6