Move Nix files into a nix directory

Move everything from `config` to the root level.
This commit is contained in:
Oliver Davies 2024-11-20 21:37:15 +00:00
parent 9f47df62b5
commit 69a397e624
124 changed files with 14 additions and 14 deletions

View file

@ -0,0 +1,294 @@
{
inputs,
outputs,
desktop ? false,
hostname,
self,
}:
{ pkgs, ... }:
let
username = "opdavies";
in
{
imports = [ ../../modules/nixos/desktop ];
nixpkgs = {
config = {
allowUnfree = true;
permittedInsecurePackages = [ "electron-27.3.11" ];
};
overlays = [
outputs.overlays.additions
outputs.overlays.modifications
outputs.overlays.stable-packages
outputs.overlays.unstable-packages
];
};
nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
# Bootloader.
boot = {
loader = {
systemd-boot = {
enable = true;
configurationLimit = 10;
};
efi = {
canTouchEfiVariables = true;
efiSysMountPoint = "/boot/efi";
};
};
};
services.thermald.enable = true;
services.power-profiles-daemon.enable = false;
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 = "";
};
};
# 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.
hardware.pulseaudio.enable = false;
security = {
polkit.enable = true;
rtkit.enable = true;
};
services.pipewire = {
enable = true;
alsa = {
enable = true;
support32Bit = true;
};
pulse.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;
[
caffeine-ng
gtypist
fastfetch
mermaid-cli
mkcert
taskopen
taskwarrior3
taskwarrior-tui
ttyper
yt-dlp
ytfzf
]
++ pkgs.lib.optionals desktop [
acpi
arandr
backintime
bluetuith
brightnessctl
cpufrequtils
libnotify
pmutils
ffmpegthumbnailer
libreoffice
logseq
rclone
rclone-browser
shotwell
slack
vscode
xfce.thunar
xfce.thunar-volman
xfce.tumbler
# 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 = [
9003 # xdebug
];
# 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?
programs.dconf.enable = true;
programs.zsh.enable = true;
programs.zsh.histSize = 5000;
users.defaultUserShell = "/etc/profiles/per-user/${username}/bin/zsh";
zramSwap.enable = true;
nix = {
extraOptions = ''
trusted-users = root ${username}
'';
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]]
'';
};
services.gvfs.enable = true;
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
pinentryPackage = pkgs.pinentry-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/${username}/.local/bin/notify-battery" ];
};
services.auto-cpufreq.enable = true;
services.udev = {
enable = true;
extraRules = ''
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0660", GROUP="users", TAG+="uaccess", TAG+="udev-acl"
'';
};
}

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

@ -0,0 +1,64 @@
{
inputs,
outputs,
nixos-hardware,
pkgs,
self,
username,
}:
{
desktop ? false,
hostname,
}:
let
configuration = import ./configuration.nix {
inherit
outputs
desktop
hostname
inputs
self
;
};
hardwareConfiguration = 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 "${self}/nix/home/${username}";
};
}
(import ../../modules/nixos/autorandr.nix)
(import ../../modules/nixos/i3.nix {
inherit
inputs
pkgs
self
username
;
})
configuration
hardwareConfiguration
# TODO: only for "lemp11".
nixos-hardware.nixosModules.common-cpu-intel
nixos-hardware.nixosModules.common-gpu-intel
nixos-hardware.nixosModules.common-pc-laptop
nixos-hardware.nixosModules.common-pc-laptop-hdd
nixos-hardware.nixosModules.system76
];
}

View file

