feat: refactor codes

feat: custom rime - disable full_shape punctuations
feat: remap capslock key
This commit is contained in:
Ryan Yin
2023-07-15 16:53:42 +08:00
parent 52c72bd45d
commit cf33721ec1
16 changed files with 43 additions and 162 deletions

View File

@@ -4,7 +4,10 @@
./alacritty
./creative.nix
./immutable-file.nix
./media.nix
./ssh.nix
./xdg.nix
];
home.packages = with pkgs; [

View File

@@ -0,0 +1,64 @@
{ config
, lib
, pkgs
, ...
}:
##############################################################################################
#
# Provide a option `home.immutable-file`, it works like `home.file` but make the generated file immutable.
#
# Copy from https://github.com/iosmanthus/nixos-config/blob/349917b/modules/immutable-file.nix
#
# this module use the `chattr +i` to make the file immutable, `i` indicates `immutable`,
# it's a i-node flags only works on Linux.
#
# TODO not used yet, need to test it.
#
##############################################################################################
with lib;
let
cfg = config.home.immutable-file;
immutableFileOpts = { ... }: {
options = {
src = mkOption {
type = types.path;
};
dst = mkOption {
type = types.path;
};
};
};
mkImmutableFile = pkgs.writeScript "make_immutable_file" ''
# $1: dst
# $2: src
if [ ! -d "$(dirname $1)" ]; then
mkdir -p $1
fi
if [ -f $1 ]; then
sudo chattr -i $1
fi
sudo cp $2 $1
sudo chattr +i $1
'';
in
{
options.home.immutable-file = mkOption {
type = with types; attrsOf (submodule immutableFileOpts);
default = { };
};
config = mkIf (cfg != { }) {
home.activation = mapAttrs'
(name: { src, dst }:
nameValuePair
"make-immutable-${name}"
(lib.hm.dag.entryAfter [ "writeBoundary" ] ''
${mkImmutableFile} ${dst} ${src}
''))
cfg;
};
}

View File

@@ -0,0 +1,50 @@
{ pkgs
, ...
}: {
programs.ssh = {
enable = true;
# all my ssh private key are generated by `ssh-keygen -t ed25519 -C "ryan@nickname"`
# the config's format:
# Host — given the pattern used to match against the host name given on the command line.
# HostName — specify nickname or abbreviation for host
# IdentityFile — the location of your SSH key authentication file for the account.
# format in details:
# https://www.ssh.com/academy/ssh/config
extraConfig = ''
Host 192.168.*
# allow to securely use local SSH agent to authenticate on the remote machine.
# It has the same effect as adding cli option `ssh -A user@host`
ForwardAgent yes
# romantic holds my homelab~
IdentityFile ~/.ssh/romantic
# Specifies that ssh should only use the identity file explicitly configured above
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host github.com
# github is controlled by gluttony~
IdentityFile ~/.ssh/gluttony
# Specifies that ssh should only use the identity file explicitly configured above
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host gtr5
HostName 192.168.5.172
Port 22
Host um560
HostName 192.168.5.173
Port 22
Host s500plus
HostName 192.168.5.174
Port 22
'';
# use ssh-agent so we only need to input passphrase once
# run `ssh-add /path/to/key` for every identity file
# check imported keys by `ssh-add -l`
# TODO `ssh-add` can only add keys temporary, use gnome-keyring to unlock all keys after login.
};
}

View File

@@ -0,0 +1,90 @@
# XDG stands for "Cross-Desktop Group", with X used to mean "cross".
# It's a bunch of specifications from freedesktop.org intended to standardize desktops and
# other GUI applications on various systems (primarily Unix-like) to be interoperable:
# https://www.freedesktop.org/wiki/Specifications/
{ config, pkgs, ... }:
{
home.packages = with pkgs; [
xdg-utils # provides cli tools such as `xdg-mime` `xdg-open`
xdg-user-dirs
];
xdg = {
enable = true;
cacheHome = config.home.homeDirectory + "/.local/cache";
# manage $XDG_CONFIG_HOME/mimeapps.list
# xdg search all desktop entries from $XDG_DATA_DIRS, check it by command:
# echo $XDG_DATA_DIRS
# the system-level desktop entries can be list by command:
# ls -l /run/current-system/sw/share/applications/
# the user-level desktop entries can be list by command(user ryan):
# ls /etc/profiles/per-user/ryan/share/applications/
mimeApps = {
enable = true;
defaultApplications =
let
browser = [ "firefox.desktop" ];
in
{
"application/json" = browser;
"application/pdf" = browser; # TODO: pdf viewer
"text/html" = browser;
"text/xml" = browser;
"application/xml" = browser;
"application/xhtml+xml" = browser;
"application/xhtml_xml" = browser;
"application/rdf+xml" = browser;
"application/rss+xml" = browser;
"application/x-extension-htm" = browser;
"application/x-extension-html" = browser;
"application/x-extension-shtml" = browser;
"application/x-extension-xht" = browser;
"application/x-extension-xhtml" = browser;
"x-scheme-handler/about" = browser;
"x-scheme-handler/ftp" = browser;
"x-scheme-handler/http" = browser;
"x-scheme-handler/https" = browser;
"x-scheme-handler/unknown" = browser;
"x-scheme-handler/discord" = [ "discord.desktop" ];
"x-scheme-handler/tg" = [ "telegramdesktop.desktop" ];
"audio/*" = [ "mpv.desktop" ];
"video/*" = [ "mpv.dekstop" ];
"image/*" = [ "imv.desktop" ];
};
associations.removed =
let
browser = [ "google-chrome.desktop" ];
in
{
"text/html" = browser;
"text/xml" = browser;
"application/xml" = browser;
"application/xhtml+xml" = browser;
"application/xhtml_xml" = browser;
"application/rdf+xml" = browser;
"application/rss+xml" = browser;
"image/gif" = browser;
"image/jpeg" = browser;
"image/png" = browser;
"image/webp" = browser;
"x-scheme-handler/http" = browser;
"x-scheme-handler/https" = browser;
"application/pdf" = browser;
};
};
userDirs = {
enable = true;
createDirectories = true;
extraConfig = {
XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
};
};
};
}