helm/modules/options.nix

95 lines
3.1 KiB
Nix
Raw Permalink Normal View History

{ config, options, lib, home-manager, ... }:
with lib;
with lib.my;
{
2020-10-23 17:55:08 -07:00
options = with types; {
user = mkOpt attrs {};
2021-05-27 21:20:50 -07:00
dotfiles = {
dir = mkOpt path
(findFirst pathExists (toString ../.) [
"${config.user.home}/.config/dotfiles"
"/etc/dotfiles"
]);
2021-05-27 21:20:50 -07:00
binDir = mkOpt path "${config.dotfiles.dir}/bin";
configDir = mkOpt path "${config.dotfiles.dir}/config";
modulesDir = mkOpt path "${config.dotfiles.dir}/modules";
themesDir = mkOpt path "${config.dotfiles.modulesDir}/themes";
};
2020-10-23 17:55:08 -07:00
home = {
file = mkOpt' attrs {} "Files to place directly in $HOME";
configFile = mkOpt' attrs {} "Files to place in $XDG_CONFIG_HOME";
dataFile = mkOpt' attrs {} "Files to place in $XDG_DATA_HOME";
};
env = mkOption {
2020-10-23 17:55:08 -07:00
type = attrsOf (oneOf [ str path (listOf (either str path)) ]);
apply = mapAttrs
(n: v: if isList v
then concatMapStringsSep ":" (x: toString x) v
else (toString v));
default = {};
description = "TODO";
};
};
config = {
2021-01-19 22:28:30 -08:00
user =
let user = builtins.getEnv "USER";
name = if elem user [ "" "root" ] then "anish" else user;
2021-01-19 22:28:30 -08:00
in {
inherit name;
description = "The primary user account";
extraGroups = [ "wheel" ];
isNormalUser = true;
home = "/home/${name}";
2021-02-28 11:26:22 -08:00
group = "users";
2021-01-19 22:28:30 -08:00
uid = 1000;
};
# Install user packages to /etc/profiles instead. Necessary for
# nixos-rebuild build-vm to work.
home-manager = {
useUserPackages = true;
# I only need a subset of home-manager's capabilities. That is, access to
# its home.file, home.xdg.configFile and home.xdg.dataFile so I can deploy
# files easily to my $HOME, but 'home-manager.users.hlissner.home.file.*'
# is much too long and harder to maintain, so I've made aliases in:
#
# home.file -> home-manager.users.hlissner.home.file
# home.configFile -> home-manager.users.hlissner.home.xdg.configFile
# home.dataFile -> home-manager.users.hlissner.home.xdg.dataFile
users.${config.user.name} = {
home = {
file = mkAliasDefinitions options.home.file;
# Necessary for home-manager to work with flakes, otherwise it will
# look for a nixpkgs channel.
stateVersion = config.system.stateVersion;
};
xdg = {
configFile = mkAliasDefinitions options.home.configFile;
dataFile = mkAliasDefinitions options.home.dataFile;
};
};
};
users.users.${config.user.name} = mkAliasDefinitions options.user;
nix = let users = [ "root" config.user.name ]; in {
trustedUsers = users;
allowedUsers = users;
};
# must already begin with pre-existing PATH. Also, can't use binDir here,
# because it contains a nix store path.
2021-02-26 10:20:46 -08:00
env.PATH = [ "$DOTFILES_BIN" "$XDG_BIN_HOME" "$PATH" ];
environment.extraInit =
concatStringsSep "\n"
(mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.env);
};
}