From 0fa23fdd05c4ec0a55127e3c03208a6740e1ea6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20M=C3=BChl?= Date: Tue, 18 Nov 2025 12:10:38 +0100 Subject: [PATCH] Create nushell application wrapper Also move elements to `/nix/elements`. --- flake.lock | 6 +- flake.nix | 9 +- .../christopher@cobalt/config/git.nix | 2 +- .../christopher@cobalt/misc/everything.nix | 3 +- lib/default.nix | 3 +- lib/writeNushellApplication.nix | 109 ++++++++++++++++++ modules/common/default.nix | 1 + modules/common/nix.nix | 25 ++-- modules/home/common/terminal/default.nix | 4 +- .../home/common/terminal/shell/aliases.nix | 4 +- .../common/terminal/shell/fish/default.nix | 35 ------ modules/home/gui/kitty.nix | 11 ++ modules/nixos/wm/default.nix | 17 +-- overlays/unstable/default.nix | 2 +- packages/scripts/open-url/default.nix | 4 +- packages/scripts/open-url/open-url | 2 +- packages/scripts/spawn-term/default.nix | 29 +++-- shells/deploy/Justfile | 7 +- 18 files changed, 186 insertions(+), 87 deletions(-) create mode 100644 lib/writeNushellApplication.nix delete mode 100644 modules/home/common/terminal/shell/fish/default.nix diff --git a/flake.lock b/flake.lock index 17ce3dc..ff03fad 100644 --- a/flake.lock +++ b/flake.lock @@ -548,11 +548,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1763049705, - "narHash": "sha256-A5LS0AJZ1yDPTa2fHxufZN++n8MCmtgrJDtxFxrH4S8=", + "lastModified": 1763334038, + "narHash": "sha256-LBVOyaH6NFzQ3X/c6vfMZ9k4SV2ofhpxeL9YnhHNJQQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3acb677ea67d4c6218f33de0db0955f116b7588c", + "rev": "4c8cdd5b1a630e8f72c9dd9bf582b1afb3127d2c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 52b196b..985ea71 100644 --- a/flake.nix +++ b/flake.nix @@ -39,9 +39,11 @@ ]; }; - homes.users."christopher@beryllium".modules = with inputs; [ - quadlet.homeManagerModules.quadlet - ]; + homes.users = { + "christopher@beryllium".modules = with inputs; [ + quadlet.homeManagerModules.quadlet + ]; + }; # Configure nixpkgs when instantiating the package set # TODO: This is already specified elsewhere. Still needed here? @@ -65,6 +67,7 @@ }; inputs = { + # nixpkgs.url = "git+file:///home/christopher/code/opensource/nixpkgs"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; diff --git a/homes/x86_64-linux/christopher@cobalt/config/git.nix b/homes/x86_64-linux/christopher@cobalt/config/git.nix index 911f9aa..710088a 100644 --- a/homes/x86_64-linux/christopher@cobalt/config/git.nix +++ b/homes/x86_64-linux/christopher@cobalt/config/git.nix @@ -3,7 +3,7 @@ # Dev tools git gh - gitAndTools.git-absorb + git-absorb delta # Diffing tool onefetch # neofetch for git repos diff --git a/homes/x86_64-linux/christopher@cobalt/misc/everything.nix b/homes/x86_64-linux/christopher@cobalt/misc/everything.nix index 64bfcc4..0383a99 100644 --- a/homes/x86_64-linux/christopher@cobalt/misc/everything.nix +++ b/homes/x86_64-linux/christopher@cobalt/misc/everything.nix @@ -21,7 +21,7 @@ vlc # Video player obsidian # Note taking calibre # eBook Manager - onlyoffice-bin # libreoffice alternative + onlyoffice-desktopeditors # libreoffice alternative filezilla # FTP Client orca-slicer # Bambu Lab Slicer + Control krita # Drawing software @@ -34,7 +34,6 @@ davinci-resolve # Video editor cider-2 # Apple music player - feh # Image viewer xarchiver # Archive viewer/extractor zathura # Document viewer evince # Document viewer diff --git a/lib/default.nix b/lib/default.nix index 7801f8a..f984900 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,8 +1,9 @@ -{lib, ...}: { +{lib, ...} @ all: { rootPath = ./..; secret = name: ./../secrets/${name}; commonHomeModule = module: ./../homes/common + "/${module}"; + writeNushellApplication = import ./writeNushellApplication.nix {inherit lib;}; enabled = {enable = true;}; disabled = {enable = false;}; diff --git a/lib/writeNushellApplication.nix b/lib/writeNushellApplication.nix new file mode 100644 index 0000000..c87f8d9 --- /dev/null +++ b/lib/writeNushellApplication.nix @@ -0,0 +1,109 @@ +{lib, ...}: pkgs: { + /* + The name of the script to write. + + Type: String + */ + name, + /* + The shell script's text, not including a shebang. + + Type: String + */ + text, + /* + Inputs to add to the shell script's `$PATH` at runtime. + + Type: [String|Derivation] + */ + runtimeInputs ? [], + /* + Extra environment variables to set at runtime. + + Type: AttrSet + */ + runtimeEnv ? null, + /* + `stdenv.mkDerivation`'s `meta` argument. + + Type: AttrSet + */ + meta ? {}, + /* + `stdenv.mkDerivation`'s `passthru` argument. + + Type: AttrSet + */ + passthru ? {}, + /* + The `checkPhase` to run. Defaults to `shellcheck` on supported + platforms and `bash -n`. + + The script path will be given as `$target` in the `checkPhase`. + + Type: String + */ + checkPhase ? null, + /* + Extra arguments to pass to `stdenv.mkDerivation`. + + :::{.caution} + Certain derivation attributes are used internally, + overriding those could cause problems. + ::: + + Type: AttrSet + */ + derivationArgs ? {}, + /* + Whether to inherit the current `$PATH` in the script. + + Type: Bool + */ + inheritPath ? true, +}: let + nu = pkgs.nushell; +in + pkgs.writeTextFile { + inherit + name + meta + passthru + derivationArgs + ; + executable = true; + destination = "/bin/${name}"; + allowSubstitutes = true; + preferLocalBuild = false; + + text = + '' + #!${nu}${nu.shellPath} + + use std/util "path add" + '' + + lib.optionalString (runtimeEnv != null) ( + lib.concatMapAttrsStringSep "" (name: value: '' + $env.${lib.toShellVar name value} + export ${name} + '') + runtimeEnv + ) + + lib.optionalString (runtimeInputs != []) ('' + ${lib.optionalString (! inheritPath) "$env.PATH = []"} + '' + + lib.concatStringsSep ":" (map (path: '' + path add '${path}/bin' + '') + runtimeInputs)) + + text; + + checkPhase = + if checkPhase == null + then '' + runHook preCheck + ${nu}${nu.shellPath} -c "nu-check --debug $target" + runHook postCheck + '' + else checkPhase; + } diff --git a/modules/common/default.nix b/modules/common/default.nix index 1883482..ee51551 100644 --- a/modules/common/default.nix +++ b/modules/common/default.nix @@ -15,6 +15,7 @@ git gitleaks just + nh age ]; } diff --git a/modules/common/nix.nix b/modules/common/nix.nix index f858dbd..82fc9d8 100644 --- a/modules/common/nix.nix +++ b/modules/common/nix.nix @@ -4,20 +4,23 @@ config, ... }: { - nix.settings = { - # auto-optimize-store = true; - # builders-use-substitutes = true; - experimental-features = ["nix-command" "flakes"]; - flake-registry = "/etc/nix/registry.json"; + nix = { + # Automatic cleanup + gc.automatic = true; + gc.dates = "weekly"; + gc.options = "--delete-older-than 21d"; - keep-derivations = true; - keep-outputs = true; + settings = { + # builders-use-substitutes = true; + experimental-features = ["nix-command" "flakes"]; + flake-registry = "/etc/nix/registry.json"; - trusted-users = ["root" "@wheel"]; + keep-derivations = true; + keep-outputs = true; - substituters = [ - "https://cache.nixos.org/" - ]; + trusted-users = ["root" "@wheel"]; + substituters = ["https://cache.nixos.org/"]; + }; }; nixpkgs = { diff --git a/modules/home/common/terminal/default.nix b/modules/home/common/terminal/default.nix index 04dcde4..2f6c75c 100644 --- a/modules/home/common/terminal/default.nix +++ b/modules/home/common/terminal/default.nix @@ -7,8 +7,7 @@ in { ./programs ./shell/aliases.nix ./shell/prompt.nix - ./shell/nu - ./shell/fish + # ./shell/nu ]; # add environment variables @@ -22,6 +21,7 @@ in { TERMINAL = "kitty"; EDITOR = "hx"; TERM = "xterm-color"; + QT_QPA_PLATFORMTHEME = "qt5ct"; # auto-run programs using nix-index-database NIX_AUTO_RUN = "1"; diff --git a/modules/home/common/terminal/shell/aliases.nix b/modules/home/common/terminal/shell/aliases.nix index d77b1bf..0b30614 100644 --- a/modules/home/common/terminal/shell/aliases.nix +++ b/modules/home/common/terminal/shell/aliases.nix @@ -1,7 +1,7 @@ {lib, ...}: { home.shellAliases = { - elements = "just -f ~/.dotfiles/Justfile -d ~/.dotfiles"; - elem = "elements"; + elements = "just -f /nix/elements/Justfile -d /nix/elements"; + elm = "elements"; g = "git"; copy = lib.mkDefault "wl-copy"; inspect = "tmux -f ~/.tmux.inspect.conf new-session ssh inspect"; diff --git a/modules/home/common/terminal/shell/fish/default.nix b/modules/home/common/terminal/shell/fish/default.nix deleted file mode 100644 index 6616ba3..0000000 --- a/modules/home/common/terminal/shell/fish/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - pkgs, - config, - ... -}: { - programs.fish = { - enable = true; - shellAliases = config.home.shellAliases; - }; - - # config = '' - # export PATH="$HOME/code/hausgold/snippets/bin:$PATH" - # export PATH="$HOME/.bun/bin:$HOME/.npm/bin:$PATH" - - # art() - # { - # if [ -f "./vendor/bin/sail" ]; - # then - # ./vendor/bin/sail artisan "$@" - # else - # php artisan "$@" - # fi - # } - - # sail() - # { - # if [ -f "./vendor/bin/sail" ]; - # then - # ./vendor/bin/sail "$@" - # else - # echo "Sail is not installed. Run 'composer require laravel/sail' to install it." - # fi - # } - # ''; -} diff --git a/modules/home/gui/kitty.nix b/modules/home/gui/kitty.nix index a002945..c87a53f 100644 --- a/modules/home/gui/kitty.nix +++ b/modules/home/gui/kitty.nix @@ -23,6 +23,10 @@ in { paste_actions = "no-op"; }; + actionAliases = { + "launch_current" = "launch --cwd current"; + }; + extraConfig = '' shell ${pkgs.nushell}/bin/nu modify_font cell_height 7px @@ -30,5 +34,12 @@ in { themeFile = "Catppuccin-Frappe"; }; + + xdg.configFile."kitty/open-actions.conf".text = '' + # Open all file links in helix in the current shell + protocol file + # mime text/* + action send_text normal,application hx "''${FILE_PATH}"\r + ''; }; } diff --git a/modules/nixos/wm/default.nix b/modules/nixos/wm/default.nix index 06a8d1f..886be9f 100644 --- a/modules/nixos/wm/default.nix +++ b/modules/nixos/wm/default.nix @@ -37,16 +37,17 @@ in { }; services.desktopManager.plasma6.enable = true; - services.displayManager.defaultSession = "plasma"; - # services.displayManager.sddm.enable = true; - # services.displayManager.sddm.wayland.enable = true; - # services.displayManager.sddm.wayland.compositor = "kwin"; + services.displayManager = { + defaultSession = "plasma"; + + # sddm = { + # enable = true; + # wayland.enable = true; + # }; + }; # xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-gtk]; - security = { - polkit.enable = true; - pam.services.swaylock = {}; - }; + security.polkit.enable = true; }; } diff --git a/overlays/unstable/default.nix b/overlays/unstable/default.nix index 03798db..7e10b74 100644 --- a/overlays/unstable/default.nix +++ b/overlays/unstable/default.nix @@ -1,4 +1,4 @@ {channels, ...}: final: prev: { # Pull the following packages from unstable instead - inherit (channels.unstable) kitty nu fish cider-2; + inherit (channels.unstable) kitty nu fish cider-2 _1password-gui; } diff --git a/packages/scripts/open-url/default.nix b/packages/scripts/open-url/default.nix index c240a76..b669a9c 100644 --- a/packages/scripts/open-url/default.nix +++ b/packages/scripts/open-url/default.nix @@ -8,7 +8,9 @@ desktopItem = pkgs.makeDesktopItem { inherit name; desktopName = "Open URL in a Browser"; - exec = "${bin}/bin/${name}"; + comment = "Open the given URL in a browser-profile based on context"; + mimeTypes = ["x-scheme-handler/http" "x-scheme-handler/https"]; + exec = "${bin}/bin/${name} %u"; }; in pkgs.symlinkJoin { diff --git a/packages/scripts/open-url/open-url b/packages/scripts/open-url/open-url index 92b0973..4013416 100755 --- a/packages/scripts/open-url/open-url +++ b/packages/scripts/open-url/open-url @@ -17,7 +17,7 @@ while [ "$parent" -ne 1 ]; do parent=$(ps -o ppid= -p "$parent" | tail -n 1 | awk '{print $1}') done -if [[ $1 == "https://github.com/hausgold"* ]]; then +if [[ ${1:-} == "https://github.com/hausgold"* ]]; then # Also use the `Work` profile for hausgold Github links open_browser "Work" "$@" else diff --git a/packages/scripts/spawn-term/default.nix b/packages/scripts/spawn-term/default.nix index df295b4..f83db38 100644 --- a/packages/scripts/spawn-term/default.nix +++ b/packages/scripts/spawn-term/default.nix @@ -1,22 +1,29 @@ -{pkgs, ...}: -pkgs.writeTextFile rec { +{ + lib, + pkgs, + ... +}: +lib._elements.writeNushellApplication pkgs { name = "spawn-term"; - destination = "/bin/${name}"; - executable = true; + runtimeInputs = with pkgs; [kdotool]; text = '' - #!/usr/bin/env nu + let focused_window = (kdotool getactivewindow) - let focused_window = (niri msg --json windows | from json | where { $in.is_focused == true } | first) - - if ($focused_window | get app_id) == "kitty" { - let child_pid = (pgrep -P $"($focused_window | get pid)" | tail -1) - if ($child_pid | is-empty) { + if (kdotool getwindowclassname $focused_window) == "kitty" { + let kitty_pid = (kdotool getwindowpid $focused_window | into int) + if ($kitty_pid | is-empty) { kitty exit 0 } - let path = ($"/proc/($child_pid)/cwd" | path expand) + let shell_pid = (ps | where ppid == $kitty_pid | where name != "kitten" | get pid | first) + if ($shell_pid | is-empty) { + kitty + exit 0 + } + + let path = ($"/proc/($shell_pid)/cwd" | path expand) kitty --directory $path } else { kitty diff --git a/shells/deploy/Justfile b/shells/deploy/Justfile index 9799a2e..63b816d 100644 --- a/shells/deploy/Justfile +++ b/shells/deploy/Justfile @@ -25,13 +25,10 @@ install host: #!/usr/bin/env bash sudo nixos-install --flake "$(pwd)#{{host}}" -# Deploys the dotfile repository to a user's home dir. +# Deploys the dotfile repository to the host. [no-cd] config host user: - #!/usr/bin/env bash - set -euxo pipefail - home=$(nix eval --extra-experimental-features "nix-command flakes" --impure --expr "(builtins.getFlake \"$(pwd)\").nixosConfigurations.{{host}}.config.users.users.{{user}}.home" | tail -n 1 | tr -d \") - cp -R $(pwd) "/mnt$home/.dotfiles" + cp -R $(pwd) "/mnt/nix/elements" # send-key: # croc send ~/.ssh/id_key