diff options
Diffstat (limited to '')
-rw-r--r-- | packages/nixfiles.nix | 151 |
1 files changed, 80 insertions, 71 deletions
diff --git a/packages/nixfiles.nix b/packages/nixfiles.nix index 3f17edc..9b16e84 100644 --- a/packages/nixfiles.nix +++ b/packages/nixfiles.nix @@ -26,75 +26,83 @@ cmd=$1 shift case $cmd in - repl|eval|build|rev) - args=() flakeArgs=() - for arg do case $arg in - -w|--wip) flakeArgs+=(--override-flake nixfiles "$nixfiles");; - *) args+=("$arg") - esac done - set -- "''${args[@]}" - ;;& - - compare) - input=$1 - # shellcheck disable=SC1090 - . <(nix flake metadata --json nixfiles | jq -r --arg input "$input" ' - def browse($url): @sh "xdg-open \($url)"; - .locks.nodes[$input] | - if .locked.type == "github" then - browse("https://github.com/\(.locked.owner)/\(.locked.repo)/compare/\(.locked.rev)...\(.original.ref // "master")") - elif .locked.type == "gitlab" then - browse("https://gitlab.com/\(.locked.owner)/\(.locked.repo)/-/compare/\(.locked.rev)...\(.original.ref // "master")") - else - "echo unsupported input type \(.locked.type) (supported: github, gitlab)" - end - ') - ;; - update) - if (( $# )); then - args=() - for input do args+=(--update-input "$input"); done - exec nix flake lock --refresh "''${args[@]}" "$nixfiles" - else - # https://github.com/NixOS/nix/issues/6095 - exec nix flake update -v --refresh "$nixfiles" - fi - ;; - rev) - if (( $# )); then - expr=inputs.''${1//'/'/.inputs.}.rev - else - expr=self.revision - fi - nix eval "''${flakeArgs[@]}" -f ~/.nix-defexpr --raw "$expr" - echo - ;; - - repl) - exec nix repl "''${flakeArgs[@]}" -f ~/.nix-defexpr "$@";; - eval) - exec nix eval "''${flakeArgs[@]}" -f ~/.nix-defexpr --json "$@" | jq -r .;; - build) - # https://github.com/NixOS/nix/issues/6661 - exec nix-build --log-format bar-with-logs "''${flakeArgs[@]}" ~/.nix-defexpr -A "$@";; - - specialise) - name=$1 - shift - exec sudo /run/current-system/specialisation/"$name"/bin/switch-to-configuration switch;; - revert) - exec sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch;; - - home) - attr=nixosConfigurations."$HOSTNAME".config.hm.home.activationPackage - export VERBOSE=1 - exec nix shell -v ".#$attr" "$@" -c home-manager-generation;; - @*) - host=''${cmd#@} - hostname=$(ssh -q "$host" 'echo "$HOSTNAME"') - exec nixos-rebuild -v --flake ".#$hostname" --target-host "$host" --use-remote-sudo "$@";; - *) - exec nixos-rebuild -v --fast --flake "." --use-remote-sudo "$cmd" "$@";; + repl|eval|build|rev) + args=() flakeArgs=() + for arg do case $arg in + -w|--wip) + flakeArgs+=(--override-flake nixfiles "$nixfiles") + ;; + *) + args+=("$arg") + ;; + esac done + set -- "''${args[@]}" + ;;& + compare) + input=$1 + # shellcheck disable=SC1090 + . <(nix flake metadata --json nixfiles | jq -r --arg input "$input" ' + def browse($url): @sh "xdg-open \($url)"; + .locks.nodes[$input] | + if .locked.type == "github" then + browse("https://github.com/\(.locked.owner)/\(.locked.repo)/compare/\(.locked.rev)...\(.original.ref // "master")") + elif .locked.type == "gitlab" then + browse("https://gitlab.com/\(.locked.owner)/\(.locked.repo)/-/compare/\(.locked.rev)...\(.original.ref // "master")") + else + "echo unsupported input type \(.locked.type) (supported: github, gitlab)" + end + ') + ;; + update) + if (( $# )); then + args=() + for input do args+=(--update-input "$input"); done + exec nix flake lock --refresh "''${args[@]}" "$nixfiles" + else + # https://github.com/NixOS/nix/issues/6095 + exec nix flake update -v --refresh "$nixfiles" + fi + ;; + rev) + if (( $# )); then + expr=inputs.''${1//'/'/.inputs.}.rev + else + expr=self.revision + fi + nix eval "''${flakeArgs[@]}" -f ~/.nix-defexpr --raw "$expr" + echo + ;; + repl) + exec nix repl "''${flakeArgs[@]}" -f ~/.nix-defexpr "$@" + ;; + eval) + exec nix eval "''${flakeArgs[@]}" -f ~/.nix-defexpr --json "$@" | jq -r . + ;; + build) + # https://github.com/NixOS/nix/issues/6661 + exec nix-build --log-format bar-with-logs "''${flakeArgs[@]}" ~/.nix-defexpr -A "$@" + ;; + specialise) + name=$1 + shift + exec sudo /run/current-system/specialisation/"$name"/bin/switch-to-configuration switch + ;; + revert) + exec sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch + ;; + home) + attr=nixosConfigurations."$HOSTNAME".config.hm.home.activationPackage + export VERBOSE=1 + exec nix shell -v ".#$attr" "$@" -c home-manager-generation + ;; + @*) + host=''${cmd#@} + hostname=$(ssh -q "$host" 'echo "$HOSTNAME"') + exec nixos-rebuild -v --flake ".#$hostname" --target-host "$host" --use-remote-sudo "$@" + ;; + *) + exec nixos-rebuild -v --fast --flake "." --use-remote-sudo "$cmd" "$@" + ;; esac ''; }; @@ -103,11 +111,12 @@ __compreply() { local completion while IFS= read -r completion; do - COMPREPLY+=("$completion") + COMPREPLY+=("$completion") done < <(compgen "$@" -- "$cur") } __complete_nix_cmd() { - local skip=$1; shift + local skip=$1 + shift COMP_WORDS=("$@" "''${COMP_WORDS[@]:skip}") (( COMP_CWORD += $# - skip )) _completion_loader nix |