Rename system to lib

This commit is contained in:
Oliver Davies 2024-02-29 08:24:01 +00:00
parent cf4c9710a2
commit addad268e5
18 changed files with 2 additions and 2 deletions

284
lib/nixos/configuration.nix Normal file
View file

@ -0,0 +1,284 @@
{
inputs,
desktop ? false,
hostname,
pkgs,
system,
}: let
configure-gtk = pkgs.writeTextFile {
name = "configure-gtk";
destination = "/bin/configure-gtk";
executable = true;
text = let
schema = pkgs.gsettings-desktop-schemas;
datadir = "${schema}/share/gsettings-schemas/${schema.name}";
in ''
export XDG_DATA_DIRS=${datadir}:$XDG_DATA_DIRS
gnome_schema=org.gnome.desktop.interface
gsettings set $gnome_schema gtk-theme 'Breeze Dark'
'';
};
username = "opdavies";
in {
nixpkgs = {
config = {
allowUnfree = true;
};
};
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.efi.efiSysMountPoint = "/boot/efi";
systemd.extraConfig = ''
DefaultTimeoutStopSec=10s
'';
networking.hostName = hostname;
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Enable networking
networking.networkmanager.enable = true;
# Set your time zone.
time.timeZone = "Europe/London";
# Select internationalisation properties.
i18n.defaultLocale = "en_GB.UTF-8";
i18n.extraLocaleSettings = {
LC_ADDRESS = "en_GB.UTF-8";
LC_IDENTIFICATION = "en_GB.UTF-8";
LC_MEASUREMENT = "en_GB.UTF-8";
LC_MONETARY = "en_GB.UTF-8";
LC_NAME = "en_GB.UTF-8";
LC_NUMERIC = "en_GB.UTF-8";
LC_PAPER = "en_GB.UTF-8";
LC_TELEPHONE = "en_GB.UTF-8";
LC_TIME = "en_GB.UTF-8";
};
# Enable the X11 windowing system.
services.xserver.enable = true;
services.xserver = {
xkb = {
layout = "gb";
variant = "";
};
displayManager = {
defaultSession = "none+i3";
lightdm.enable = true;
};
windowManager.i3 = {
enable = true;
extraPackages = with pkgs; [i3status i3lock i3blocks];
};
};
# Configure console keymap
console.keyMap = "uk";
services.avahi.enable = true;
services.avahi.nssmdns4 = true;
services.avahi.openFirewall = true;
services.printing.enable = true;
# Enable sound with pipewire.
sound.enable = true;
hardware.pulseaudio.enable = true;
security.rtkit.enable = true;
# services.pipewire = {
# enable = true;
# alsa.enable = true;
# alsa.support32Bit = true;
# pulse.enable = true;
# # If you want to use JACK applications, uncomment this
# #jack.enable = true;
#
# # use the example session manager (no others are packaged yet so this is enabled by default,
# # no need to redefine it in your config for now)
# #media-session.enable = true;
# };
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
users.users.${username} = {
isNormalUser = true;
description = "Oliver Davies";
extraGroups = ["docker" "networkmanager" "wheel"];
packages = with pkgs; [];
};
security.sudo.wheelNeedsPassword = false;
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs;
[
brightnessctl
configure-gtk
ffmpegthumbnailer
shotwell
xfce.thunar
xfce.thunar-volman
xfce.tumbler
]
++ pkgs.lib.optionals desktop [
acpi
arandr
dunst
libnotify
rclone
rclone-browser
# Games.
zeroad
];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
# programs.mtr.enable = true;
# programs.gnupg.agent = {
# enable = true;
# enableSSHSupport = true;
# };
# List services that you want to enable:
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "22.11"; # Did you read the comment?
virtualisation.docker.enable = true;
programs.zsh.enable = true;
programs.zsh.histSize = 5000;
users.defaultUserShell = "/etc/profiles/per-user/${username}/bin/zsh";
fonts = {
fontconfig = {
enable = true;
defaultFonts = {
monospace = ["JetBrainsMono Nerd Font Mono"];
};
};
packages = with pkgs; [
(nerdfonts.override {
fonts = [
"AnonymousPro"
"FiraCode"
"GeistMono"
"IntelOneMono"
"Iosevka"
"JetBrainsMono"
"Meslo"
];
})
];
};
zramSwap.enable = true;
nix = {
gc = {
automatic = true;
dates = "daily";
options = "--delete-older-than 7d";
};
optimise.automatic = true;
settings = {
auto-optimise-store = true;
experimental-features = ["nix-command" "flakes"];
warn-dirty = false;
};
};
# Make Caps lock work as an Escape key on press and Ctrl on hold.
services.interception-tools = let
dfkConfig = pkgs.writeText "dual-function-keys.yaml" ''
MAPPINGS:
- KEY: KEY_CAPSLOCK
TAP: KEY_ESC
HOLD: KEY_LEFTCTRL
'';
in {
enable = true;
plugins = pkgs.lib.mkForce [pkgs.interception-tools-plugins.dual-function-keys];
udevmonConfig = ''
- JOB: "${pkgs.interception-tools}/bin/intercept -g $DEVNODE | ${pkgs.interception-tools-plugins.dual-function-keys}/bin/dual-function-keys -c ${dfkConfig} | ${pkgs.interception-tools}/bin/uinput -d $DEVNODE"
DEVICE:
NAME: "AT Translated Set 2 keyboard"
EVENTS:
EV_KEY: [[KEY_CAPSLOCK, KEY_ESC, KEY_LEFTCTRL]]
'';
};
system.autoUpgrade = {
enable = true;
flake = inputs.self.outPath;
flags = [
"--update-input"
"nixpkgs"
"--no-write-lock-file"
"-L" # print build logs
];
dates = "08:00";
randomizedDelaySec = "45min";
};
services.gvfs.enable = true;
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
pinentryFlavor = "qt";
};
programs.firefox = {
enable = true;
languagePacks = ["en-GB"];
preferences = {
"intl.accept_languages" = "en-GB, en";
"intl.regional_prefs.use_os_locales" = true;
};
};
services.blueman.enable = true;
services.cron = {
enable = true;
systemCronJobs = [
"* * * * * opdavies /home/opdavies/.config/bin/notify-battery.sh"
];
};
services.auto-cpufreq.enable = true;
}

