Skip to content

Instantly share code, notes, and snippets.

@K900
Created November 3, 2023 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save K900/c0788e4708c189635e0bb471f3fa86af to your computer and use it in GitHub Desktop.
Save K900/c0788e4708c189635e0bb471f3fa86af to your computer and use it in GitHub Desktop.
{
imports = [ ./users.nix ];
x.users.alice.editor = "hx";
x.users.bob.editor = "vi";
x.users.clive.editor = "code";
boot.loader.grub.enable = false;
fileSystems."/" = { device = "/dev/sda1"; };
}
❯ nix-build '<nixpkgs/nixos>' -I nixos-config=example.nix
trace: warning: system.stateVersion is not set, defaulting to 23.11. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
trace: warning: I am alice and my editor is hx
trace: warning: I am bob and my editor is vi
trace: warning: I am clive and my editor is code
{ config, lib, ... }:
let
userOptions = {
options = {
editor = lib.mkOption {
type = lib.types.str;
};
};
};
in
{
options = {
x.users = lib.mkOption {
type = lib.types.attrsOf (lib.types.submoduleWith {
modules = [ userOptions ];
});
};
};
config.warnings = lib.mapAttrsToList (name: cfg: "I am ${name} and my editor is ${cfg.editor}") config.x.users;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment