From 7b79203f54853733d4fae88943829d0e24e6e49f Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sun, 7 Jan 2024 12:00:08 -0500 Subject: massive overhaul --- modules/options.nix | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 modules/options.nix (limited to 'modules/options.nix') 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. + 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"]; + }; +} -- cgit v1.2.1