helm/options/my.nix

109 lines
3 KiB
Nix
Raw Normal View History

2020-01-12 15:17:17 -08:00
{ config, options, lib, utils, pkgs, ... }:
with lib;
{
imports = [ <home-manager/nixos> ];
options.my = {
username = mkOption {
type = types.str;
default = "hlissner";
};
email = mkOption {
type = types.str;
default = "henrik@lissner.net";
};
2020-01-12 15:17:17 -08:00
home = mkOption {
type = options.home-manager.users.type.functor.wrapped;
default = {};
2020-01-13 19:11:29 -08:00
description = "A convenience alias for home-manager.users.{my.username}."
2020-01-12 15:17:17 -08:00
};
user = mkOption {
type = types.submodule;
default = {};
2020-01-13 19:11:29 -08:00
description = "A convenience alias for users.users.{my.username}.";
2020-01-12 15:17:17 -08:00
};
env = mkOption {
type = with types; attrsOf (either (either str path) (listOf (either str path)));
default = {};
2020-01-13 19:11:29 -08:00
description = ''
An map of environment variables that are set later than
environment.variables or environment.sessionVariables. This is insurance
that XDG variables (and other essentials) are initialized by the time
these are set.
'';
2020-01-12 15:17:17 -08:00
apply = mapAttrs
(n: v: if isList v
then concatMapStringsSep ":" (x: toString x) v
else (toString v));
};
alias = mkOption {
type = with types; nullOr (attrsOf (nullOr (either str path)));
default = {};
2020-01-13 19:11:29 -08:00
description = "Shell-independent aliases for interactive shells.";
2020-01-12 15:17:17 -08:00
};
packages = mkOption {
type = types.listOf types.package;
default = [];
description = "The set of packages to appear in the user environment.";
};
init = mkOption {
type = types.lines;
default = "";
2020-01-13 19:11:29 -08:00
description = ''
An init script that runs after the environment has been rebuilt or
booted. Anything done here should be idempotent and inexpensive.
'';
2020-01-12 15:17:17 -08:00
};
zsh = {
rc = mkOption {
type = types.lines;
default = "";
2020-01-13 19:11:29 -08:00
description = ''
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshrc and
sourced by $XDG_CONFIG_HOME/zsh/.zshrc
'';
2020-01-12 15:17:17 -08:00
};
env = mkOption {
type = types.lines;
default = "";
2020-01-13 19:11:29 -08:00
description = ''
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshenv and
sourced by $XDG_CONFIG_HOME/zsh/.zshenv
'';
2020-01-12 15:17:17 -08:00
};
};
};
config = {
users.users.${config.my.username} = mkAliasDefinitions options.my.user;
home-manager.users.${config.my.username} = mkAliasDefinitions options.my.home;
my.user.packages = config.my.packages;
my.env.PATH = [ "$PATH" ];
environment.extraInit =
let exportLines = mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.my.env;
in ''
${concatStringsSep "\n" exportLines}
${config.my.init}
'';
my.home.xdg.configFile."zsh/extra.zshrc".text =
let aliasLines = mapAttrsToList (n: v: "alias ${n}=\"${v}\"") config.my.alias;
in ''
${concatStringsSep "\n" aliasLines}
${config.my.zsh.rc}
'';
2020-01-12 15:17:17 -08:00
my.home.xdg.configFile."zsh/extra.zshenv".text = config.my.zsh.env;
};
}