Add xdg settings, cache, cleanup script

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-06-21 23:39:18 +03:00
parent ce37f320c2
commit 48f391e3ad
22 changed files with 245 additions and 51 deletions

View File

@@ -88,6 +88,9 @@
};
};
home.persistence."/persist${user.home}".directories = [ ".mozilla" ];
home.persistence = {
"/persist${user.home}".directories = [ ".mozilla" ];
"/cache${user.home}".directories = [ ".cache/mozilla" ];
};
};
}

View File

@@ -1,6 +1,8 @@
{ user ? throw "user argument is required" }: { pkgs, ... }:
{ user ? throw "user argument is required" }: { config, pkgs, ... }:
{
let
hmConfig = config.home-manager.users."${user.name}";
in {
home-manager.users."${user.name}" = {
programs.git = {
enable = true;
@@ -14,7 +16,7 @@
extraConfig.credential.helper = "store";
hooks = let
commit-msg-hook = pkgs.writeShellScriptBin "git-commit-msg" ''
git interpret-trailers --if-exists doNothing --trailer \
${pkgs.git}/bin/git interpret-trailers --if-exists doNothing --trailer \
"Signed-off-by: $(git config user.name) <$(git config user.email)>" \
--in-place "$1"
'';
@@ -22,5 +24,7 @@
commit-msg = "${commit-msg-hook}/bin/git-commit-msg";
};
};
sops.secrets."git".path = "${hmConfig.xdg.configHome}/git/credentials";
};
}

View File