29
lib/nixos/default.nix Normal file
View file

@ -0,0 +1,29 @@
{
inputs,
pkgs,
self,
system,
username,
}: {
desktop ? false,
hostname,
}: let
configuration = import ./configuration.nix {inherit desktop hostname inputs pkgs system;};
hardware-configuration = import ./hardware-configuration.nix;
in
inputs.nixpkgs.lib.nixosSystem {
modules = [
inputs.home-manager.nixosModules.home-manager
{
home-manager = {
extraSpecialArgs = {inherit inputs desktop self username;};
useGlobalPkgs = true;
useUserPackages = true;
users."${username}" = import ./home-manager;
};
}
configuration
hardware-configuration
];
}

View file

@ -0,0 +1,44 @@
{
config,
lib,
pkgs,
modulesPath,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = [];
boot.kernelModules = ["kvm-intel"];
boot.kernelParams = ["i8042.reset"];
boot.extraModulePackages = [];
boot.kernelPackages = pkgs.linuxPackages_latest;
hardware.enableAllFirmware = true;
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
fileSystems."/boot/efi" = {
device = "/dev/disk/by-label/boot";
fsType = "vfat";
};
swapDevices = [{device = "/dev/disk/by-label/swap";}];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp0s13f0u1.useDHCP = lib.mkDefault true;
# networking.interfaces.wlo1.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
hardware.bluetooth.enable = true;
hardware.cpu.intel.updateMicrocode =
lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -0,0 +1,50 @@
{
config,
desktop,
inputs,
pkgs,
self,
username,
...
}: let
desktop-config = import ./desktop.nix {inherit config inputs pkgs username;};
shared-config = import ../../shared/home-manager.nix {inherit inputs pkgs self username;};
shared-packages = import ../../shared/home-manager-packages.nix {inherit inputs pkgs;};
in {
imports =
if desktop
then [desktop-config shared-config]
else [shared-config];
home.packages =
shared-packages
++ pkgs.lib.optionals desktop [
pkgs.discord
pkgs.gimp
pkgs.gscan2pdf
pkgs.kdenlive
pkgs.meslo-lg
pkgs.obs-studio
pkgs.okular
pkgs.pamixer
pkgs.pass
pkgs.pavucontrol
pkgs.pinentry
pkgs.slack
pkgs.via
pkgs.vlc
pkgs.xsel
pkgs.xcape
pkgs.zoom-us
];
home.sessionVariables = {
EDITOR = "nvim";
LANG = "en_GB.UTF-8";
LC_ALL = "en_GB.UTF-8";
LC_CTYPE = "en_GB.UTF-8";
PATH = "$PATH:./vendor/bin:./node_modules/.bin";
PULUMI_SKIP_UPDATE_CHECK = "true";
RIPGREP_CONFIG_PATH = "$HOME/.config/ripgrep/config";
};
}

View file

@ -0,0 +1,43 @@
{
config,
inputs,
pkgs,
username,
}: {
imports = [
./modules/alacritty.nix
./modules/autorandr.nix
./modules/espanso.nix
./modules/i3.nix
];
services.dunst = {
enable = true;
settings = {
global = {
follow = "keyboard";
};
};
};
services.copyq.enable = true;
services.flameshot = {
enable = true;
settings = {
General = {
disabledTrayIcon = false;
saveAfterCopy = true;
savePath = "/home/${username}/Pictures/Screenshots";
showHelp = false;
uiColor = "#60a5fa";
};
};
};
programs.feh.enable = true;
programs.rofi.enable = true;
}

View file

@ -0,0 +1,27 @@
{
programs.alacritty = {
enable = true;
settings = {
window.opacity = 0.9;
window.padding = {
x = 15;
y = 15;
};
font = {
size = 12.0;
bold.style = "Regular";
normal.family = "GeistMono Nerd Font Mono";
# fc-list : family | sort | grep "Nerd Font"
offset.y = 12;
glyph_offset.y = 6;
};
shell = {program = "zsh";};
};
};
}

View file

@ -0,0 +1,43 @@
{username, ...}: {
services.autorandr.enable = true;
xdg.configFile."autorandr/postswitch" = {
executable = true;
text = ''
#!/usr/bin/env bash
feh --randomize --bg-scale /home/${username}/Pictures/Wallpaper/*;
'';
};
programs.autorandr = {
enable = true;
profiles = let
laptop = "00ffffffffffff000daef21400000000161c0104a51f117802ee95a3544c99260f505400000001010101010101010101010101010101363680a0703820402e1e240035ad10000018000000fe004e3134304843472d4751320a20000000fe00434d4e0a202020202020202020000000fe004e3134304843472d4751320a2000bb";
monitor = "00ffffffffffff004c2d1710424e58432b1f0103803f24782ac8b5ad50449e250f5054bfef80714f810081c081809500a9c0b300010108e80030f2705a80b0588a0078682100001e000000fd00324b1e873c000a202020202020000000fc004c5532385235350a2020202020000000ff0048345a524130303132380a20200183020335f04961120313041f10605f2309070783010000e305c0006b030c002000b83c2000200167d85dc401788003e20f81e3060501023a801871382d40582c450078682100001e023a80d072382d40102c458078682100001e04740030f2705a80b0588a0078682100001e565e00a0a0a029503020350078682100001a000049";
in {
laptop = {
config.eDP-1 = {
enable = true;
mode = "1920x1080";
primary = true;
rate = "59.95";
};
fingerprint.eDP-1 = laptop;
};
desktop = {
config.HDMI-1 = {
enable = true;
mode = "2560x1440";
primary = true;
rate = "59.95";
};
fingerprint.HDMI-1 = monitor;
};
};
};
}

View file

@ -0,0 +1,80 @@
let
baseUrl = "https://www.oliverdavies.uk";
in {
services.espanso = {
enable = true;
configs = {
default = {
show_notifications = false;
};
};
matches = {
base = {
matches = [
{
trigger = ":archive";
replace = "${baseUrl}/archive";
}
{
trigger = ":atdc";
replace = "${baseUrl}/atdc";
}
{
trigger = ":call";
replace = "${baseUrl}/call";
}
{
trigger = ":coaching";
replace = "${baseUrl}/team-coaching";
}
{
trigger = ":daily";
replace = "${baseUrl}/daily";
}
{
trigger = ":dotfiles";
replace = "https://github.com/opdavies/dotfiles.nix";
}
{
trigger = ":dc";
replace = "Drupal Commerce";
}
{
trigger = ":dr";
replace = "Drupal";
}
{
trigger = ":gt";
replace = "Great, thanks!";
}
{
trigger = ":lh";
replace = "http://localhost";
}
{
trigger = ":podcast";
replace = "${baseUrl}/podcast";
}
{
trigger = ":pricing";
replace = "${baseUrl}/pricing";
}
{
trigger = ":talks";
replace = "${baseUrl}/talks";
}
{
trigger = ":website";
replace = "${baseUrl}";
}
{
trigger = ":zoom";
replace = "https://savvycal.com/opdavies/zoom";
}
];
};
};
};
}

View file

@ -0,0 +1,158 @@
{
config,
inputs,
self,
username,
pkgs,
...
}: let
modifier = "Mod4";
in {
xsession.windowManager.i3 = {
enable = true;
config = {
assigns = {
"7" = [{class = "vlc";}];
"8" = [{class = "0ad";}];
"9" = [
{class = "Slack";}
{class = "discord";}
];
};
defaultWorkspace = "workspace number 1";
focus.followMouse = false;
modifier = modifier;
keybindings = inputs.nixpkgs.lib.mkOptionDefault {
"${modifier}+d" = "exec ${pkgs.rofi}/bin/rofi -show drun";
"${modifier}+Shift+b" = "exec ${pkgs.firefox}/bin/firefox";
"${modifier}+Shift+f" = "exec ${pkgs.xfce.thunar}/bin/thunar";
"${modifier}+Tab" = "workspace back_and_forth";
# Change focus.
"${modifier}+h" = "focus left";
"${modifier}+j" = "focus down";
"${modifier}+k" = "focus up";
"${modifier}+l" = "focus right";
# Move focused window.
"${modifier}+Shift+h" = "move left";
"${modifier}+Shift+j" = "move down";
"${modifier}+Shift+k" = "move up";
"${modifier}+Shift+l" = "move right";
"${modifier}+Shift+s" = "exec ${pkgs.flameshot}/bin/flameshot gui";
"${modifier}+Shift+p" = "exec ${pkgs.autorandr}/bin/autorandr --cycle";
"${modifier}+Shift+y" = "exec ${pkgs.copyq}/bin/copyq toggle";
"XF86AudioRaiseVolume" = "exec pamixer -ui 2 && pamixer --get-volume";
"XF86AudioLowerVolume" = "exec pamixer -ud 2 && pamixer --get-volume";
"XF86AudioMute" = "exec pamixer --toggle-mute && ( [ \"$(pamixer --get-mute)\" = \"true\" ] && echo 0";
"XF86MonBrightnessDown" = "exec brightnessctl set 5%- | sed -En 's/.*\(([0-9]+)%\).*/\1/p'";
"XF86MonBrightnessUp" = "exec brightnessctl set +5% | sed -En 's/.*\(([0-9]+)%\).*/\1/p'";
};
terminal = "alacritty";
window = {
border = 0;
hideEdgeBorders = "none";
};
};
extraConfig = ''
set $laptop eDP-1
bindswitch --reload --locked lid:on output $laptop disable
bindswitch --reload --locked lid:off output $laptop enable
exec --no-startup-id ${pkgs.feh}/bin/feh --randomize --bg-scale /home/${username}/Pictures/Wallpaper/*;
default_border none
default_floating_border none
smart_borders on
smart_gaps on
#border backgr text indicator
client.focused #444444 #555555 #ffffff #dddddd
client.focused_inactive #222222 #333333 #888888 #292d2e
client.unfocused #222222 #111111 #888888 #292d2e
client.urgent #2f343a #900000 #ffffff #900000
'';
config = {
bars = [
{
position = "bottom";
statusCommand = "${pkgs.i3status}/bin/i3status";
colors = {
background = "#161616";
statusline = "#ffffff";
separator = "#333333";
focusedWorkspace = {
background = "#444444";
border = "#555555";
text = "#ffffff";
};
activeWorkspace = {
background = "#555555";
border = "#666666";
text = "#ffffff";
};
inactiveWorkspace = {
background = "#111111";
border = "#000000";
text = "#888888";
};
bindingMode = {
background = "#ff0000";
border = "#880000";
text = "#ffffff";
};
urgentWorkspace = {
background = "#ff0000";
border = "#880000";
text = "#ffffff";
};
};
}
];
fonts.names = ["GeistMono"];
gaps = {
smartBorders = "on";
smartGaps = true;
};
};
};
programs.i3status = {
enable = true;
general = {
colors = true;
color_bad = "#f7768e";
color_degraded = "#ff9e64";
color_good = "#c0caf5";
};
modules = {
cpu_temperature.enable = false;
ipv6.enable = false;
load.enable = false;
};
};
}

View file

@ -0,0 +1,43 @@
{
inputs,
pkgs,
...
}:
with pkgs; [
awscli2
bitwarden-cli
bottom
ctop
delta
dog
doppler
fd
file
gcc
gh
git
git-crypt
gnupg
go
htop
inotify-tools
jq
lua
mysql
neofetch
php82
php82Packages.composer
pv
ripgrep
rustywind
tldr
tree
tree-sitter
unzip
virtualenv
watchexec
wget
xcp
xh
yarn
]

View file

@ -0,0 +1,60 @@
{
inputs,
pkgs,
username,
self,
}: {
home.username = "${username}";
home.homeDirectory = "/home/${username}";
home.stateVersion = "22.05";
programs.home-manager.enable = true;
imports = [
(import ./modules/neovim.nix {inherit inputs;})
./modules/git.nix
./modules/starship.nix
./modules/tmux.nix
./modules/zsh.nix
];
programs.fzf = {
enable = true;
enableZshIntegration = true;
};
programs.bat.enable = true;
home.file."logo.txt" = {
source = pkgs.copyPathToStore "${self}/logo.txt";
target = "logo.txt";
};
programs.lsd.enable = true;
programs.nnn.enable = true;
programs.direnv = {
enable = true;
enableZshIntegration = true;
nix-direnv.enable = true;
};
home.sessionPath = ["$HOME/.config/bin"];
xdg.configFile."ripgrep/config".text = ''
--follow
--smart-case
'';
xdg.configFile.bin = {
source = ../../bin;
recursive = true;
};
xdg.configFile.phpactor = {
source = ../../config/phpactor;
recursive = true;
};
}

127
lib/shared/modules/git.nix Normal file
View file

@ -0,0 +1,127 @@
{
home.file.".gitmessage".text = ''
# Description
#
# - Why is this change necessary?
# - How does it address the issue?
# - What side effects does this change have?
#
# For breaking changes, uncomment the following line and describe the change:
#
# BREAKING CHANGE:
#
#
# Add any issue IDs or commit SHAs that this commit references:
#
# Refs:
'';
xdg.configFile."git/ignore".text = ''
/.direnv/
/.ignored/
/.issue-id
/.phpactor.json
/notes
/todo
'';
programs = {
git = {
enable = true;
userName = "Oliver Davies";
userEmail = "oliver@oliverdavies.dev";
aliases = {
aa = "add --all";
assume = "update-index --assume-unchanged";
assumed = "!git ls-files -v | grep '^[hsmrck?]' | cut -c 3-";
b = "branch";
browse = "!gh repo view --web";
ca = "commit --amend --verbose";
car = "commit --amend --no-edit";
cl = "!hub clone";
co = "checkout";
compare = "!hub compare";
current-branch = "rev-parse --abbrev-ref HEAD";
dc = "diff --color --word-diff --cached";
df = "diff --color --word-diff";
dup = "!git checkout develop && git fetch origin && echo && git sl develop..origin/develop && echo && git pull --quiet && git checkout -";
fixup = "commit --fixup";
issues = "!gh issue list --web";
mup = "!git master-to-main-wrapper checkout %BRANCH% && git fetch origin && echo && git sl %BRANCH%..origin/%BRANCH% && echo && git pull --quiet && git checkout -";
no-ff = "merge --no-ff";
pl = "pull";
prune = "remote prune origin";
ps = "push";
pulls = "!gh pr list --web";
rbc = "rebase --continue";
rdup = "!git dup && git rebase develop";
remotes = "remote -v";
repush = "!git pull --rebase && git push";
ri = "rebase --interactive";
rid = "!git rebase -i $(git merge-base develop HEAD)";
rim = "!git rebase -i $(git master-to-main-wrapper merge-base %BRANCH% HEAD)";
rip = "!git rebase -i $(git merge-base production HEAD)";
ris = "!git rebase -i $(git merge-base staging HEAD)";
riu = "!git rebase -i $(git rev-parse --abbrev-ref --symbolic-full-name @{u})";
rmup = "!git mup && git master-to-main-wrapper rebase %BRANCH%";
sl = "log --oneline --decorate -20";
sla = "log --oneline --decorate --graph --all -20";
slap = "log --oneline --decorate --graph --all";
slp = "log --oneline --decorate";
staged = "diff --staged";
unassume = "update-index --no-assume-unchanged";
uncommit = "reset --soft HEAD^";
unstage = "reset";
upstream = "rev-parse --abbrev-ref --symbolic-full-name @{u}";
ureset = "!git reset --hard $(git upstream)";
worktrees = "worktree list";
};
extraConfig = {
branch = {
autosetupmerge = true;
autosetuprebase = "always";
};
checkout.defaultRemote = "origin";
color.ui = true;
commit = {template = "~/.gitmessage";};
core = {
editor = "nvim";
excludesFile = "~/.config/git/ignore";
pager = "delta";
};
delta.line-numbers = true;
diff.tool = "vimdiff";
fetch.prune = true;
grep.lineNumber = true;
help.autocorrect = "1";
init.defaultBranch = "main";
merge.ff = "only";
push = {
autoSetupRemote = true;
default = "upstream";
};
pull = {
ff = "only";
rebase = true;
};
rebase = {
autosquash = true;
autostash = true;
};
};
};
lazygit = {
enable = true;
settings = {
gui.skipDiscardChangeWarning = true;
};
};
};
}

View file

@ -0,0 +1,14 @@
{inputs}: {pkgs, ...}: let
system = pkgs.system;
in {
programs.neovim = inputs.opdavies-nvim.lib.mkHomeManager {inherit system;};
home.file.".markdownlint.yaml".text = ''
default: true
line-length: false
no-duplicate-heading:
siblings_only: true
'';
}

View file

@ -0,0 +1,3 @@
{
programs.starship.enable = true;
}

108
lib/shared/modules/tmux.nix Normal file
View file

@ -0,0 +1,108 @@
{pkgs, ...}: {
programs.tmux = {
enable = true;
terminal = "tmux-256color";
extraConfig = ''
unbind C-b
set -g prefix C-s
bind C-s send-prefix
bind-key -n C-h select-pane -L
bind-key -n C-j select-pane -D
bind-key -n C-k select-pane -U
bind-key -n C-l select-pane -R
set-option -g status-keys "emacs"
set-option -sa terminal-features "''${TERM}:RGB"
bind-key h split-window -v -c "#{pane_current_path}"
bind-key v split-window -h -c "#{pane_current_path}"
bind -n S-Left resize-pane -L 2
bind -n S-Right resize-pane -R 2
bind -n S-Down resize-pane -D 1
bind -n S-Up resize-pane -U 1
bind -n C-Left resize-pane -L 10
bind -n C-Right resize-pane -R 10
bind -n C-Down resize-pane -D 5
bind -n C-Up resize-pane -U 5
# Status line customisation
set-option -g status-left " "
set-option -g status-right " #{session_name} "
set-option -g status-right-length 100
set-option -g status-style "fg=#7C7D83 bg=#242631"
set-option -g window-status-activity-style none
set-option -g window-status-current-format "#{window_index}:#{pane_current_command}#{window_flags} "
set-option -g window-status-current-style "fg=#E9E9EA"
set-option -g window-status-format "#{window_index}:#{pane_current_command}#{window_flags} "
bind c new-window -c "#{pane_current_path}"
set -g base-index 1
set -g renumber-windows on
# Break a pane into a new window.
bind-key b break-pane -d
bind-key J command-prompt -p "join pane from: " "join-pane -h -s '%%'"
bind-key C-j choose-tree
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-pipe "reattach-to-user-namespace pbcopy"
bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t"
bind-key K run-shell 'tmux switch-client -n \; kill-session -t "$(tmux display-message -p "#S")" || tmux kill-session'
# Allow clearing screen with ctrl-l by using <prefix> C-l
bind C-l send-keys "C-l"
bind C-k send-keys "C-k"
# Enable mouse support.
setw -g mouse on
# Remove delay when switching Vim modes.
set -sg escape-time 0
set-option -g pane-active-border-style "fg=#1f2335"
set-option -g pane-border-style "fg=#1f2335"
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
bind-key -r F new-window t
bind-key -r D run-shell "t ~/Code/github.com/opdavies/dotfiles.nix"
bind-key -r N run-shell "t ~/Code/github.com/opdavies/opdavies.nvim"
bind-key -r W run-shell "t ~/Code/github.com/opdavies/oliverdavies.uk"
set -g @resurrect-strategy-nvim 'session'
'';
plugins = with pkgs; [
tmuxPlugins.resurrect
tmuxPlugins.vim-tmux-navigator
tmuxPlugins.yank
];
};
}

219
lib/shared/modules/zsh.nix Normal file
View file

@ -0,0 +1,219 @@
{
programs.zsh = {
enable = true;
enableCompletion = false;
dotDir = ".config/zsh";
initExtra = ''
# Plugins
source "''${ZPLUG_REPOS}/robbyrussell/oh-my-zsh/plugins/git/git.plugin.zsh"
source "''${ZPLUG_REPOS}/robbyrussell/oh-my-zsh/plugins/vi-mode/vi-mode.plugin.zsh"
# Case insensitive autocompletion.
zstyle ":completion:*" matcher-list "" "m:{a-zA-Z}={A-Za-z}" "r:|=*" "l:|=* r:|=*"
autoload -Uz compinit && compinit
bindkey -s ^f "t\n"
clear-ls-all() {
clear
lsd -al
}
zle -N clear-ls-all
clear-git-status() {
clear
git status -sb .
}
zle -N clear-git-status
clear-tree-2() {
clear
tree -L 2
}
zle -N clear-tree-2
clear-tree-3() {
clear
tree -L 3
}
zle -N clear-tree-3
bindkey '^G' clear-git-status
# bindkey '^H' clear-tree-3
# bindkey '^J' clear-tree-2
# bindkey '^K' clear-ls-all
# auto-completes aliases
# enables to define
# - normal aliases (completed with trailing space)
# - blank aliases (completed without space)
# - ignored aliases (not completed)
# ignored aliases
typeset -a ialiases
ialiases=()
ialias() {
alias $@
args="$@"
args=''${args%%\=*}
ialiases+=(''${args##* })
}
# blank aliases
typeset -a baliases
baliases=()
balias() {
alias $@
args="$@"
args=''${args%%\=*}
baliases+=(''${args##* })
}
expand-alias-space() {
[[ $LBUFFER =~ "\<(''${(j:|:)baliases})\$" ]]; insertBlank=$?
if [[ ! $LBUFFER =~ "\<(''${(j:|:)ialiases})\$" ]]; then
zle _expand_alias
fi
zle self-insert
if [[ "$insertBlank" = "0" ]]; then
zle backward-delete-char
fi
}
zle -N expand-alias-space
bindkey " " expand-alias-space
bindkey -M isearch " " magic-space
alias dea='direnv allow'
alias dee='direnv edit'
ialias cs="create-script"
ialias daily="run create-daily next"
ialias fetch="git fetch --all --jobs=4 --progress --prune"
ialias ls="lsd -la"
ialias pull="git pull --autostash --jobs=4 --summary origin"
ialias rebase="git rebase --autostash --stat"
ialias reset="git reset --hard; git clean -fd"
ialias run="./run"
ialias s="secrets"
ialias secrets="doppler --project \"$(whoami)\" run"
ialias switch="run nixos nixedo switch"
ialias sz="source ~/.config/zsh/.zshrc"
ialias tag="tag-release"
ialias uncommit="git reset --soft HEAD^";
ialias update="fetch && rebase"
ialias wip="git add . && git commit -m 'wip'";
ialias wt="git worktree"
balias lh3="xdg-open http://localhost:3000"
balias lh8="xdg-open http://localhost:8000"
# tmux
alias ta="tmux attach"
alias tl="tmux list-sessions"
alias tk="tmux kill-session"
# Docker and Docker Compose.
alias dk="docker"
alias dkp="docker ps"
alias dkpa="docker ps -a"
alias dkpaq="docker ps -a -q"
alias dkb="docker build -t"
alias dks="docker start"
alias dkt="docker stop"
alias dkrm="docker rm"
alias dkri="docker rmi"
alias dke="docker exec -ti"
alias dkl="docker logs -f"
alias dki="docker images"
alias dkpu="docker pull"
alias dkph="docker push"
alias dkbnc="docker build --no-cache -t"
alias dkr="docker run --rm"
alias dkrti="docker run --rm -ti"
alias dkc="docker compose"
alias dkcb="docker compose build"
alias dkcu="docker compose up"
alias dkclean="docker ps -q -a -f status=exited | xargs -r docker rm && docker images -q -f dangling=true | xargs -r docker rmi"
# Nix and NixOS.
alias nx="nix"
alias nxb="nix build --json --no-link --print-build-logs"
alias nxd="nix develop"
alias nxf="nix flake"
alias nxfu="nix flake update"
alias nxs="nix shell"
ialias full-system-clean='nix-collect-garbage -d && sudo nix-collect-garbage -d'
ialias full-system-repair='nix-store --verify --check-contents --repair'
ialias full-system-upgrade="sudo nixos-rebuild switch --upgrade && nix-env -u '*'"
ialias list-system-configurations='\ls -l /nix/var/nix/profiles/system-*-link'
ialias local-upgrade="nix-channel --update nixpkgs && nix-env -u '*'"
ialias set-default-boot='/run/current-system/bin/switch-to-configuration boot'
ialias system-rebuild='sudo nixos-rebuild switch'
ialias system-repair='sudo nixos-rebuild switch --repair'
ialias system-upgrade-information='sudo nixos-rebuild switch --upgrade dry-build'
alias tf="terraform"
# run scripts.
alias r="run"
alias rc="run composer"
alias rd="run drush"
alias rdcr="run drush cr"
alias rdup="run drush updb -y"
alias rdce="run drush config:export -y"
alias rdci="run drush config:import -y"
alias rduli="run drush uli"
# Build Configs.
ialias build-configs="nix shell nixpkgs#php82 --command ~/Code/github.com/OliverDaviesLtd/build-configs/main/bin/build-configs app:generate"
ialias build-configs-update-all="~/Code/github.com/OliverDaviesLtd/build-configs-updater/update.sh"
alias bc=build-configs
alias bcu=build-configs-update-all
alias -g A1="| awk '{print \$1}'"
alias -g Fj='| jq .'
alias -g Fy='| yq .'
alias -g G='| grep'
alias -g GH='| grep HTTP'
alias -g Gi='| grep -i'
alias -g H2='| head -n 20'
alias -g H='| head'
alias -g L='| less'
alias -g V='| vim -'
alias -g X='| xargs -I1'
setopt auto_cd
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
'';
zplug = {
enable = true;
plugins = [
{
name = "themes/robbyrussell";
tags = ["from:oh-my-zsh" "as:theme"];
}
{
name = "plugin/git";
tags = ["from:oh-my-zsh"];
}
{
name = "plugin/vi-mode";
tags = ["from:oh-my-zsh"];
}
{name = "mollifier/cd-gitroot";}
{name = "zsh-users/zsh-completions";}
{name = "zsh-users/zsh-syntax-highlighting";}
];
};
};
}

28
lib/wsl2/default.nix Normal file
View file

@ -0,0 +1,28 @@
{
inputs,
pkgs,
self,
system,
username,
}: let
shared-config = import ../shared/home-manager.nix {inherit inputs pkgs self username;};
shared-packages = import ../shared/home-manager-packages.nix {inherit inputs pkgs;};
in
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
{
imports = [shared-config];
home.packages = shared-packages;
home.sessionVariables = {
EDITOR = "nvim";
PATH = "$PATH:./vendor/bin:./node_modules/.bin";
PULUMI_SKIP_UPDATE_CHECK = "true";
RIPGREP_CONFIG_PATH = "$HOME/.config/ripgrep/config";
};
}
];
}