@ -0,0 +1,59 @@
{
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 = [
"i915.modeset=1"
"i915.fastboot=1"
"i915.enable_guc=2"
"i915.enable_psr=1"
"i915.enable_fbc=1"
"i915.enable_dc=2"
];
boot.extraModulePackages = [ ];
boot.kernelPackages = pkgs.linuxPackages_zen;
hardware.enableAllFirmware = true;
hardware.system76.enableAll = 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,83 @@
{
desktop,
inputs,
pkgs,
username,
...
}:
let
php = pkgs.php82;
phpPackages = pkgs.php82Packages;
inherit (pkgs) writeShellApplication;
_timer = writeShellApplication (import ./scripts/_timer.nix);
create-zellij-session = writeShellApplication (
import ./scripts/create-zellij-session.nix { inherit pkgs; }
);
deliver = writeShellApplication (import ./scripts/deliver.nix { inherit pkgs; });
export-video-list = writeShellApplication (
import ./scripts/export-video-list.nix { inherit pkgs username; }
);
run = writeShellApplication (import ./scripts/run.nix { inherit pkgs; });
t = writeShellApplication (import ./scripts/t.nix { inherit pkgs; });
timer = writeShellApplication (import ./scripts/timer.nix);
in
with pkgs;
[
age
awscli2
bitwarden-cli
bottom
cachix
ctop
delta
devenv
dog
doppler
entr
fd
file
gcc
gh
git
git-crypt
gnupg
go
inotify-tools
jq
killall
lua
mariadb
mob
php
phpPackages.composer
pv
rustywind
simple-http-server
sshs
tldr
tree
tree-sitter
unzip
virtualenv
watchexec
wget
xclip
xcp
xdg-utils
xh
yarn
# Scripts.
create-zellij-session
deliver
run
t
]
++ pkgs.lib.optionals desktop [
# Scripts.
_timer
export-video-list
timer
]

View file

@ -0,0 +1,47 @@
{
inputs,
pkgs,
username,
self,
}:
{
home.username = "${username}";
home.homeDirectory = "/home/${username}";
# Nicely reload system units when changing configs.
systemd.user.startServices = "sd-switch";
# See https://github.com/nix-community/home-manager/issues/2064#issuecomment-2259307514.
# This is a workaround for the following errors that appeared when switching back to unstable:
# - 1: Failed to start unit flameshot.service
# - 2: org.freedesktop.systemd1.NoSuchUnit: Unit tray.target not found.
systemd.user.targets.tray = {
Unit = {
Description = "Home Manager System Tray";
Requires = [ "graphical-session-pre.target" ];
};
};
home.stateVersion = "22.05";
programs.home-manager.enable = true;
imports = [
(import ../../modules/home-manager/git.nix { inherit inputs pkgs; })
(import ../../modules/home-manager/neovim.nix { inherit inputs pkgs; })
../../modules/home-manager/bat.nix
../../modules/home-manager/bin.nix
../../modules/home-manager/direnv.nix
../../modules/home-manager/fzf.nix
../../modules/home-manager/htop.nix
../../modules/home-manager/lsd.nix
../../modules/home-manager/pet.nix
../../modules/home-manager/phpactor.nix
../../modules/home-manager/ripgrep.nix
../../modules/home-manager/starship.nix
../../modules/home-manager/syncthing.nix
../../modules/home-manager/tmux.nix
../../modules/home-manager/zellij.nix
../../modules/home-manager/zsh.nix
];
}

View file

@ -0,0 +1,13 @@
{
name = "_timer";
runtimeInputs = [ ];
text = ''
mins=$1
message=''${2:-Time out!}
sleep -- "$mins" * 60
notify-send -t 0 "''${message}" "Your timer of $mins min is over" -u normal
'';
}

View file

@ -0,0 +1,65 @@
{ pkgs }:
{
name = "create-zellij-session";
runtimeInputs = with pkgs; [
openssl
zellij
];
text = ''
function _execute_zellij_layout {
local session_name="$1"
local layout_file="$2"
DIGEST="$(openssl sha512 "$layout_file")"
# Prompt the first time we see a given layout file before running it.
if ! grep -q "$DIGEST" ~/..zellij.digests 2> /dev/null; then
cat "$layout_file"
read -r -n 1 -p "Trust (and run) this Zellij file? (t = trust, otherwise = skip) "
if [[ $REPLY =~ ^[Tt]$ ]]; then
echo "$DIGEST" >> ~/..zellij.digests
_attach_to_or_create_zellij_session --layout "$layout_file"
fi
else
_attach_to_or_create_zellij_session --layout "$layout_file"
fi
}
function _attach_to_or_create_zellij_session {
zellij attach "$session_name" 2>/dev/null || zellij --session "$session_name" "$@"
}
function main {
if [[ $# -eq 1 ]]; then
selected_path=$1
else
selected_path=$(find "$REPOS" "$REPOS/tfw" "$HOME/Documents" -maxdepth 1 -mindepth 1 -type d \
! -name "*-old" \
! -name "*.bak" \
! -name "*.old" \
! -name "_archive" \
| sort \
| fzf --reverse)
fi
session_name=$(basename "$selected_path")
cd "$selected_path"
if [[ -f ".ignored/dev.kdl" ]]; then
_execute_zellij_layout "$session_name" ".ignored/dev.kdl"
elif [[ -f "dev.kdl" ]]; then
_execute_zellij_layout "$session_name" "dev.kdl"
fi
_attach_to_or_create_zellij_session
}
main "$@"
'';
}

View file

@ -0,0 +1,25 @@
{ pkgs }:
{
name = "deliver";
runtimeInputs = with pkgs; [ docker ];
text = ''
set +o pipefail
# Based on https://github.com/jessarcher/dotfiles/blob/ef692c35d64db2c13674dfc850a23b6acf9e8f91/scripts/deliver.
docker_compose_service_name=$(docker compose ps --services 2>/dev/null | grep '^app\|php$' | head -n1)
if [[ "$docker_compose_service_name" != "" ]]; then
if [ -t 1 ]; then
"${pkgs.docker}/bin/docker" compose exec "$docker_compose_service_name" "$@"
else
# The command is not being run in a TTY
"${pkgs.docker}/bin/docker" compose exec -T "$docker_compose_service_name" "$@"
fi
else
"$@"
fi
'';
}

View file

@ -0,0 +1,33 @@
{ pkgs, username, ... }:
{
name = "export-video-list";
runtimeInputs = with pkgs; [
jq
tree
udisks
];
text = ''
device_name="/dev/sda2"
device_label="UNTITLED"
source_path="/run/media/${username}/$device_label"
# If the source path doesn't exist, try mounting the device.
if [[ ! -d "$source_path" ]]; then
${pkgs.udisks}/bin/udisksctl mount -b "$device_name"
fi
# Exit early if the source path still doesn't exist.
if [[ ! -d "$source_path" ]]; then
echo "Error: $source_path not found."
exit 1
fi
output_file="$HOME/Documents/videos.json"
${pkgs.tree}/bin/tree -J "$source_path/Videos" | ${pkgs.jq}/bin/jq . > "$output_file"
${pkgs.jq}/bin/jq . < "$output_file"
'';
}

View file

@ -0,0 +1,16 @@
{ pkgs }:
{
name = "run";
runtimeInputs = with pkgs; [ bashInteractive ];
text = ''
if [[ -e .ignored/run ]]; then
.ignored/run "$@"
exit $?
fi
./run "$@"
'';
}

View file

@ -0,0 +1,38 @@
{ pkgs }:
{
name = "t";
runtimeInputs = with pkgs; [
openssl
tmux
];
text = ''
# Based on similar scripts by ThePrimeagen and Jess Archer.
if [[ $# -eq 1 ]]; then
selected_path=$1
else
# Get the session name from fuzzy-finding list of directories and generating a
# tmux-safe version.
items=$(find "$REPOS" ~/Documents \
-maxdepth 1 -mindepth 1 -type d \
! -name "_archive" \
! -name "*-old" \
! -name "*.old"
)
selected_path=$(echo "''${items}" | sort | fzf --reverse)
fi
session_name=$(basename "$selected_path" | sed 's/\./_/g')
if tmux switch-client -t="$session_name" 2>/dev/null; then
exit 0
fi
( (tmux new-session -c "$selected_path" -d -s "$session_name" && tmux switch-client -t "$session_name") 2>/dev/null ) ||
tmux new-session -c "$selected_path" -A -s "$session_name"
'';
}

View file

@ -0,0 +1,20 @@
{
name = "timer";
runtimeInputs = [ ];
text = ''
if [[ "$1" == "" ]]; then
echo "Usage: ''${0##*/} <mins> [message]"
exit 1
fi
mins=$1
message=$2
nohup _timer "$mins" "$message" &> /dev/null &
echo "timer started for $mins min"
echo "timer started for $mins min, message: '$message'" | systemd-cat -t timer
'';
}

12
nix/lib/theme/default.nix Normal file
View file

@ -0,0 +1,12 @@
{ pkgs, ... }:
{
fonts = {
monospace = {
name = "MesloLGSDZ Nerd Font Mono";
# fc-list : family | sort | grep "Nerd Font"
package = pkgs.nerdfonts.override { fonts = [ "Meslo" ]; };
size = "10";
};
};
}

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

@ -0,0 +1,62 @@
{
inputs,
outputs,
self,
username,
}:
{ system }:
let
inherit (pkgs) lib;
pkgs = import inputs.nixpkgs {
overlays = [
outputs.overlays.additions
outputs.overlays.modifications
outputs.overlays.unstable-packages
];
};
shared-config = import "${self}/nix/lib/shared/home-manager.nix" {
inherit
inputs
pkgs
self
username
;
};
shared-packages = import "${self}/nix/lib/shared/home-manager-packages.nix" {
inherit inputs pkgs username;
desktop = false;
};
in
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit self;
};
modules = [
{
imports = [ shared-config ];
home.packages = shared-packages ++ [ pkgs.wsl-open ];
home.sessionVariables = {
DIRENV_LOG_FORMAT = "";
EDITOR = "nvim";
PATH = lib.concatStringsSep ":" [
"$PATH"
"$HOME/go/bin"
"./vendor/bin"
"./node_modules/.bin"
];
PULUMI_SKIP_UPDATE_CHECK = "true";
REPOS = "$HOME/Code";
RIPGREP_CONFIG_PATH = "$HOME/.config/ripgrep/config";
};
}
];
}