From 94c12e9cdb1b55439f5a3de2def50b4f52accb3f Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 26 Jan 2025 15:55:30 +0100 Subject: [PATCH] home: make bashrc.d --- .../pbsds/home/profiles/bashrc.d/default.nix | 11 +++++ users/pbsds/home/profiles/bashrc.d/destore.sh | 20 ++++++++ users/pbsds/home/profiles/bashrc.d/mnix.sh | 20 ++++++++ .../pbsds/home/profiles/desktop/sshuttle.nix | 4 +- users/pbsds/home/profiles/shell.nix | 48 ++----------------- 5 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 users/pbsds/home/profiles/bashrc.d/default.nix create mode 100644 users/pbsds/home/profiles/bashrc.d/destore.sh create mode 100644 users/pbsds/home/profiles/bashrc.d/mnix.sh diff --git a/users/pbsds/home/profiles/bashrc.d/default.nix b/users/pbsds/home/profiles/bashrc.d/default.nix new file mode 100644 index 0000000..435aedb --- /dev/null +++ b/users/pbsds/home/profiles/bashrc.d/default.nix @@ -0,0 +1,11 @@ +{ lib, ... }: +{ + programs.bash.initExtra = lib.pipe (builtins.readDir ./.) [ + (lib.filterAttrs (k: v: v == "regular")) + (lib.filterAttrs (k: v: lib.hasSuffix ".sh" k)) + lib.attrNames + /* (map (x: builtins.readFile ./${x})) */ + (map (x: "source ${./${x}}")) + lib.concatLines + ]; +} diff --git a/users/pbsds/home/profiles/bashrc.d/destore.sh b/users/pbsds/home/profiles/bashrc.d/destore.sh new file mode 100644 index 0000000..937551f --- /dev/null +++ b/users/pbsds/home/profiles/bashrc.d/destore.sh @@ -0,0 +1,20 @@ +destore() { + for dst in "$@"; do + test -L "$dst" || continue + # TODO: assert dst is in the store + src="$(realpath "$dst")" + if test -d "$src"; then + (set -x + rm -v "$dst" + cp -r --dereference --one-file-system "$src/" "$dst/" + chmod -R +rw "$dst" + ) + elif test -f "$src"; then + (set -x + rm -v "$dst" + cp -v "$src" "$dst" + chmod -v +rw "$dst" + ) + fi + done +} diff --git a/users/pbsds/home/profiles/bashrc.d/mnix.sh b/users/pbsds/home/profiles/bashrc.d/mnix.sh new file mode 100644 index 0000000..f6934f0 --- /dev/null +++ b/users/pbsds/home/profiles/bashrc.d/mnix.sh @@ -0,0 +1,20 @@ +_choose_nix_systems() { + # x86_64-linux aarch64-linux aarch64-darwin x86_64-darwin i686-linux riscv64-linux x86_64-freebsd aarch64-freebsd i686-freebsd riscv64-freebsd + gum choose --no-limit --ordered --height 15 {linux,darwin,freebsd}-{x86_64,aarch64,i686,riscv64} \ + | sed -E 's/^([^-]*)-([^-]*)$/\2-\1/' +} + +mnix-build() { + # TODO: somehow store the out-links + _choose_nix_systems | xe -j0 -s 'nix-instantiate --system "$1" '"$(printf " %q" "$@")" | xargs nix-build --keep-going --no-out-link +} +mnom-build() { + # TODO: somehow store the out-links + _choose_nix_systems | xe -j0 -s 'nix-instantiate --system "$1" '"$(printf " %q" "$@")" | xargs nom-build --keep-going --no-out-link +} +mnixpkgs-review() { + # TODO: use /run/user/... + # mkdir -p /dev/shm/nixpkgs-review + # ln -sfn /dev/shm/nixpkgs-review $HOME/.cache/nixpkgs-review + nixpkgs-review --systems "$(_choose_nix_systems | xargs)" "$@" +} diff --git a/users/pbsds/home/profiles/desktop/sshuttle.nix b/users/pbsds/home/profiles/desktop/sshuttle.nix index 1107306..764cb0b 100644 --- a/users/pbsds/home/profiles/desktop/sshuttle.nix +++ b/users/pbsds/home/profiles/desktop/sshuttle.nix @@ -6,8 +6,8 @@ ]; programs.bash.initExtra = '' - function vpn ( - ip="$(dig +short -x a $1 | tail -n 1)" + vpn() ( + ip="$(dig +short -x a $1 | tail -n 1)" set -x #sshuttle 0.0.0.0/0 --disable-ipv6 --dns -r "$1" -x $ip -x 127.0.0.1 -x 172.0.0.0/8 sshuttle 0.0.0.0/0 ::/0 --dns -r "$1" -x $ip -x 127.0.0.1 -x 172.0.0.0/8 diff --git a/users/pbsds/home/profiles/shell.nix b/users/pbsds/home/profiles/shell.nix index 816f181..f5d3c38 100644 --- a/users/pbsds/home/profiles/shell.nix +++ b/users/pbsds/home/profiles/shell.nix @@ -35,52 +35,12 @@ in if command -v tldr >/dev/null; then complete -F _command tldr fi - - destore() { - for dst in "$@"; do - test -L "$dst" || continue - # TODO: assert dst is in the store - src="$(realpath "$dst")" - if test -d "$src"; then - (set -x - rm -v "$dst" - cp -r --dereference --one-file-system "$src/" "$dst/" - chmod -R +rw "$dst" - ) - elif test -f "$src"; then - (set -x - rm -v "$dst" - cp -v "$src" "$dst" - chmod -v +rw "$dst" - ) - fi - done - } - - _choose_nix_systems() { - # x86_64-linux aarch64-linux aarch64-darwin x86_64-darwin i686-linux riscv64-linux x86_64-freebsd aarch64-freebsd i686-freebsd riscv64-freebsd - gum choose --no-limit --ordered --height 15 {linux,darwin,freebsd}-{x86_64,aarch64,i686,riscv64} \ - | sed -E 's/^([^-]*)-([^-]*)$/\2-\1/' - } - - mnix-build() { - # TODO: somehow store the out-links - _choose_nix_systems | xe -j0 -s 'nix-instantiate --system "$1" '"$(printf " %q" "$@")" | xargs nix-build --keep-going --no-out-link - } - mnom-build() { - # TODO: somehow store the out-links - _choose_nix_systems | xe -j0 -s 'nix-instantiate --system "$1" '"$(printf " %q" "$@")" | xargs nom-build --keep-going --no-out-link - } - mnixpkgs-review() { - # TODO: use /run/user/... - # mkdir -p /dev/shm/nixpkgs-review - # ln -sfn /dev/shm/nixpkgs-review $HOME/.cache/nixpkgs-review - nixpkgs-review --systems "$(_choose_nix_systems | xargs)" "$@" - } - ''; - imports = [ ../modules/jump.nix ]; + imports = [ + ../profiles/bashrc.d + ../modules/jump.nix + ]; programs.jump.enableBash = true; programs.nix-index.enable = true;