about summary refs log tree commit diff
path: root/packages
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2023-09-28 03:57:43 +0300
committerAzat Bahawi <azat@bahawi.net>2023-09-28 03:57:43 +0300
commit1516209f857dd328828dd3c5da7f85d8af27a7ec (patch)
tree76e793cf4b25e265662b86e358be1195aedc2a7a /packages
parent2023-09-28 (diff)
2023-09-28
Diffstat (limited to 'packages')
-rw-r--r--packages/nixfiles.nix151
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

Consider giving Nix/NixOS a try! <3