Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

treewide: replace system variables with a local module system #22

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion darwin/system.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{config, ...}:
{ config, ... }:
# This section apply settings to the system configuration only available on macOS
# see <https://daiderd.com/nix-darwin/manual/index.html#sec-options> for more options
{
Expand Down
5 changes: 2 additions & 3 deletions system/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
outputs =
inputs@{ nixpkgs, ... }:
let
system = "x86_64-linux";
hostName = builtins.abort "You need to fill in your hostName"; # Set this variable equal to your hostName
in
{
nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
./configuration.nix
./options.nix

{ networking.hostName = hostName; }
{ aux.hostname = hostName; }
];

specialArgs = {
Expand Down
25 changes: 25 additions & 0 deletions system/options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ config, lib, ... }:
let
inherit (lib.options) mkOption;
inherit (lib.types) str;
in
{
# More options can be added here.
# Following the module system, any module option added in the `options.aux` attribute set
# will become available under `config.aux` within your configuration. Thus making it
# possible to reference arbitrary internal variables if they have been set here
options.aux = {
hostname = mkOption {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be extremely cautious about adding options. It doesn't seem like this one is used for anything other than mapping directly to networking.hostname. Maybe we can just use the available option and have an explicit "example" option if the intention is to show how to create options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This serves firstly to introduce the user to the module system, and secondly to avoid the user accidentally putting the hostname in specialArgs. Not exactly necessary, but not quite sure what else to put in a starter module system.

type = str;
default = builtins.throw "hostname is required";
description = "The hostname for the machine";
};
};

config = {
# internally set `networking.hostName` to the value of `aux.hostname`
# similarly, you can set the values of nixpkgs module system options
# to the variable options defined under `options.aux`
networking.hostName = config.aux.hostname;
};
}