157 lines
5.3 KiB
Nix
Executable File
157 lines
5.3 KiB
Nix
Executable File
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
namespace,
|
|
...
|
|
}:
|
|
with lib;
|
|
let
|
|
cfg = config.${namespace}.user;
|
|
|
|
home-directory =
|
|
if cfg.name == null then
|
|
null
|
|
else if pkgs.stdenv.hostPlatform.isDarwin then
|
|
"/Users/${cfg.name}"
|
|
else
|
|
"/home/${cfg.name}";
|
|
in
|
|
{
|
|
options.${namespace}.user = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = "Whether to configure the user account.";
|
|
};
|
|
email = mkOption {
|
|
type = types.str;
|
|
default = "jalle008@proton.me";
|
|
description = "The email of the user.";
|
|
};
|
|
fullName = mkOption {
|
|
type = types.str;
|
|
default = "Matt Jallen";
|
|
description = "The full name of the user.";
|
|
};
|
|
home = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = home-directory;
|
|
description = "The user's home directory.";
|
|
};
|
|
icon = mkOption {
|
|
type = types.nullOr types.package;
|
|
default = null;
|
|
description = "The profile picture to use for the user. Set to a package whose output is the icon file (e.g. a derivation producing a PNG).";
|
|
};
|
|
name = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = "matt";
|
|
description = "The user account.";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
{
|
|
assertions = [
|
|
{
|
|
assertion = cfg.name != null;
|
|
message = "${namespace}.user.name must be set";
|
|
}
|
|
{
|
|
assertion = cfg.home != null;
|
|
message = "${namespace}.user.home must be set";
|
|
}
|
|
];
|
|
|
|
home = {
|
|
file = {
|
|
"Desktop/.keep".text = "";
|
|
"Documents/.keep".text = "";
|
|
"Downloads/.keep".text = "";
|
|
"Music/.keep".text = "";
|
|
"Pictures/.keep".text = "";
|
|
"Videos/.keep".text = "";
|
|
}
|
|
// lib.optionalAttrs (cfg.icon != null) {
|
|
".face".source = cfg.icon;
|
|
".face.icon".source = cfg.icon;
|
|
"Pictures/${cfg.icon.fileName or (builtins.baseNameOf cfg.icon)}".source = cfg.icon;
|
|
};
|
|
|
|
homeDirectory = mkDefault cfg.home;
|
|
|
|
shellAliases = {
|
|
# nix specific aliases
|
|
cleanup = "sudo nix-collect-garbage --delete-older-than 3d && nix-collect-garbage -d";
|
|
bloat = "nix path-info -Sh /run/current-system";
|
|
curgen = "sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
|
|
gc-check = "nix-store --gc --print-roots | egrep -v \"^(/nix/var|/run/\w+-system|\{memory|/proc)\"";
|
|
repair = "nix-store --verify --check-contents --repair";
|
|
nixnuke = ''
|
|
# Kill nix-daemon and nix processes first
|
|
sudo pkill -9 -f "nix-(daemon|store|build)" || true
|
|
|
|
# Find and kill all nixbld processes
|
|
for pid in $(ps -axo pid,user | ${getExe pkgs.gnugrep} -E '[_]?nixbld[0-9]+' | ${getExe pkgs.gawk} '{print $1}'); do
|
|
sudo kill -9 "$pid" 2>/dev/null || true
|
|
done
|
|
|
|
# Restart nix-daemon based on platform
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
sudo launchctl kickstart -k system/org.nixos.nix-daemon
|
|
else
|
|
sudo systemctl restart nix-daemon.service
|
|
fi
|
|
'';
|
|
flake = "nix flake";
|
|
nix = "nix -vL";
|
|
gsed = "${getExe pkgs.gnused}";
|
|
hmvar-reload = ''__HM_ZSH_SESS_VARS_SOURCED=0 source "/etc/profiles/per-user/${config.${namespace}.user.name}/etc/profile.d/hm-session-vars.sh"'';
|
|
|
|
# File management
|
|
rcp = "${getExe pkgs.rsync} -rahP --mkpath --modify-window=1"; # Rsync copy keeping all attributes,timestamps,permissions"
|
|
rmv = "${getExe pkgs.rsync} -rahP --mkpath --modify-window=1 --remove-sent-files"; # Rsync move keeping all attributes,timestamps,permissions
|
|
tarnow = "${getExe pkgs.gnutar} -acf ";
|
|
untar = "${getExe pkgs.gnutar} -zxvf ";
|
|
wget = "${getExe pkgs.wget} -c ";
|
|
remove-empty = "${getExe' pkgs.findutils "find"} . -type d --empty --delete";
|
|
print-empty = "${getExe' pkgs.findutils "find"} . -type d --empty --print";
|
|
dfh = "${getExe' pkgs.coreutils "df"} -h";
|
|
duh = "${getExe' pkgs.coreutils "du"} -h";
|
|
usage = "${getExe' pkgs.coreutils "du"} -ah -d1 | sort -rn 2>/dev/null";
|
|
|
|
# Navigation shortcuts
|
|
home = "cd ~";
|
|
dots = "cd $DOTS_DIR";
|
|
".." = "cd ..";
|
|
"..." = "cd ../..";
|
|
"...." = "cd ../../..";
|
|
"....." = "cd ../../../..";
|
|
"......" = "cd ../../../../..";
|
|
|
|
# Colorize output
|
|
dir = "${getExe' pkgs.coreutils "dir"} --color=auto";
|
|
egrep = "${getExe' pkgs.gnugrep "egrep"} --color=auto";
|
|
fgrep = "${getExe' pkgs.gnugrep "fgrep"} --color=auto";
|
|
grep = "${getExe pkgs.gnugrep} --color=auto";
|
|
vdir = "${getExe' pkgs.coreutils "vdir"} --color=auto";
|
|
|
|
# Misc
|
|
clear = "clear && ${getExe config.programs.fastfetch.package}";
|
|
clr = "clear";
|
|
pls = "sudo";
|
|
psg = "${getExe pkgs.ps} aux | grep";
|
|
myip = "${getExe pkgs.curl} ifconfig.me";
|
|
|
|
# Cryptography
|
|
genpass = "${getExe pkgs.openssl} rand -base64 20"; # Generate a random, 20-character password
|
|
sha = "shasum -a 256"; # Test checksum
|
|
};
|
|
|
|
username = mkDefault cfg.name;
|
|
};
|
|
}
|
|
]);
|
|
}
|