91 lines
2.7 KiB
Nix
91 lines
2.7 KiB
Nix
|
{ config, options, lib, ... }:
|
||
|
|
||
|
with lib;
|
||
|
let mkOptionStr = value: mkOption
|
||
|
{ type = types.str;
|
||
|
default = value; };
|
||
|
in
|
||
|
{
|
||
|
imports = [ <home-manager/nixos> ];
|
||
|
|
||
|
|
||
|
## Personal settings
|
||
|
options.my.username = mkOptionStr "hlissner";
|
||
|
options.my.email = mkOptionStr "henrik@lissner.net";
|
||
|
|
||
|
|
||
|
## Convenience aliases
|
||
|
options.my.home = mkOption
|
||
|
{ type = options.home-manager.users.type.functor.wrapped; };
|
||
|
config.home-manager.users.${config.my.username} = mkAliasDefinitions options.my.home;
|
||
|
|
||
|
options.my.user = mkOption { type = types.submodule; };
|
||
|
config.users.users.${config.my.username} = mkAliasDefinitions options.my.user;
|
||
|
|
||
|
options.my.packages = mkOption
|
||
|
{ type = types.listOf types.package;
|
||
|
description = "The set of packages to appear in the user environment."; };
|
||
|
config.my.user.packages = config.my.packages;
|
||
|
|
||
|
|
||
|
## Shell/Environment
|
||
|
options.my.env = mkOption {
|
||
|
type = with types; attrsOf (either (either str path) (listOf (either str path)));
|
||
|
apply = mapAttrs
|
||
|
(n: v: if isList v
|
||
|
then concatMapStringsSep ":" (x: toString x) v
|
||
|
else (toString v));
|
||
|
};
|
||
|
options.my.init = mkOption {
|
||
|
type = types.lines;
|
||
|
description = ''
|
||
|
An init script that runs after the environment has been rebuilt or
|
||
|
booted. Anything done here should be idempotent and inexpensive.
|
||
|
'';
|
||
|
};
|
||
|
config.environment.extraInit =
|
||
|
let exportLines = mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.my.env;
|
||
|
in ''
|
||
|
${concatStringsSep "\n" exportLines}
|
||
|
${config.my.init}
|
||
|
'';
|
||
|
|
||
|
options.my.alias = mkOption
|
||
|
{ type = with types; nullOr (attrsOf (nullOr (either str path))); };
|
||
|
options.my.zsh = {
|
||
|
rc = mkOption {
|
||
|
type = types.lines;
|
||
|
default = "";
|
||
|
description = ''
|
||
|
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshrc and
|
||
|
sourced by $XDG_CONFIG_HOME/zsh/.zshrc
|
||
|
'';
|
||
|
};
|
||
|
env = mkOption {
|
||
|
type = types.lines;
|
||
|
default = "";
|
||
|
description = ''
|
||
|
Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshenv and
|
||
|
sourced by $XDG_CONFIG_HOME/zsh/.zshenv
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
# I avoid programs.zsh.*Init variables because they initialize too soon. My
|
||
|
# zsh config is particular about load order.
|
||
|
config.my.home.xdg.configFile."zsh/extra.zshrc".text =
|
||
|
let aliasLines = mapAttrsToList (n: v: "alias ${n}=\"${v}\"") config.my.alias;
|
||
|
in ''
|
||
|
# This file is autogenerated, do not edit it!
|
||
|
${concatStringsSep "\n" aliasLines}
|
||
|
${config.my.zsh.rc}
|
||
|
'';
|
||
|
config.my.home.xdg.configFile."zsh/extra.zshenv".text = ''
|
||
|
# This file is autogenerated, do not edit it!
|
||
|
${config.my.zsh.env};
|
||
|
'';
|
||
|
|
||
|
## PATH should always start with its old value
|
||
|
config.my.env.PATH = [ "$PATH" ];
|
||
|
}
|