···11# crescentrose's dotfiles
2233-> [!WARNING]
44-> This is a highly experimental NixOS branch. Here be dragons!
5366-
44+
7588-
66+
97108## Setup
1191212-This is a standard Nix flake. so on a NixOS system, running `sudo nixos-rebuild --flake
1313-./nixos#streaming-heart switch` should do the trick. Note that you will need a handful of
1414-_secrets_ - refer to the flake files for details. Also, the wallpaper directory is not distributed
1515-as a part of this repo as that would be rude to the artists - find your own wallpapers! Improving
1616-the setup experience is on my to-do list, but it's not yet ready.
1010+This is a standard Nix flake. so on a NixOS system, running `sudo nixos-rebuild
1111+--flake ./nixos#starlight switch` should do the trick. Note that you will need a
1212+handful of _secrets_ - refer to the flake files for details. Also, the wallpaper
1313+directory is not distributed as a part of this repo as that would be rude to
1414+the artists - find your own wallpapers! Improving the setup experience is on my
1515+to-do list, but it's not yet ready.
17161818-Note that this set-up is tweaked for my desktop PC and is currently not very modular or
1919-extensible. Improving this is also on my to-do list.
1717+Note that this set-up is tweaked for my desktop PC and is currently not very
1818+modular or extensible. Improving this is also on my to-do list.
-88
bin/change-wallpaper
···11-#!/usr/bin/env nu
22-33-use vlog.nu *
44-55-let WALLPAPER_LOCATION = $"($env.HOME)/.cache/current_wallpaper"
66-let LOCK_WALLPAPER_LOCATION = $"($env.HOME)/.cache/hyprlock_wallpaper.jpg"
77-let BLUR_WALLPAPER_LOCATION = $"($env.HOME)/.cache/blurred_wallpaper.jpg"
88-let WALLPAPER_FOLDER = $"($env.HOME)/Wallpapers"
99-1010-# Links the new wallpaper to the wallpaper cache, converts it to JPG for the lock screen if
1111-# necessary, and cleans up previous wallpaper if needed.
1212-def prepare-wallpaper [path: string] {
1313- # Clean up existing links/caches
1414- if ($LOCK_WALLPAPER_LOCATION | path exists) {
1515- vlog debug $" Removing lock-screen wallpaper from ($LOCK_WALLPAPER_LOCATION)..."
1616- rm $LOCK_WALLPAPER_LOCATION
1717- }
1818-1919- if ($BLUR_WALLPAPER_LOCATION | path exists) {
2020- vlog debug $" Removing blurred wallpaper from ($BLUR_WALLPAPER_LOCATION)..."
2121- rm $BLUR_WALLPAPER_LOCATION
2222- }
2323-2424- if ($WALLPAPER_LOCATION | path exists) {
2525- vlog debug $" Removing wallpaper link from ($WALLPAPER_LOCATION)..."
2626- rm $WALLPAPER_LOCATION
2727- }
2828-2929- # Determine if we have to use the "first frame" when converting to JPEG or not
3030- let wallpaperFileType = file --brief --dereference --mime $path
3131- if ($wallpaperFileType | str index-of 'image/gif') != -1 {
3232- # "index into" first frame of the GIF
3333- vlog debug $"🎥 Converting GIF to JPG..."
3434- magick $"($path)[0]" $LOCK_WALLPAPER_LOCATION
3535- } else {
3636- vlog debug $"👨🎨 Converting image to JPG..."
3737- magick $"($path)" $LOCK_WALLPAPER_LOCATION
3838- }
3939-4040- # Link to new location
4141- vlog debug $"🔗 Linking new wallpaper..."
4242- ln -fs $path $WALLPAPER_LOCATION
4343-}
4444-4545-# Switches the wallpaper to the prepared wallpaper.
4646-def switch-wallpaper [--transition-type (-t): string = "random", --filter (-f): string = "Nearest"] {
4747- vlog info "🌆 Transitioning wallpaper..."
4848- let params = [
4949- "img",
5050- $"--transition-type=($transition_type)",
5151- $"--filter=($filter)",
5252- $WALLPAPER_LOCATION
5353- ]
5454- vlog debug $"Params: ($params | to json -r)"
5555- swww ...$params
5656-}
5757-5858-# Returns a random file from the directory.
5959-def random-file [dir: string] {
6060- vlog info "🎲 Selecting random wallpaper..."
6161- let files = ls $dir
6262- let idx = random int 0..(($files | length) - 1)
6363-6464- $files | get $idx
6565-}
6666-6767-def set-wallpaper [path: string, --filter (-f): string = "Nearest"] {
6868- prepare-wallpaper $path
6969- switch-wallpaper --filter=($filter)
7070-}
7171-7272-def "main set" [path: string, --filter (-f): string = "Nearest"] {
7373- vlog timed "Wallpaper change" {
7474- set-wallpaper $path
7575- }
7676-}
7777-7878-def "main random" [] {
7979- vlog timed "Random wallpaper" {
8080- let wallpaper = random-file $WALLPAPER_FOLDER
8181- vlog debug $"Selected ($wallpaper.name) for new wallpaper."
8282- set-wallpaper $wallpaper.name
8383- }
8484-}
8585-8686-def main [] {
8787- help main
8888-}
···11-# Show notifications on primary display
22-output=HDMI-A-1
33-44-# Basic styling settings
55-font=Departure Mono 11px
66-max-icon-size=32
77-88-# By default, show just the summary
99-format=%s
1010-1111-# Catppuccin theme colours
1212-background-color=#24273a
1313-text-color=#cad3f5
1414-border-color=#1e2030
1515-1616-# Show notifications above any other window, even full-screen ones
1717-layer=overlay
1818-1919-# Only show one notification per app
2020-group-by=app-name
2121-2222-# Kill a notification after 7.5s if not otherwise specified
2323-default-timeout=7500
2424-2525-# Keep the last 20 notifications in the buffer so we can look back at them
2626-history=1
2727-max-history=20
2828-2929-# If the notification has a body, separate the body and the summary with a line.
3030-[body~=.+]
3131-format=%s\n──\n%b
3232-3333-# If `do-not-disturb` mode is enabled, hide all notifications
3434-[mode=do-not-disturb]
3535-invisible=1
3636-3737-# If `locked` mode is enabled, do not expire notifications. Keep them all in "limbo".
3838-[mode=locked]
3939-ignore-timeout=1
4040-default-timeout=0
4141-invisible=1
4242-4343-# vim: ft=config
···11-# A place to put all the extra commands and aliases that I might need.
22-33-# Switch the Kubernetes context with the magic of FZF.
44-def kctx [] {
55- kubectl config use-context (kubectl config get-contexts -o=name | fzf --height=30% --reverse)
66-}
77-88-# Pass to nushell's open command.
99-def nuopen [arg, --raw (-r)] {
1010- if $raw { open -r $arg } else { open $arg }
1111-}
1212-alias open = ^open
1313-1414-# List all projects (directories under ~/Code)
1515-def list-projects [] { ls -s $"($env.HOME)/Code" | sort-by -r modified | get name }
1616-1717-# Change to a project directory (directory under ~/Code).
1818-def --env view-project [dir: string@list-projects] {
1919- cd $"($env.HOME)/Code/($dir)"
2020-}
2121-2222-# Open the project in VS Code
2323-def open-project [dir: string@list-projects] {
2424- code $"($env.HOME)/Code/($dir)"
2525-}
2626-alias ccd = view-project
-14
config/ripgreprc
···11-# limit line length
22---max-columns=150
33---max-columns-preview
44-55-# also show hidden directories and files
66---hidden
77-88-# ignore Git data
99---glob=!.git/*
1010-1111---smart-case
1212-1313-# allow clicking on file names to open them
1414---hyperlink-format=kitty
···11+#!/usr/bin/env nu
22+33+use vlog
44+55+let WALLPAPER_LOCATION = $"($env.HOME)/.cache/current_wallpaper"
66+let LOCK_WALLPAPER_LOCATION = $"($env.HOME)/.cache/hyprlock_wallpaper.jpg"
77+let BLUR_WALLPAPER_LOCATION = $"($env.HOME)/.cache/blurred_wallpaper.jpg"
88+let WALLPAPER_FOLDER = $"($env.HOME)/Wallpapers"
99+1010+# Links the new wallpaper to the wallpaper cache, converts it to JPG for the lock screen if
1111+# necessary, and cleans up previous wallpaper if needed.
1212+def prepare-wallpaper [path: string] {
1313+ # Clean up existing links/caches
1414+ if ($LOCK_WALLPAPER_LOCATION | path exists) {
1515+ vlog debug $" Removing lock-screen wallpaper from ($LOCK_WALLPAPER_LOCATION)..."
1616+ rm $LOCK_WALLPAPER_LOCATION
1717+ }
1818+1919+ if ($BLUR_WALLPAPER_LOCATION | path exists) {
2020+ vlog debug $" Removing blurred wallpaper from ($BLUR_WALLPAPER_LOCATION)..."
2121+ rm $BLUR_WALLPAPER_LOCATION
2222+ }
2323+2424+ if ($WALLPAPER_LOCATION | path exists) {
2525+ vlog debug $" Removing wallpaper link from ($WALLPAPER_LOCATION)..."
2626+ rm $WALLPAPER_LOCATION
2727+ }
2828+2929+ # Determine if we have to use the "first frame" when converting to JPEG or not
3030+ let wallpaperFileType = file --brief --dereference --mime $path
3131+ if ($wallpaperFileType | str index-of 'image/gif') != -1 {
3232+ # "index into" first frame of the GIF
3333+ vlog debug $"🎥 Converting GIF to JPG..."
3434+ magick $"($path)[0]" $LOCK_WALLPAPER_LOCATION
3535+ } else {
3636+ vlog debug $"👨🎨 Converting image to JPG..."
3737+ magick $"($path)" $LOCK_WALLPAPER_LOCATION
3838+ }
3939+4040+ # Link to new location
4141+ vlog debug $"🔗 Linking new wallpaper..."
4242+ ln -fs $path $WALLPAPER_LOCATION
4343+}
4444+4545+# Switches the wallpaper to the prepared wallpaper.
4646+def switch-wallpaper [--transition-type (-t): string = "random", --filter (-f): string = "Nearest"] {
4747+ vlog info "🌆 Transitioning wallpaper..."
4848+ let params = [
4949+ "img",
5050+ $"--transition-type=($transition_type)",
5151+ $"--filter=($filter)",
5252+ $WALLPAPER_LOCATION
5353+ ]
5454+ vlog debug $"Params: ($params | to json -r)"
5555+ swww ...$params
5656+}
5757+5858+# Returns a random file from the directory.
5959+def random-file [dir: string] {
6060+ vlog info "🎲 Selecting random wallpaper..."
6161+ let files = ls $dir
6262+ let idx = random int 0..(($files | length) - 1)
6363+6464+ $files | get $idx
6565+}
6666+6767+def set-wallpaper [path: string, --filter (-f): string = "Nearest"] {
6868+ prepare-wallpaper $path
6969+ switch-wallpaper --filter=($filter)
7070+}
7171+7272+def "main set" [path: string, --filter (-f): string = "Nearest"] {
7373+ vlog timed "Wallpaper change" {
7474+ set-wallpaper $path
7575+ }
7676+}
7777+7878+def "main random" [] {
7979+ vlog timed "Random wallpaper" {
8080+ let wallpaper = random-file $WALLPAPER_FOLDER
8181+ vlog debug $"Selected ($wallpaper.name) for new wallpaper."
8282+ set-wallpaper $wallpaper.name
8383+ }
8484+}
8585+8686+def main [] {
8787+ help main
8888+}
+4
resources/scripts/bin/kctx
···11+#!/usr/bin/env nu
22+33+# Switch the Kubernetes context with the magic of FZF.
44+kubectl config use-context (kubectl config get-contexts -o=name | fzf --height=30% --reverse)
+48
resources/scripts/bin/manage-system
···11+#!/usr/bin/env nu
22+33+use vlog
44+55+let FLAKE_DIR = $"($env.HOME)/Code/dotfiles"
66+let SYSTEM_NAME = "starlight"
77+let FLAKE_NAME = $"($FLAKE_DIR)#($SYSTEM_NAME)"
88+99+# Update the Nix flake version.
1010+def "main update" [] {
1111+ vlog info $"🚚 Updating flake ($FLAKE_NAME)..."
1212+ vlog timed "Update" {
1313+ nix flake update --flake $FLAKE_DIR
1414+ }
1515+}
1616+1717+# Build a new derivation and switch to it.
1818+def "main rebuild" [] {
1919+ vlog timed "Rebuild" {
2020+ vlog info $"🏠 Building flake ($FLAKE_NAME)..."
2121+ sudo nixos-rebuild --flake $FLAKE_NAME --impure switch
2222+ }
2323+}
2424+2525+# Clean up garbage and optimise Nix store. (Most of the time this should happen automatically,
2626+# though.)
2727+def "main clean-up" [] {
2828+ vlog timed "Clean-up" {
2929+ vlog info "♻ Running garbage collection..."
3030+ sudo nix-collect-garbage --delete-old
3131+ }
3232+}
3333+3434+# Show the latest logs for a (root) systemd unit in reverse chronological order.
3535+def "main inspect" [service: string, --root (-r)] {
3636+ vlog info $"🤨 Inspecting ($service)..."
3737+ vlog timed "Service inspection" {
3838+ if $root {
3939+ sudo journalctl -u $service --reverse --since="15m ago"
4040+ } else {
4141+ journalctl --user -u $service --reverse --since="15m ago"
4242+ }
4343+ }
4444+}
4545+4646+def main [] {
4747+ help main
4848+}
+35
resources/scripts/bin/screen-lock
···11+#!/usr/bin/env nu
22+33+use vlog
44+55+def lock [] {
66+ if (pidof hyprlock | complete).exit_code == 0 {
77+ vlog warn "🔒 Screen already locked; exiting."
88+ return # we are already running hyprlock
99+ }
1010+ $env.LC_TIME = "en_GB.UTF8" # don't localize date names...
1111+ makoctl mode -a locked
1212+1313+ hyprlock # Block until we unlock
1414+1515+ after-unlock
1616+}
1717+1818+def after-unlock [] {
1919+ makoctl mode -r locked
2020+ vlog info "🔓 After-unlock triggered."
2121+}
2222+2323+# Lock the screen, if it is not already locked.
2424+def "main lock" [] {
2525+ lock
2626+}
2727+2828+# Send a signal to unlock the screen.
2929+def "main unlock" [] {
3030+ pkill -SIGUSR1 "hyprlock"
3131+}
3232+3333+def main [] {
3434+ help main
3535+}
+21
resources/scripts/lib/pm/mod.nu
···11+# "Project manager"
22+33+# List all projects (directories under ~/Code)
44+export def list [] {
55+ ls -s $"($env.HOME)/Code" | sort-by -r modified | get name
66+}
77+88+# Change to a project directory (directory under ~/Code).
99+export def --env go [dir: string@list] {
1010+ cd $"($env.HOME)/Code/($dir)"
1111+}
1212+1313+# Open the project in $EDITOR
1414+export def edit [dir: string@list] {
1515+ run-external $env.EDITOR $"($env.HOME)/Code/($dir)"
1616+}
1717+1818+# Load the project's .env file as env variables
1919+export def --env dotenv [] {
2020+ nuopen .env | from toml | load-env
2121+}