summaryrefslogtreecommitdiffstats
path: root/modules/options.nix
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2024-01-07 12:00:08 -0500
committerJon Santmyer <jon@jonsantmyer.com>2024-01-07 12:00:08 -0500
commit7b79203f54853733d4fae88943829d0e24e6e49f (patch)
treea352d199fad7453332b9308a6295164157729f27 /modules/options.nix
parent184bd30bcb303104a4981ac742d8f8961c5477e7 (diff)
downloadnix-config-7b79203f54853733d4fae88943829d0e24e6e49f.tar.gz
nix-config-7b79203f54853733d4fae88943829d0e24e6e49f.tar.bz2
nix-config-7b79203f54853733d4fae88943829d0e24e6e49f.zip
massive overhaul
Diffstat (limited to 'modules/options.nix')
-rw-r--r--modules/options.nix143
1 files changed, 143 insertions, 0 deletions
diff --git a/modules/options.nix b/modules/options.nix
new file mode 100644
index 0000000..e429171
--- /dev/null
+++ b/modules/options.nix
@@ -0,0 +1,143 @@
+# Defines the user and home manager options (credit to hlissner, KubqoA)
+{
+ config,
+ options,
+ lib,
+ home-manager,
+ ...
+}: {
+ options = {
+ user = lib.mkOption {
+ type = lib.types.attrs;
+ default = {};
+ };
+ nixosConfig = {
+ dir = lib.mkOption {
+ type = lib.types.path;
+ default = lib.removePrefix "/mnt" (
+ lib.findFirst lib.pathExists (toString ../.) [
+ "/mnt/etc/nixos"
+ "/mnt/nixos"
+ ]
+ );
+ };
+ binDir = lib.mkOption {
+ type = lib.types.path;
+ default = "${config.nixosConfig.dir}/bin";
+ };
+ configDir = lib.mkOption {
+ type = lib.types.path;
+ default = "${config.nixosConfig.dir}/config";
+ };
+ modulesDir = lib.mkOption {
+ type = lib.types.path;
+ default = "${config.nixosConfig.dir}/modules";
+ };
+ };
+ home = {
+ activation = lib.mkOption {
+ type = lib.types.attrs;
+ default = {};
+ };
+ file = lib.mkOption {
+ type = lib.types.attrs;
+ default = {};
+ };
+ configFile = lib.mkOption {
+ type = lib.types.attrs;
+ default = {};
+ };
+ manager = lib.mkOption {
+ type = lib.types.attrs;
+ default = {};
+ };
+ packages = lib.mkOption {
+ type = lib.types.listOf lib.types.package;
+ default = [];
+ };
+ };
+ env = lib.mkOption {
+ type = lib.types.attrsOf (
+ lib.types.oneOf [
+ lib.types.str
+ lib.types.path
+ (
+ lib.types.listOf (lib.types.either lib.types.str lib.types.path)
+ )
+ ]
+ );
+ apply = lib.mapAttrs (n: v:
+ if lib.isList v
+ then lib.concatMapStringsSep ":" (x: toString x) v
+ else (toString v));
+ default = {};
+ };
+ };
+
+ config = {
+ user = let
+ defaultUser = "jon";
+ user = builtins.getEnv "USER";
+ name =
+ if lib.elem user ["" "root"]
+ then defaultUser
+ else user;
+ in {
+ inherit name;
+ description = "Primary user account";
+ home = "/home/${name}";
+ isNormalUser = true;
+ group = "users";
+ extraGroups = ["wheel"];
+ uid = 1000;
+ };
+
+ # home manager configuration
+ home-manager = {
+ useUserPackages = true;
+ users.${config.user.name} = lib.mkAliasDefinitions options.home.manager;
+ };
+
+ # home.manager is an alias for having to write home-manager.users.<user>
+ home.manager = {
+ home = {
+ homeDirectory = config.user.home;
+ stateVersion = config.system.stateVersion;
+ activation = lib.mkAliasDefinitions options.home.activation;
+ file = lib.mkAliasDefinitions options.home.file;
+ packages = lib.mkAliasDefinitions options.home.packages;
+ };
+ xdg = {
+ enable = true;
+ configFile = lib.mkAliasDefinitions options.home.configFile;
+ };
+ };
+
+ # link to user config
+ users.users.${config.user.name} = lib.mkAliasDefinitions options.user;
+
+ # nix configuration set new user and root as trusted to connect to the nix daemon
+ nix.settings = let
+ users = ["root" config.user.name];
+ in {
+ trusted-users = users;
+ allowed-users = users;
+ };
+
+ # set default XDG dirs
+ environment = {
+ sessionVariables = {
+ XDG_CACHE_HOME = "$HOME/.cache";
+ XDG_CONFIG_HOME = "$HOME/.config";
+ XDG_DATA_HOME = "$HOME/.local/share";
+ XDG_BIN_HOME = "$HOME/.local/bin/";
+ };
+ extraInit =
+ lib.concatStringsSep "\n"
+ (lib.mapAttrsToList (n: v: ''export ${n}="${v}"'') config.env);
+ };
+
+ # add user binary path to PATH
+ env.PATH = ["$NIXOSCONFIG_BIN" "$XDG_BIN_HOME" "$PATH"];
+ };
+}