Examples
Constants
nix
{delib, ...}:
delib.module {
name = "constants";
options.constants = with delib; {
username = readOnly (strOption "sjohn");
userfullname = readOnly (strOption "John Smith");
useremail = readOnly (strOption "johnsmith@example.com");
};
}
Home Manager
With constants:
nix
{delib, pkgs, ...}:
delib.module {
name = "home";
home.always = {myconfig, ...}: let
inherit (myconfig.constants) username;
in {
home = {
inherit username;
# If you don't need Nix-Darwin, or if you're using it exclusively,
# you can keep the string here instead of the condition.
homeDirectory =
if pkgs.stdenv.isDarwin
then "/Users/${username}"
else "/home/${username}";
};
};
}
User
With constants:
nix
{delib, ...}:
delib.module {
name = "user";
# If you're not using NixOS, you can remove this entire block.
nixos.always = {myconfig, ...}: let
inherit (myconfig.constants) username;
in {
users = {
groups.${username} = {};
users.${username} = {
isNormalUser = true;
initialPassword = username;
extraGroups = ["wheel"];
};
};
};
# If you're not using Nix-Darwin, you can remove this entire block.
darwin.always = {myconfig, ...}: let
inherit (myconfig.constants) username;
in {
users.users.${username} = {
name = username;
home = "/Users/${username}";
};
};
}
Git
With constants:
nix
{delib, ...}:
delib.module {
name = "programs.git";
options.programs.git = with delib; {
enable = boolOption true;
enableLFS = boolOption true;
};
home.ifEnabled.programs.git = {myconfig, cfg, ...}: {
enable = true;
lfs.enable = cfg.enableLFS;
userName = myconfig.constants.username;
userEmail = myconfig.constants.useremail;
};
}
Alejandra
nix
{delib, ...}:
delib.module {
name = "programs.alejandra";
options = delib.singleEnableOption true;
home.ifEnabled.home.packages = [pkgs.alejandra];
}