Create nushell application wrapper

Also move elements to `/nix/elements`.
This commit is contained in:
Christopher Mühl 2025-11-18 12:10:38 +01:00
parent b98774c1bf
commit 0fa23fdd05
No known key found for this signature in database
GPG key ID: E919B0F59E14FD47
18 changed files with 186 additions and 87 deletions

6
flake.lock generated
View file

@ -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": {

View file

@ -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";

View file

@ -3,7 +3,7 @@
# Dev tools
git
gh
gitAndTools.git-absorb
git-absorb
delta # Diffing tool
onefetch # neofetch for git repos

View file

@ -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

View file

@ -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;};

View file

@ -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;
}

View file

@ -15,6 +15,7 @@
git
gitleaks
just
nh
age
];
}

View file

@ -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 = {

View file

@ -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";

View file

@ -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";

View file

@ -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
# }
# '';
}

View file

@ -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
'';
};
}

View file

@ -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;
};
}

View file

@ -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;
}

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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