From b37371a61aa9f6ec3f4e4e4b118a9d06f3689b5e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 2 May 2025 16:15:52 +0200 Subject: ... --- accounts/gkleen@sif/default.nix | 85 +++++++++++++++++++++++++++++++++++++++-- accounts/gkleen@sif/zshrc | 62 +++++++++--------------------- overlays/lesspipe.nix | 2 +- user-profiles/utils.nix | 19 ++------- 4 files changed, 106 insertions(+), 62 deletions(-) diff --git a/accounts/gkleen@sif/default.nix b/accounts/gkleen@sif/default.nix index 6574af9d..e900370b 100644 --- a/accounts/gkleen@sif/default.nix +++ b/accounts/gkleen@sif/default.nix @@ -175,13 +175,92 @@ in { gpu-api = "vulkan"; }; - zsh.initExtra = '' - source ${./zshrc} + zsh.initExtra = let + zshrc = pkgs.resholve.mkDerivation { + pname = "zshrc"; + version = "0.0.0"; + + src = ./zshrc; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/share + install "$src" $out/share/zshrc + ''; + + solutions = { + default = { + scripts = [ "share/zshrc" ]; + interpreter = "none"; + inputs = with pkgs; [ + coreutils + rpm + binutils + squashfsTools + unzip + cfg.programs.git.package + magickWrapped + curl + file + gnutar + cpio + magic-wormhole + quickserve + cfg.programs.zsh.package + fuse + util-linux + findutils + qrencode + tty-clock + cfg.programs.jq.package + eza + less + config.systemd.package + config.programs.ssh.package + gnused + ]; + execer = with pkgs; [ + "cannot:${lib.getExe' rpm "rpm2cpio"}" + "cannot:${lib.getExe' squashfsTools "unsquashfs"}" + "cannot:${lib.getExe' unzip "unzip"}" + "cannot:${lib.getExe cfg.programs.git.package}" + "cannot:${lib.getExe cpio}" + "cannot:${lib.getExe' magic-wormhole "wormhole"}" + "cannot:${lib.getExe quickserve}" + "cannot:${lib.getExe' fuse "fusermount"}" + "cannot:${lib.getExe less}" + "cannot:${lib.getExe' config.systemd.package "systemctl"}" + "cannot:${lib.getExe config.programs.ssh.package}" + ]; + wrapper = with pkgs; [ + "${lib.getExe' magickWrapped "magick"}:${lib.getExe' imagemagick "magick"}" + ]; + fake = { + builtin = ["print"]; + external = ["sudo" "umount"]; + }; + }; + }; + }; + magickWrapped = pkgs.symlinkJoin { + inherit (pkgs.imagemagick) name; + paths = [ pkgs.imagemagick ]; + + buildInputs = with pkgs; [ makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/magick \ + --prefix PATH : ${lib.makeBinPath (with pkgs; [ ghostscript ])} + ''; + }; + in '' + source ${zshrc}/share/zshrc ''; zsh.dirHashes = let flakeHashes = mapAttrs' (n: v: nameValuePair (inputNames.${n} or n) (toString v)) flakeInputs; inputNames = { - "nixpkgs" = "nixos"; }; in flakeHashes // { u2w = "$HOME/projects/uni2work"; diff --git a/accounts/gkleen@sif/zshrc b/accounts/gkleen@sif/zshrc index c628e2e9..06f6f6f2 100644 --- a/accounts/gkleen@sif/zshrc +++ b/accounts/gkleen@sif/zshrc @@ -2,8 +2,6 @@ dir() { curlArchive=false templateArchive="" repoUrl="" - nixShell="" - findNix=false dir="" forceShell=false wormhole=false @@ -12,7 +10,7 @@ dir() { quickserve=false modifyPDF="" - while getopts ':t:a:s:Sd:ir:wqg:p:' arg; do + while getopts ':t:a:d:ir:wqg:p:' arg; do case $arg in "t") ;; "a") @@ -23,8 +21,6 @@ dir() { templateArchive=${OPTARG:a} fi ;; - "s") nixShell=${OPTARG:a} ;; - "S") findNix=true ;; "d") dir=${OPTARG} ;; "i") forceShell=true ;; "r") repoUrl=${OPTARG} ;; @@ -59,7 +55,11 @@ dir() { cleanup() { cd ${modifyPDF:h} - [[ -n ${modifyPDF} ]] && nix shell 'nixos#imagemagick' -c convert -verbose ${dir}/${modifyPDF:t:r}_*.png(on) ${modifyPDF} + if [[ -n ${modifyPDF} ]]; then + typeset -a pages + eval 'pages=(${dir}/${modifyPDF:t:r}_*.png(on))' + magick -verbose "$pages" ${modifyPDF} + fi } ( @@ -68,8 +68,6 @@ dir() { cd ${dir} export dir; - ${findNix} && { nixShell=$(findNix) || return $? } - [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} . [[ -n ${modifyPDF} ]] && templateArchive=${modifyPDF} @@ -82,7 +80,7 @@ dir() { } trap cleanup EXIT - if ${curlArchive}; then + if [[ $curlArchive = "true" ]]; then archiveFile=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t}") curl -L -o ${archiveFile} ${templateArchive} @@ -91,14 +89,14 @@ dir() { fi unpack=true - while ${unpack}; do + while [[ $unpack = "true" ]]; do case $(file --brief --mime-type --dereference ${templateArchive}) in application/zip) unzip ${templateArchive} unpack=false ;; application/vnd.debian.binary-package) - nix shell 'nixos#binutils' --command ar x ${templateArchive} + ar x ${templateArchive} mkdir control data tar -C control -xvaf control.* tar -C data -xvaf data.* @@ -106,7 +104,7 @@ dir() { ;; application/x-rpm) cpioArchive=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t:r}.cpio") - nix shell 'nixos#busybox' --command rpm2cpio ${templateArchive} > ${cpioArchive} + rpm2cpio ${templateArchive} > ${cpioArchive} templateArchive=${cpioArchive} unpack=true ;; @@ -115,12 +113,12 @@ dir() { unpack=false ;; application/pdf) - nix shell 'nixos#ghostscript' 'nixos#imagemagick' -c convert -verbose -density 400 ${templateArchive} ${modifyPDF:t:r}_%0d.png + magick -verbose -density 400 ${templateArchive} ${modifyPDF:t:r}_%0d.png unpack=false ;; application/octet-stream) - if [[ $(file --brief --dereferenc ${templateArchive}) =~ Squashfs ]]; then - nix shell 'nixos#squashfsTools' -c unsquashfs -d . ${templateArchive} + if [[ $(file --brief --dereference ${templateArchive}) =~ Squashfs ]]; then + unsquashfs -d . ${templateArchive} unpack=false fi ;; @@ -134,21 +132,17 @@ dir() { fi - ${wormhole} && wormhole receive --accept-file + [[ $wormhole = "true" ]] && wormhole receive --accept-file - if ${quickserve}; then + if [[ $quickserve = "true" ]]; then quickserve --root . --upload . --show-hidden --tar gz fi - if [[ ${#@} -eq 0 ]] || ${forceShell}; then + if [[ ${#@} -eq 0 ]] || [[ $forceShell = "true" ]]; then if [[ ${#@} -gt 0 ]]; then - if [[ -z ${nixShell} ]]; then - ${@} - else - nix-shell ${nixShell} --run "${@}" - fi + ${@} fi cd $(pwd) # Needed for mounting to work @@ -167,17 +161,9 @@ dir() { while d=$(isSingleDir); do cd ${d}; done - if [[ -z ${nixShell} ]]; then - zsh - else - nix-shell ${nixShell} --run zsh - fi + zsh else - if [[ -z ${nixShell} ]]; then - ${@} - else - nix-shell ${nixShell} --run "${@}" - fi + ${@} fi ) } @@ -234,16 +220,6 @@ public-ip() { curl -s -H 'Accept: application/json' $@ ifconfig.co | jq -r '.ip' } -nix-ghci() { - pkgExpr="" - if [[ ${#@} -gt 0 ]]; then - pkgExpr="${1}" - shift - fi - - nix-shell -p "with (import {}); pkgs.haskellPackages.ghcWithPackages (p: with p; [${pkgExpr}])" --run "ghci ${@}" -} - swap() { f1=${1} f2=${2} diff --git a/overlays/lesspipe.nix b/overlays/lesspipe.nix index 3258eb70..b791f6e5 100644 --- a/overlays/lesspipe.nix +++ b/overlays/lesspipe.nix @@ -17,7 +17,7 @@ preFixup = '' wrapProgram $out/bin/lesspipe.sh \ - --prefix PATH : ${final.python3.pkgs.pygments}/bin:${final.file}/bin:${final.ncurses}/bin + --prefix PATH : ${prev.lib.makeBinPath (with final; [ file ncurses binutils ])} ''; }; } diff --git a/user-profiles/utils.nix b/user-profiles/utils.nix index 13eb6033..4b7c4d0f 100644 --- a/user-profiles/utils.nix +++ b/user-profiles/utils.nix @@ -1,19 +1,6 @@ { userName, lib, pkgs, config, ... }: let cfg = config.home-manager.users.${userName}; - - wrappedLess = pkgs.less.overrideAttrs (oldAttrs: { - pname = "${oldAttrs.pname or "less"}-wrapper"; - - nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ (with pkgs; [makeWrapper]); - - postInstall = '' - ${oldAttrs.postInstall or ""} - - wrapProgram $out/bin/less \ - --prefix PATH : ${lib.makeBinPath (with pkgs; [binutils])} - ''; - }); in { home-manager.users.${userName} = { programs = { @@ -55,10 +42,12 @@ in { }; jq.enable = true; + + lesspipe.enable = true; }; home.sessionVariables = { - LESSCOLORIZER = "pygmentize -O style=rrt"; + LESSCOLORIZER = "${lib.getExe' pkgs.python3Packages.pygments "pygmentize"} -O style=rrt"; }; home.packages = with pkgs; [ @@ -67,7 +56,7 @@ in { psmisc mosh tree vnstat file pv bc zip nmap aspell aspellDicts.de aspellDicts.en borgbackup man-pages rsync socat inetutils yq cached-nix-shell persistent-nix-shell rage - smartmontools hdparm nix-output-monitor wrappedLess dscp + smartmontools hdparm nix-output-monitor less dscp iputils ]; }; -- cgit v1.2.3