@@ -1,7 +1,16 @@
{ user ? throw "user argument is required" }: { pkgs, ... }:
{ user ? throw "user argument is required" }: { config, lib, pkgs, ... }:
let
hmConfig = config.home-manager.users."${user.name}";
gpgPath = "${hmConfig.xdg.dataHome}/gnupg";
in
{
home-manager.users."${user.name}" = {
programs.gpg = {
enable = true;
homedir = gpgPath;
};
services.gpg-agent = {
enable = true;
defaultCacheTtl = 31536000;
@@ -11,22 +20,24 @@
systemd.user = {
services.gpg-agent-import = let
init = pkgs.writeShellScriptBin "import-gpg-keys" ''
export GNUPGHOME=${gpgPath}
for keyfile in "${user.home}"/.config/sops-nix/secrets/gpg-agent/*.key; do
passfile="''${keyfile%.key}.pass"
if [ -f "$passfile" ]; then
gpg --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile"
${pkgs.gnupg}/bin/gpg2 --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile"
else
gpg --batch --yes --import "$keyfile"
${pkgs.gnupg}/bin/gpg2 --batch --yes --import "$keyfile"
fi
gpg --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do
echo "$KEY_ID:6:" >> "${user.home}"/.gnupg/otrust.txt
${pkgs.gnupg}/bin/gpg2 --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do
echo "$KEY_ID:6:" >> "${gpgPath}"/otrust.txt
done
done
gpg --import-ownertrust "${user.home}"/.gnupg/otrust.txt
rm "${user.home}"/.gnupg/otrust.txt
${pkgs.gnupg}/bin/gpg2 --import-ownertrust "${gpgPath}"/otrust.txt
rm "${gpgPath}"/otrust.txt
'';
in {
Unit = {
@@ -43,7 +54,12 @@
Install = { WantedBy = [ "default.target" ]; };
};
tmpfiles.rules = [ "d ${user.home}/.gnupg 0700 ${user.name} users -" ];
tmpfiles.rules = [ "d ${hmConfig.xdg.dataHome}/gnupg 0700 ${user.name} users -" ];
};
sops.secrets = {
"gpg-agent/pgp.key" = { };
"gpg-agent/pgp.pass" = { };
};
};
}

View File

@@ -0,0 +1,10 @@
{ user ? throw "user argument is required" }: { config, ... }:
let
hmConfig = config.home-manager.users."${user.name}";
in
{
home-manager.users."${user.name}" = {
gtk.gtk2.configLocation = "${hmConfig.xdg.configHome}/gtk-2.0/gtkrc";
};
}

View File

@@ -1,5 +1,8 @@
{ user ? throw "user argument is required" }: { lib, pkgs, ... }:
{ user ? throw "user argument is required" }: { config, lib, pkgs, ... }:
let
hmConfig = config.home-manager.users."${user.name}";
in
{
programs.hyprland.enable = true;
@@ -8,12 +11,12 @@
enable = true;
settings = {
"$mod" = "SUPER";
"$term" = "kitty";
"$term" = "${pkgs.kitty}/bin/kitty";
bind = [
"$mod, Return, exec, $term"
"$mod, r, exec, rofi -show drun"
"$mod, b, exec, firefox"
"$mod, r, exec, ${pkgs.rofi-wayland}/bin/rofi -cache-dir ${hmConfig.xdg.cacheHome}/rofi -show drun"
"$mod, b, exec, ${pkgs.firefox}/bin/firefox"
"$mod, 1, workspace, 1"
"$mod, 2, workspace, 2"
@@ -116,9 +119,8 @@
home = {
sessionVariables.NIXOS_OZONE_WL = "1";
packages = with pkgs; [
swww
rofi-wayland
pavucontrol
];
};

View File

@@ -8,5 +8,7 @@
confirm_os_window_close 0
'';
};
home.persistence."/cache${user.home}".directories = [ ".cache/kitty" ];
};
}

View File

@@ -0,0 +1,10 @@
{ user ? throw "user argument is required" }: { pkgs, ... }:
{
home-manager.users."${user.name}" = {
home = {
packages = with pkgs; [ rofi-wayland ];
persistence."/cache${user.home}".directories = [ ".cache/rofi" ];
};
};
}

View File

@@ -0,0 +1,10 @@
{ user ? throw "user argument is required" }: { pkgs, ... }:
{
home-manager.users."${user.name}" = {
home = {
packages = with pkgs; [ swww ];
persistence."/cache${user.home}".directories = [ ".cache/swww" ];
};
};
}

View File

@@ -1,6 +1,22 @@
{ user ? throw "user argument is required" }: { pkgs, ... }:
{ user ? throw "user argument is required" }: { inputs, lib, pkgs, ... }:
{
let
configDir = ".config/Code";
cacheDirs = [
".config/Code/Cache"
".config/Code/CachedConfigurations"
".config/Code/CachedData"
".config/Code/CachedExtensionVSIXs"
".config/Code/CachedExtensions"
".config/Code/CachedProfilesData"
".config/Code/Code Cache"
".config/Code/DawnCache"
".config/Code/GPUCache"
".config/Code/Service Worker/CacheStorage"
".config/Code/Service Worker/ScriptCache"
];
inherit (pkgs.callPackage "${inputs.impermanence}/lib.nix" { }) sanitizeName concatPaths;
in {
home-manager.users."${user.name}" = {
programs.vscode = {
enable = true;
@@ -59,6 +75,28 @@
./langs/nix.nix
];
home.persistence."/persist${user.home}".directories = [ ".config/Code" ];
home.persistence = {
"/persist${user.home}".directories = [ configDir ];
# Bastard: https://github.com/microsoft/vscode/issues/3884
"/cache${user.home}".directories = cacheDirs;
};
# Some filthy fucking shit below, be warned.
# Microsoft stores cache under .config/Code instead of .cache/Code like normal people.
# Sometimes a race condition is caused if the cache bind mounts are created before the config one.
# So we do this. Sorry.
# https://github.com/nix-community/impermanence/blob/27979f1c3a0d3b9617a3563e2839114ba7d48d3f/home-manager.nix#L238
systemd.user.services = let
configDirService = "bindMount-${sanitizeName (lib.strings.escapeShellArg (concatPaths [ "/persist${user.home}" configDir ]))}.service";
in
builtins.listToAttrs (builtins.map (dir: {
name = "bindMount-${sanitizeName (lib.strings.escapeShellArg (concatPaths [ "/cache${user.home}" dir ]))}";
value = {
Unit = {
Requires = [ configDirService ];
After = [ configDirService ];
};
};
}) cacheDirs);
};
}

View File

@@ -0,0 +1,10 @@
{ user ? throw "user argument is required" }: { config, ... }:
let
hmConfig = config.home-manager.users."${user.name}";
in
{
home-manager.users."${user.name}" = {
xresources.path = "${hmConfig.xdg.configHome}/X11/xresources";
};
}

View File

@@ -4,6 +4,7 @@
home-manager.users."${user.name}" = {
programs.zsh = {
enable = true;
dotDir = ".config/zsh";
autocd = true;
history = {
path = "${user.home}/.local/share/zsh/history";