code:
#!@GUILE@ \
--no-auto-compile -s
!#

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This script stages and commits changes to package definitions.

;;; Code:

(import (sxml xpath)
        (srfi srfi-1)
        (srfi srfi-2)
        (srfi srfi-9)
        (srfi srfi-11)
        (srfi srfi-26)
        (ice-9 format)
        (ice-9 popen)
        (ice-9 match)
        (ice-9 rdelim)
        (ice-9 textual-ports)
        (guix gexp))

(define* (break-string str #:optional (max-line-length 70))
  "Break the string STR into lines that are no longer than MAX-LINE-LENGTH.
Return a single string."
  (define (restore-line words)
    (string-join (reverse words) " "))
  (if (<= (string-length str) max-line-length)
      str
      (let ((words+lengths (map (lambda (word)
                                  (cons word (string-length word)))
                                (string-tokenize str))))
        (match (fold (match-lambda*
                       (((word . length)
                         (count current lines))
                        (let ((new-count (+ count length 1)))
                          (if (< new-count max-line-length)
                              (list new-count
                                    (cons word current)
                                    lines)
                              (list length
                                    (list word)
                                    (cons (restore-line current) lines))))))
                     '(0 () ())
                     words+lengths)
          ((_ last-words lines)
           (string-join (reverse (cons (restore-line last-words) lines))
                        "\n"))))))

(define (read-excursion port)
  "Read an expression from PORT and reset the port position before returning
the expression."
  (let ((start (ftell port))
        (result (read port)))
    (seek port start SEEK_SET)
    result))

(define (surrounding-sexp port line-no)
  "Return the top-level S-expression surrounding the change at line number
LINE-NO in PORT."
  (let loop ((i (1- line-no))
             (last-top-level-sexp #f))
    (if (zero? i)
        last-top-level-sexp
        (match (peek-char port)
          (#\(
           (let ((sexp (read-excursion port)))
             (read-line port)
             (loop (1- i) sexp)))
          (_
           (read-line port)
           (loop (1- i) last-top-level-sexp))))))

(define-record-type <hunk>
  (make-hunk file-name
             old-line-number
             new-line-number
             diff-lines
             definition?)
  hunk?
  (file-name       hunk-file-name)
  ;; Line number before the change
  (old-line-number hunk-old-line-number)
  ;; Line number after the change
  (new-line-number hunk-new-line-number)
  ;; The full diff to be used with "git apply --cached"
  (diff-lines hunk-diff-lines)
  ;; Does this hunk add a definition?
  (definition? hunk-definition?))

(define* (hunk->patch hunk #:optional (port (current-output-port)))
  (let ((file-name (hunk-file-name hunk)))
    (format port
            "diff --git a/~a b/~a~%--- a/~a~%+++ b/~a~%~a"
            file-name file-name file-name file-name
            (string-join (hunk-diff-lines hunk) ""))))

(define (diff-info)
  "Read the diff and return a list of <hunk> values."
  (let ((port (open-pipe* OPEN_READ
                          "git" "diff-files"
                          "--no-prefix"
                          ;; Only include one context line to avoid lumping in
                          ;; new definitions with changes to existing
                          ;; definitions.
                          "--unified=1"
                          "gnu")))
    (define (extract-line-number line-tag)
      (abs (string->number
            (car (string-split line-tag #\,)))))
    (define (read-hunk)
      (let loop ((lines '())
                 (definition? #false))
        (let ((line (read-line port 'concat)))
          (cond
           ((eof-object? line)
            (values (reverse lines) definition?))
           ((or (string-prefix? "@@ " line)
                (string-prefix? "diff --git" line))
            (unget-string port line)
            (values (reverse lines) definition?))
           (else
            (loop (cons line lines)
                  (or definition?
                      (string-prefix? "+(define" line))))))))
    (define info
      (let loop ((acc '())
                 (file-name #f))
        (let ((line (read-line port)))
          (cond
           ((eof-object? line) acc)
           ((string-prefix? "--- " line)
            (match (string-split line #\space)
              ((_ file-name)
               (loop acc file-name))))
           ((string-prefix? "@@ " line)
            (match (string-split line #\space)
              ((_ old-start new-start . _)
               (let-values
                   (((diff-lines definition?) (read-hunk)))
                 (loop (cons (make-hunk file-name
                                        (extract-line-number old-start)
                                        (extract-line-number new-start)
                                        (cons (string-append line "\n")
                                              diff-lines)
                                        definition?) acc)
                       file-name)))))
           (else (loop acc file-name))))))
    (close-pipe port)
    info))

(define (lines-to-first-change hunk)
  "Return the number of diff lines until the first change."
  (1- (count (lambda (line)
               ((negate char-set-contains?)
                (char-set #\+ #\-)
                (string-ref line 0)))
             (hunk-diff-lines hunk))))

(define (old-sexp hunk)
  "Using the diff information in HUNK return the unmodified S-expression
corresponding to the top-level definition containing the staged changes."
  ;; TODO: We can't seek with a pipe port...
  (let* ((port (open-pipe* OPEN_READ
                           "git" "cat-file" "-p" (string-append
                                                  "HEAD:"
                                                  (hunk-file-name hunk))))
         (contents (get-string-all port)))
    (close-pipe port)
    (call-with-input-string contents
      (lambda (port)
        (surrounding-sexp port
                          (+ (lines-to-first-change hunk)
                             (hunk-old-line-number hunk)))))))

(define (new-sexp hunk)
  "Using the diff information in HUNK return the modified S-expression
corresponding to the top-level definition containing the staged changes."
  (call-with-input-file (hunk-file-name hunk)
    (lambda (port)
      (surrounding-sexp port
                        (+ (lines-to-first-change hunk)
                           (hunk-new-line-number hunk))))))

(define* (change-commit-message file-name old new #:optional (port (current-output-port)))
  "Print ChangeLog commit message for changes between OLD and NEW."
  (define (get-values expr field)
    (match ((sxpath `(// ,field quasiquote *)) expr)
      (() '())
      ((first . rest)
       (map cadadr first))))
  (define (listify items)
    (match items
      ((one) one)
      ((one two)
       (string-append one " and " two))
      ((one two . more)
       (string-append (string-join (drop-right items 1) ", ")
                      ", and " (first (take-right items 1))))))
  (define variable-name
    (second old))
  (define version
    (and=> ((sxpath '(// version *any*)) new)
           first))
  (format port
          "gnu: ~a: Update to ~a.~%~%* ~a (~a): Update to ~a.~%"
          variable-name version file-name variable-name version)
  (for-each (lambda (field)
              (let ((old-values (get-values old field))
                    (new-values (get-values new field)))
                (or (equal? old-values new-values)
                    (let ((removed (lset-difference equal? old-values new-values))
                          (added (lset-difference equal? new-values old-values)))
                      (format port
                              "[~a]: ~a~%" field
                              (break-string
                               (match (list (map symbol->string removed)
                                            (map symbol->string added))
                                 ((() added)
                                  (format #f "Add ~a."
                                          (listify added)))
                                 ((removed ())
                                  (format #f "Remove ~a."
                                          (listify removed)))
                                 ((removed added)
                                  (format #f "Remove ~a; add ~a."
                                          (listify removed)
                                          (listify added))))))))))
            '(inputs propagated-inputs native-inputs)))

(define* (add-commit-message file-name variable-name #:optional (port (current-output-port)))
  "Print ChangeLog commit message for a change to FILE-NAME adding a definition."
  (format port
          "gnu: Add ~a.~%~%* ~a (~a): New variable.~%"
          variable-name file-name variable-name))

(define (group-hunks-by-sexp hunks)
  "Return a list of pairs associating all hunks with the S-expression they are
modifying."
  (fold (lambda (sexp hunk acc)
          (match acc
            (((previous-sexp . hunks) . rest)
             (if (equal? sexp previous-sexp)
                 (cons (cons previous-sexp
                             (cons hunk hunks))
                       rest)
                 (cons (cons sexp (list hunk))
                       acc)))
            (_
             (cons (cons sexp (list hunk))
                   acc))))
        '()
        (map new-sexp hunks)
        hunks))

(define (new+old+hunks hunks)
  (map (match-lambda
         ((new . hunks)
          (cons* new (old-sexp (first hunks)) hunks)))
       (group-hunks-by-sexp hunks)))

(define %delay 1000)

(define (main . args)
  (match (diff-info)
    (()
     (display "Nothing to be done.\n" (current-error-port)))
    (hunks
     (let-values
         (((definitions changes)
           (partition hunk-definition? hunks)))

       ;; Additions.
       (for-each (lambda (hunk)
                   (and-let*
                       ((define-line (find (cut string-prefix? "+(define" <>)
                                           (hunk-diff-lines hunk)))
                        (variable-name (and=> (string-tokenize define-line) second)))
                     (add-commit-message (hunk-file-name hunk) variable-name)
                     (let ((port (open-pipe* OPEN_WRITE
                                             "git" "apply"
                                             "--cached"
                                             "--unidiff-zero")))
                       (hunk->patch hunk port)
                       (unless (eqv? 0 (status:exit-val (close-pipe port)))
                         (error "Cannot apply")))

                     (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
                       (add-commit-message (hunk-file-name hunk)
                                           variable-name port)
                       (usleep %delay)
                       (unless (eqv? 0 (status:exit-val (close-pipe port)))
                         (error "Cannot commit"))))
                   (usleep %delay))
                 definitions)

       ;; Changes.
       (for-each (match-lambda
                   ((new old . hunks)
                    (for-each (lambda (hunk)
                                (let ((port (open-pipe* OPEN_WRITE
                                                        "git" "apply"
                                                        "--cached"
                                                        "--unidiff-zero")))
                                  (hunk->patch hunk port)
                                  (unless (eqv? 0 (status:exit-val (close-pipe port)))
                                    (error "Cannot apply")))
                                (usleep %delay))
                              hunks)
                    (change-commit-message (hunk-file-name (first hunks))
                                           old new
                                           (current-output-port))
                    (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
                      (change-commit-message (hunk-file-name (first hunks))
                                             old new
                                             port)
                      (usleep %delay)
                      (unless (eqv? 0 (status:exit-val (close-pipe port)))
                        (error "Cannot commit")))))
                 ;; XXX: we recompute the hunks here because previous
                 ;; insertions lead to offsets.
                 (new+old+hunks (diff-info)))))))

(main)


code:
# GNU Guix --- Functional package management for GNU
# Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
# Copyright © 2021 Tobias Geerinck-Rice <me@tobias.gr>
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

# Bash completion for Guix commands.

declare _guix_available_packages
declare _guix_commands

_guix_complete_command ()
{
    local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
    if [ -z "$_guix_commands" ]
    then
	# Cache the list of commands to speed things up.
	_guix_commands="$(guix --help 2> /dev/null  \
                                     | grep '^    ' \
				     | sed '-es/^ *\([a-z-]\+\).*$/\1/g')"
    fi
    COMPREPLY=($(compgen -W "$_guix_commands" -- "$word_at_point"))
}

_guix_complete_subcommand ()
{
    local command="${COMP_WORDS[1]}"
    local subcommands="$(${COMP_WORDS[0]} $command --help 2> /dev/null \
                         | grep '^   [a-z]' \
                         | sed -e's/^ \+\([a-z-]\+\).*$/\1/g')"
    COMPREPLY=($(compgen -W "$subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
}

_guix_complete_available_package ()
{
    local prefix="$1"
    if [ -z "$_guix_available_packages" ]
    then
	# Cache the complete list because it rarely changes and makes
	# completion much faster.
	_guix_available_packages="$(${COMP_WORDS[0]} package -A 2> /dev/null \
                                    | cut -f1)"
    fi
    COMPREPLY=($(compgen -W "$_guix_available_packages" -- "$prefix"))
}

_guix_complete_installed_package ()
{
    # Here we do not cache the list of installed packages because that
    # may change over time and the list is relatively small anyway.
    local prefix="$1"
    local packages="$(${COMP_WORDS[0]} package -I "^$prefix" 2> /dev/null \
                      | cut -f1)"
    COMPREPLY=($(compgen -W "$packages" -- "$prefix"))
}

_guix_complete_option ()
{
    local command="${COMP_WORDS[$1]}"
    local subcommand="${COMP_WORDS[$(($1 + 1))]}"
    if _guix_is_option "$subcommand"
    then
	subcommand=""
    fi
    local options="$(${COMP_WORDS[0]} $command $subcommand --help 2> /dev/null \
                            | grep '^  \+-' \
                            | sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
    compopt -o nospace
    COMPREPLY=($(compgen -W "$options" -- "$2"))
}

_guix_is_option ()
{
    case "$1" in
	-*)
	    true
	    ;;
	*)
	    false
	    ;;
    esac
}

_guix_is_removing ()
{
    local word
    local result="false"
    for word in ${COMP_WORDS[*]}
    do
	case "$word" in
	    --remove|--remove=*|-r)
		result=true
		break
		;;
	esac
    done
    $result
}

_guix_is_dash_f ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-f" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --file=*|--install-from-file=*) true;;
		 *)                              false;;
	     esac }
}

_guix_is_dash_l ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-l" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --load=*) true;;
		 *)        false;;
	     esac }
}

_guix_is_dash_L ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-L" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --load-path=*) true;;
		 *)             false;;
	     esac }
}

_guix_is_dash_m ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-m" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --manifest=*) true;;
		 *)            false;;
	     esac }
}

_guix_is_dash_C ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-C" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --channels=*)  true;;
		 *)             false;;
	     esac }
}

_guix_is_dash_p ()
{
    [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-p" ] \
	|| { case "${COMP_WORDS[$COMP_CWORD]}" in
		 --profile=*)   true;;
		 *)             false;;
	     esac }
}

_guix_complete_file ()
{
    # Let Readline complete file names.
    compopt -o default
    COMPREPLY=()
}

_guix_complete_pid ()
{
    local pids="$(cd /proc; echo [0-9]*)"
    COMPREPLY=($(compgen -W "$pids" -- "$1"))
}

_guix_complete ()
{
    local word_count=${#COMP_WORDS[*]}
    local word_at_point="${COMP_WORDS[$COMP_CWORD]}"

    # Find the innermost command at point, e.g. "build" in the case of
    # "guix time-machine OPTIONS -- build<Tab>" -- but "time-machine" if
    # point is moved before "build".
    local command_index=0
    local command
    local word_index=0
    local word
    local expect_command="true"
    while [[ $((++word_index)) -le COMP_CWORD ]]
    do
	word="${COMP_WORDS[$word_index]}"
	if $expect_command
	then
	    command_index=$word_index
	    command="$word"
	    expect_command="false"
	    continue
	fi
	if [[ "$word" = "--" ]]
	then
	    case "$command" in
		environment)
		    break
		    ;;
		time-machine)
		    expect_command="true"
		    ;;
	    esac
	fi
    done

    case $COMP_CWORD in
	$command_index)
	    _guix_complete_command
	    ;;
	*)
	    if [[ "$command" = "package" ]]
	    then
		if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p || _guix_is_dash_f
		then
		    _guix_complete_file
		elif _guix_is_removing
		then
		    _guix_complete_installed_package "$word_at_point"
		else
		    _guix_complete_available_package "$word_at_point"
		fi
	    elif [[ "$command" = "install" ]]
	    then
                if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p
                then
                    _guix_complete_file
		else
		    _guix_complete_available_package "$word_at_point"
		fi
	    elif [[ "$command" = "remove" ]]
	    then
                if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p
                then
                    _guix_complete_file
		else
		    _guix_complete_installed_package "$word_at_point"
		fi
	    elif [[ "$command" = "upgrade" ]]
	    then
                if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p
                then
                    _guix_complete_file
		else
		    _guix_complete_installed_package "$word_at_point"
		fi
            elif [[ "$command" = "build" ]]
            then
                if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_f
                then
                    _guix_complete_file
		else
		    _guix_complete_available_package "$word_at_point"
                fi
	    elif [[ "$command" = "environment" ]]
	    then
                if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p || _guix_is_dash_l
                then
                    _guix_complete_file
		elif _guix_is_option "$word_at_point"
		then
		    _guix_complete_option "$command_index" "$word_at_point"
		else
		    _guix_complete_available_package "$word_at_point"
		fi
	    elif [[ "$command" = "download" ]]
	    then
		 _guix_complete_file
	    elif [[ "$command" = "system" ]]
	    then
		case $COMP_CWORD in
		    2) _guix_complete_subcommand;;
		    *) _guix_complete_file;; # TODO: restrict to *.scm
		esac
            elif [[ "$command" = "pull" ]]
            then
                if _guix_is_dash_C || _guix_is_dash_p
                then
                    _guix_complete_file
                fi
            elif [[ "$command" = "time-machine" ]]
            then
                if _guix_is_dash_C
                then
                    _guix_complete_file
		else
		    _guix_complete_option "$command_index" "$word_at_point"
                fi
	    elif [[ "$command" = "container" ]]
	    then
		case $COMP_CWORD in
		    2) _guix_complete_subcommand;;
		    3) _guix_complete_pid "$word_at_point";;
		    *) _guix_complete_file;;
		esac
	    elif [[ "$command" = "import" ]]
	    then
		_guix_complete_subcommand
	    elif [[ "$command" = "hash" || "$command" = "gc" ]]
	    then
		_guix_complete_file
            elif [[ "$command" = "weather" ]]
            then
                if _guix_is_dash_m
                then
                    _guix_complete_file
                fi
	    else
		_guix_complete_available_package "$word_at_point"
	    fi
	    ;;
    esac

    if [[ -z "$COMPREPLY" && COMP_CWORD -gt command_index ]] &&
        _guix_is_option "$word_at_point"
    then
	_guix_complete_option "$command_index" "$word_at_point"
    fi
}

complete -F _guix_complete guix

repo_name: maximed/guix

path: etc/completion/bash/guix

license: mit


code:
# GNU Guix --- Functional package management for GNU
# Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

# Bash completion for guix-daemon command.

_guix_daemon_complete ()
{
    local options="$(${COMP_WORDS[0]} --help 2> /dev/null \
                            | grep '^  \+-' \
                            | sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
    compopt -o nospace
    COMPREPLY=($(compgen -W "$options" -- "${COMP_WORDS[${#COMP_WORDS[*]} - 1]}"))
}

complete -F _guix_daemon_complete guix-daemon

path: etc/completion/bash/guix-daemon


code:
#
# GNU Guix --- Functional package management for GNU
# Copyright © 2017, 2018 Nikita <nikita@n0.is>
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

# Guix commands covered:
# download, pull, system, build, package, size, refresh
# publish, lint, import, hash, graph, gc, environment,
# edit, copy, container, challenge, archive, pack,
# weather

# Existing commands provided by guix as of 2017-11-30:
# archive, challenge, copy, edit, gc, hash, lint, package
# pull, size, weather, build, container, download, environment
# graph, import, pack, publish, refresh, system

# TODO: a rewrite similar to rust.fish

# Use 'command guix' to avoid interactions for aliases.

## To be used later on:
# function __fish_guix_archive
# end
# function __fish_guix_build_file_ls
# end
# function __fish_guix_challenge
# end
# function __fish_guix_container
# end
# function __fish_guix_copy
# end
# function __fish_guix_download
# end
# function __fish_guix_edit
# end
# function __fish_guix_environment
# end
# function __fish_guix_gc
# end
# function __fish_guix_graph
# end
# function __fish_guix_hash
# end
# function __fish_guix_import
# end
# function __fish_guix_lint
# end
# function __fish_guix_package
# end
# function __fish_guix_publish
# end
# function __fish_guix_pull
# end
# function __fish_guix_refresh
# end
# function __fish_guix_size
# end
# function __fish_guix_system
# end

function __fish_guix_needs_command
    set cmd (commandline -opc)
    if [ (count $cmd) -eq 1 ]
        return 0
    else
        set -l skip_next 1
        # Skip first word because it's "guix"
        for c in $cmd[2..-1]
            test $skip_next -eq 0
            and set skip_next 1
            and continue
            switch $c
                # General options that can still take a command
                case "=*"
                    continue
                    # case --asdf
                    #     set skip_next 0
                    #     continue
                    # these behave like commands and everything after them is ignored
                case "--help" "--version"
                    return 1
                    # We assume that any other token that's not an argument to a general option is a command
                case "*"
                    echo $c
                    return 1
            end
        end
        return 0
    end
    return 1
end

function __fish_guix_using_command
    set -l cmd (__fish_guix_needs_command)
    test -z "$cmd"
    and return 1
    contains -- $cmd $argv
    and return 0
end

# general options
complete -f -c guix -s h -l help -d 'Display the manual of a guix command'
complete -f -c guix -s V -l version -d 'Display version information.'

# shared options
#complete -f -c guix -n '__fish_guix_using_command'

#### download
set -l remotecommands format no-check-certificate
complete -f -c guix -n '__fish_guix_needs_command' -a download -d 'Download object from source into the gnu store'
complete -f -c guix -n '__fish_guix_using_command download' -s f -l format -d'Write the hash in the given format'
complete -f -c guix -n '__fish_guix_using_command download' -l no-check-certificate -d 'Do not validate the certificate of HTTPS servers'

#### pull
set -l remotecommands verbose url bootstrap
complete -f -c guix -n '__fish_guix_needs_command' -a pull -d 'Download and deploy the latest version of Guix'
complete -f -c guix -n '__fish_guix_using_command pull' -l verbose -d 'produce verbose output'
complete -f -c guix -n '__fish_guix_using_command pull' -l url -d 'download the Guix tarball from URL'
complete -f -c guix -n '__fish_guix_using_command pull' -l bootstrap -d 'use the bootstrap Guile to build the new Guix'

#### system
set -l remotecommands reconfigure roll-back switch-generation list-generations build container vm image init extension-graph shepherd-graph load-path keep-failed keep-going dry-run fallback no-substitutes substitutes-urls no-grafts no-offload max-silent-time timeout verbosity rounds cores max-jobs derivation on-error image-size no-grub share expose full-boot
complete -f -c guix -n '__fish_guix_needs_command' -a system -d 'Build the operating system declared in FILE according to ACTION.'
complete -f -c guix -n '__fish_guix_using_command system' -l reconfigure -d 'switch to a new operating system configuration'
complete -f -c guix -n '__fish_guix_using_command system' -l roll-back -d 'switch to the previous operating system configuration'
complete -f -c guix -n '__fish_guix_using_command system' -l switch-generation -d 'switch to an existing operating system configuration'
complete -f -c guix -n '__fish_guix_using_command system' -l list-generations -d 'list the system generations'
complete -f -c guix -n '__fish_guix_using_command system' -l build -d 'build the operating system without installing anything'
complete -f -c guix -n '__fish_guix_using_command system' -l container -d 'build a container that shares the host\'s store'
complete -f -c guix -n '__fish_guix_using_command system' -l vm -d 'build a virtual machine image that shares the host\'s store'
complete -f -c guix -n '__fish_guix_using_command system' -l image -d 'build a disk image, suitable for a USB stick'
complete -f -c guix -n '__fish_guix_using_command system' -l init -d 'initialize a root file system to run GNU'
complete -f -c guix -n '__fish_guix_using_command system' -l extension-graph -d 'emit the service extension graph in Dot format'
complete -f -c guix -n '__fish_guix_using_command system' -l shepherd-graph -d 'emit the graph of shepherd services in Dot format'
complete -f -c guix -n '__fish_guix_using_command system' -s L -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command system' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command system' -s K -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command system' -s k -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command system' -s n -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command system' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command system' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command system' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command system' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command system' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command system' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command system' -a "--timeout=" -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command system' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command system' -a --"rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command system' -s c -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command system' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command system' -s M -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command system' -a "--max-jobs=" -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command system' -s d -l derivation -d 'return the derivation of the given system'
complete -f -c guix -n '__fish_guix_using_command system' -a "--on-error=" -d 'apply STRATEGY when an error occurs while reading FILE'
complete -f -c guix -n '__fish_guix_using_command system' -a "--image-size=" -d 'for \'image\', produce an image of SIZE'
complete -f -c guix -n '__fish_guix_using_command system' -l no-grub -d 'for \'init\', do not install GRUB'
complete -f -c guix -n '__fish_guix_using_command system' -a "--share=" -d 'for \'vm\', share host file system according to SPEC'
complete -f -c guix -n '__fish_guix_using_command system' -a "--expose=" -d 'for \'vm\', expose host file system according to SPEC'
complete -f -c guix -n '__fish_guix_using_command system' -l full-boot -d 'for \'vm\', make a full boot sequence'

#### build
set -l remotecommands expression file source sources system target derivations check repair root quiet log-file load-path keep-failed keep-going dry-run fallback no-substitutes substitute-urls no-grafts no-offload max-silent-time timeout verbosity rounds cores max-jobs with-source with-input with-graft
complete -f -c guix -n '__fish_guix_needs_command' -a build -d 'Build the given PACKAGE-OR-DERIVATION and return their output paths.'
complete -f -c guix -n '__fish_guix_using_command build' -a "--expression=" -d 'build the package or derivation EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command build' -s f -d 'build the package or derivation that the code within FILE evaluates to' --exclusive --arguments "(ls -ap)"
# The command below is broken:
complete -f -c guix -n '__fish_guix_using_command build' -a '--file=' -a '(ls -ap)' -d 'build the package or derivation that the code within FILE evaluates to'
complete -f -c guix -n '__fish_guix_using_command build' -s S -l source -d 'build the packages\' source derivations'
complete -f -c guix -n '__fish_guix_using_command build' -l sources -d 'build source derivations, TYPE may optionally be one of "package", "all" (default), or "transitive"' -a "package all transitive" -a "package all transitive"
complete -f -c guix -n '__fish_guix_using_command build' -s s -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command build' -a "--system=" -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command build' -a "--target=" -d 'cross-build for TRIPLET--e.g., "armel-linux-gnu"'
complete -f -c guix -n '__fish_guix_using_command build' -s d -l derivations -d 'return the derivation paths of the given packages'
complete -f -c guix -n '__fish_guix_using_command build' -l check -d 'rebuild items to check for non-determinism issues'
complete -f -c guix -n '__fish_guix_using_command build' -l repair -d 'repair the specified items'
complete -f -c guix -n '__fish_guix_using_command build' -s r -d 'make FILE a symlink to the result, and register it as a garbage collector root'
complete -f -c guix -n '__fish_guix_using_command build' -a "--root=" -d 'make FILE a symlink to the result, and register it as a garbage collector root'
complete -f -c guix -n '__fish_guix_using_command build' -s q -l quiet -d 'do not show the build log'
complete -f -c guix -n '__fish_guix_using_command build' -l log-file -d 'return the log file names for the given derivations'
complete -f -c guix -n '__fish_guix_using_command build' -s L -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command build' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command build' -s K -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command build' -s k -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command build' -s n -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command build' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command build' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command build' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command build' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command build' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command build' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command build' -a "--timeout=" -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command build' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command build' -a "--rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command build' -s c -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command build' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command build' -s M -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command build' -a "--max-jobs=" -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command build' -a "--with-source=" -d 'use SOURCE when building the corresponding package'
complete -f -c guix -n '__fish_guix_using_command build' -a "--with-input=" -d 'PACKAGE=REPLACEMENT .. replace dependency PACKAGE by REPLACEMENT'
complete -f -c guix -n '__fish_guix_using_command build' -a "--with-graft=" -d 'PACKAGE=REPLACEMENT .. graft REPLACEMENT on packages that refer to PACKAGE'

#### package
set -l remotecommands install install-from-expression install-from-file remove upgrade manifest do-no-upgrade roll-back search-paths list-generations delete-generations switch-generation profile bootstrap verbose search list-installed list-available show load-path keep-failed keep-going dry-run fallback no.substitutes substitute-urls no-grafts no-offload max-silent-time timenout verbosity rounds cores max-jobs with-source with-input with-graft
complete -f -c guix -n '__fish_guix_needs_command' -a package -d 'Install, remove, or upgrade packages in a single transaction.'
complete -f -c guix -n '__fish_guix_using_command package' -s i -l install -d 'install PACKAGEs'
complete -f -c guix -n '__fish_guix_using_command package' -s e -d 'install the package EXP evaluates to'
complete -f -c guix -n '__fish_guix_using_command package' -a "--install-from-expression=" -d 'install the package EXP evaluates to'
complete -f -c guix -n '__fish_guix_using_command package' -s f -d 'install the package that the code within FILE evaluates to'
complete -f -c guix -n '__fish_guix_using_command package' -a "--install-from-file=" -d 'install the package that the code within FILE evaluates to'
complete -f -c guix -n '__fish_guix_using_command package' -s r -l remove -d 'remove PACKAGEs'
complete -f -c guix -n '__fish_guix_using_command package' -s u -l upgrade -d '[=REGEXP] upgrade all the installed packages matching REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -s m -d 'create a new profile generation with the manifest from FILE'
complete -f -c guix -n '__fish_guix_using_command package' -a "--manifest=" -d 'create a new profile generation with the manifest from FILE'
complete -f -c guix -n '__fish_guix_using_command package' -l do-not-upgrade -d '[=REGEXP] do not upgrade any packages matching REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -l roll-back -d 'roll back to the previous generation'
complete -f -c guix -n '__fish_guix_using_command package' -l search-paths -d '[=KIND] display needed environment variable definitions'
complete -f -c guix -n '__fish_guix_using_command package' -s l -l list-generations -d '[=PATTERN] list generations matching PATTERN'
complete -f -c guix -n '__fish_guix_using_command package' -s d -l delete-generations -d '[=PATTERN] delete generations matching PATTERN'
complete -f -c guix -n '__fish_guix_using_command package' -s S -d 'PATTERN switch to a generation matching PATTERN'
complete -f -c guix -n '__fish_guix_using_command package' -a "--switch-generation=" -d 'PATTERN switch to a generation matching PATTERN'
complete -f -c guix -n '__fish_guix_using_command package' -s p -d 'use PROFILE instead of the user\'s default profile'
complete -f -c guix -n '__fish_guix_using_command package' -a "--profile=" -d 'use PROFILE instead of the user\'s default profile'
complete -f -c guix -n '__fish_guix_using_command package' -l bootstrap -d 'use the bootstrap Guile to build the profile'
complete -f -c guix -n '__fish_guix_using_command package' -l verbose -d 'produce verbose output'
complete -f -c guix -n '__fish_guix_using_command package' -s s -d 'REGEXP search in synopsis and description using REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -a "--search=" -d 'REGEXP search in synopsis and description using REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -s I -l list-installed -d '[=REGEXP] list installed packages matching REGEXP'
#complete -c guix -n '__fish_guix_using_command package' -s I -l list-installed --exclusive --arguments "(guix package --list-installed)" --description 'List installed packages matching REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -s A -l list-available -d '[=REGEXP] list available packages matching REGEXP'
complete -f -c guix -n '__fish_guix_using_command package' -a "--show=" -d 'PACKAGE show details about PACKAGE'
complete -f -c guix -n '__fish_guix_using_command package' -s L -d 'DIR prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command package' -a "--load-path=" -d 'DIR prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command package' -s K -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command package' -s k -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command package' -s n -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command package' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command package' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command package' -a "--substitute-urls=" -d 'URLS fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command package' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command package' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command package' -a "--max-silent-time=" -d 'SECONDS mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command package' -a "--timeout=" -d 'SECONDS mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command package' -a "--verbosity=" -d 'LEVEL use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command package' -a "--rounds=" -d 'N build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command package' -s c -d 'N allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command package' -a "--cores=" -d 'N allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command package' -s M -l max-jobs= -d 'N allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command package' -a "--max-jobs=" -d 'N allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command package' -a "--with-source=" -d 'SOURCE use SOURCE when building the corresponding package'
complete -f -c guix -n '__fish_guix_using_command package' -a "--with-input=" -d 'PACKAGE=REPLACEMENT replace dependency PACKAGE by REPLACEMENT'
complete -f -c guix -n '__fish_guix_using_command package' -a "--with-graft=" -d 'PACKAGE=REPLACEMENT graft REPLACEMENT on packages that refer to PACKAGE'

#### size
set -l remotecommands substitute-urls= system= map-file=
complete -f -c guix -n '__fish_guix_needs_command' -a size -d 'Report the size of PACKAGE and its dependencies.'
complete -f -c guix -n '__fish_guix_using_command size' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command size' -a "--system=" -d 'consider packages for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command size' -a "--map-file=" -d 'write to FILE a graphical map of disk usage'

#### refresh
set -l remotecommands expression update select type list-updaters list-dependent key-server gpg key-download
complete -f -c guix -n '__fish_guix_needs_command' -a refresh -d 'Update package definitions to match the latest upstream version'
# FIXME: Too long. When PACKAGE... is given, update only the specified packages. Otherwise update all the packages of the distribution, or the subset thereof specified with `--select`.'
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--expression=" -d 'consider the package EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command refresh' -l update -d 'update source files in place'
#complete -f -c guix -n '__fish_guix_using_command refresh' -l select= -d 'select all the packages in SUBSET, one of `core` or `non-core`' --exclusive --arguments "core non-core"
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--select=" -d 'select all the packages in SUBSET, one of `core` or `non-core`' --exclusive --arguments "core non-core"
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--type=" -d 'restrict to updates from the specified updaters (e.g., \'gnu\')' --exclusive --arguments "gnu gnome kde xorg kernel.org elpa cran bioconductor cpan pypi gem github hackage crate"
complete -f -c guix -n '__fish_guix_using_command refresh' -l list-updaters -d 'list available updaters and exit'
complete -f -c guix -n '__fish_guix_using_command refresh' -l list-dependent -d 'list top-level dependent packages that would need to be rebuilt as a result of upgrading PACKAGE'
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--key-server=" -d 'use HOST as the OpenPGP key server'
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--gpg=" -d 'use COMMAND as the GnuPG 2.x command'
complete -f -c guix -n '__fish_guix_using_command refresh' -a "--key-download=" -d 'handle missing OpenPGP keys according to POLICY.' --exclusive --arguments "always never interactive"

#### publish
set -l remotecommands port= listen= user= compression ttl= repl
complete -f -c guix -n '__fish_guix_needs_command' -a publish -d 'Publish /gnu/store over HTTP.'
complete -f -c guix -n '__fish_guix_using_command publish' -a "--port=" -d 'listen on PORT'
complete -f -c guix -n '__fish_guix_using_command publish' -a "--listen=" -d 'listen on the network interface for HOST'
complete -f -c guix -n '__fish_guix_using_command publish' -a "--user=" -d 'change privileges to USER as soon as possible'
complete -f -c guix -n '__fish_guix_using_command publish' -l compression -d '[=LEVEL] compress archives at LEVEL'
complete -f -c guix -n '__fish_guix_using_command publish' -a "--ttl=" -d 'announce narinfos can be cached for TTL seconds'
complete -f -c guix -n '__fish_guix_using_command publish' -l repl -d '[=PORT] spawn REPL server on PORT'

#### lint
set -l remotecommands checkers list-checkers
complete -f -c guix -n '__fish_guix_needs_command' -a lint -d 'Run a set of checkers on the specificied package.'
complete -f -c guix -n '__fish_guix_using_command lint' -l list-checkers -d 'Display the list of available lint checkers.'
complete -f -c guix -n '__fish_guix_using_command lint' -l checkers -d 'Only run the specified checkers.'
complete -f -c guix -n '__fish_guix_using_command lint' -l description -d 'Validate package descriptions.'
complete -f -c guix -n '__fish_guix_using_command lint' -l gnu-description -d 'Validate synopsis and descriptions of the GNU packages.'
complete -f -c guix -n '__fish_guix_using_command lint' -l inputs-should-be-native -d 'Identify inputs that should be native inputs.'
complete -f -c guix -n '__fish_guix_using_command lint' -l inputs-should-not-be-inputs -d 'Identify inputs that should not be inputs at all.'
complete -f -c guix -n '__fish_guix_using_command lint' -l patch-file-names -d 'Validate file names anda availability of patches.'
complete -f -c guix -n '__fish_guix_using_command lint' -l home-page -d 'Validate home-page URLs'
complete -f -c guix -n '__fish_guix_using_command lint' -l license -d 'Make sure the "license" field is a <license > or a list thereof'
complete -f -c guix -n '__fish_guix_using_command lint' -l source -d 'Validate source URLs'
complete -f -c guix -n '__fish_guix_using_command lint' -l mirror-url -d 'Suggest "mirror://" URLs'
complete -f -c guix -n '__fish_guix_using_command lint' -l source-file-name -d 'Validate file names of sources'
complete -f -c guix -n '__fish_guix_using_command lint' -l derivation -d 'Report failure to compile a package to a derivation'
complete -f -c guix -n '__fish_guix_using_command lint' -l synopsis -d 'Validate package synopses'
complete -f -c guix -n '__fish_guix_using_command lint' -l cve -d 'Check the Common Vulnerabilities and Exposures (CVE) database'
complete -f -c guix -n '__fish_guix_using_command lint' -l formatting -d 'Look for formatting issues in the source'

#### import
set -l remotecommands import gnu nix pypi cpan hackage elpa gem cran crate texlive json
complete -f -c guix -n '__fish_guix_needs_command' -a import -d 'Run IMPORTER with ARGS'
##### import gnu
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a gnu -d 'Return a package declaration template for PACKAGE, a GNU package.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from gnu' -a "--key-download=" -d 'handle missing OpenPGP keys according to POLICY: "always", "never", and "interactive", which is also used when "key-download" is not specified.'
##### import pypi
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a pypi -d 'Import and convert the PyPI package for PACKAGE-NAME.'
##### import cpan
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a cpan -d 'Import and convert the CPAN package for PACKAGE-NAME.'
##### import hackage
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a hackage -d 'Import and convert the Hackage package for PACKAGE-NAME.  If PACKAGE-NAME includes a suffix constituted by a at-sign followed by a numerical version (as used with Guix packages), then a definition for the specified version of the package will be generated.  If no version suffix is pecified, then the generated package definition will correspond to the latest available version.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from hackage' -s e -d 'ALIST specify environment for Cabal evaluation.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from hackage' -a "--cabal-environment=" -d 'ALIST specify environment for Cabal evaluation.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from hackage' -s s -l stdin -d 'Read from standard input.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from hackage' -s t -l no-test-dependencies -d 'don\'t include test-only dependencies.'
##### import elpa
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a elpa -d 'Import the latest package named PACKAGE-NAME from an ELPA repository.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from elpa' -s a -d 'specify the archive repository' --exclusive --arguments "gnu melpa-stable melpa"
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from elpa' -a "--archive=" -d 'specify the archive repository' --exclusive --arguments "gnu melpa-stable melpa"
##### import gem
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a gem -d 'Import and convert the RubyGems package for PACKAGE-NAME.'
##### import cran
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a cran -d 'Import and convert the CRAN package for PACKAGE-NAME.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from cran' -s a -d 'specify the archive repository' --exclusive --arguments "bioconductor cran"
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from cran' -a "--archive=" -d 'specify the archive repository' --exclusive --arguments "bioconductor cran"
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from cran' -l recursive -d 'traverse the dependency graph of the given package recursively and generate package definitions for all those packages that are not yet in Guix'
##### import crate
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a crate -d 'Import and convert the crate.io package for PACKAGE-NAME.'
##### import json
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a json -d 'Import and convert the JSON package definition in PACKAGE-FILE.'
##### import texlive
complete -f -c guix -n '__fish_guix_using_command import; and not __fish_seen_subcommand_from $remotecommands' -a texlive -d 'Import and convert the Texlive package for PACKAGE-NAME.'
complete -f -c guix -n '__fish_guix_using_command import; and __fish_seen_subcommand_from texlive' -s a -l "--archive=" -d 'specify the archive repository'

#### hash
set -l remotecommands exclude-vcs format= recursive
complete -f -c guix -n '__fish_guix_needs_command' -a hash -d 'Return the cryptographic hash of a FILE.'
complete -f -c guix -n '__fish_guix_using_command hash' -s x -l exclude-vcs -d 'Exclude version control directories.'
complete -f -c guix -n '__fish_guix_using_command hash' -s f -d 'Write the hash in the given format.' --exclusive --arguments "nix-base32 base32 base16 hex hexadecimal"
complete -f -c guix -n '__fish_guix_using_command hash' -a "--format=" -d 'Write the hash in the given format.' --exclusive --arguments "nix-base32 base32 base16 hex hexadecimal"
complete -f -c guix -n '__fish_guix_using_command hash' -s r -l recursive -d 'Compute the hash on FILE recursively.'

#### graph
set -l remotecommands backend list-backends type list-types expression
complete -f -c guix -n '__fish_guix_needs_command' -a graph -d 'Emit a Graphviz (dot) representation of the dependencies of a PACKAGE.'
complete -f -c guix -n '__fish_guix_using_command graph' -l backend -d 'Produce a graph with the given backend TYPE'
complete -f -c guix -n '__fish_guix_using_command graph' -l list-backends -d 'list the available graph backends'
complete -f -c guix -n '__fish_guix_using_command graph' -l type -d 'represent nodes of the given TYPE'
complete -f -c guix -n '__fish_guix_using_command graph' -l list-types -d 'list the available graph types'
complete -f -c guix -n '__fish_guix_using_command graph' -l expression -d 'consider the package EXPR evaluates to'

#### gc
set -l remotecommands collect-garbage free-space delete optimize list-dead list-live references requisites referrers verify list-failures clear-failures
complete -f -c guix -n '__fish_guix_needs_command' -a gc -d 'Invoke the garbage collector.'
complete -f -c guix -n '__fish_guix_using_command gc' -s C -d 'collect at least MIN bytes of garbage'
complete -f -c guix -n '__fish_guix_using_command gc' -a "--collect-garbage=" -d 'collect at least MIN bytes of garbage'
complete -f -c guix -n '__fish_guix_using_command gc' -s F -d 'attempt to reach FREE available space in the store'
complete -f -c guix -n '__fish_guix_using_command gc' -a "--free-space=" -d 'attempt to reach FREE available space in the store'
complete -f -c guix -n '__fish_guix_using_command gc' -s d -l delete -d 'attempt to delete PATHS'
complete -f -c guix -n '__fish_guix_using_command gc' -l optimize -d 'optimize the store by deduplicating identical files'
complete -f -c guix -n '__fish_guix_using_command gc' -l list-dead -d 'list dead paths'
complete -f -c guix -n '__fish_guix_using_command gc' -l list-live -d 'list live paths'
complete -f -c guix -n '__fish_guix_using_command gc' -l references -d 'list the references of PATHS'
complete -f -c guix -n '__fish_guix_using_command gc' -s R -l requisites -d 'list the requisites of PATHS'
complete -f -c guix -n '__fish_guix_using_command gc' -l referrers -d 'list the referrers of PATHS'
complete -f -c guix -n '__fish_guix_using_command gc' -l verify -d 'verify the integrity of the store
OPTS is a comma-separated combination of \'repair\' and \'contents\''
complete -f -c guix -n '__fish_guix_using_command gc' -l list-failures -d 'list cached build failures'
complete -f -c guix -n '__fish_guix_using_command gc' -l clear-failures -d 'remove PATHS from the set of cached failures'

#### environment
set -l remotecommands expression load ad-hoc pure search-paths system root container network share expose bootstrap load-path keep-failed keep-going dry-run fallback no-substitutes substitute-urls no-grafts no-offload max-silent-time timeout verbosity rounds cores max-jobs
complete -f -c guix -n '__fish_guix_needs_command' -a environment -d 'Build an environment that includes the dependencies of PACKAGE and execute COMMAND or an interactive shell in that environment.'
complete -f -c guix -n '__fish_guix_using_command environment' -s e -d 'Create environment for the package that EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--expression=" -d 'Create environment for the package that EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command environment' -s l -d 'create environment for the package that the code within FILE evaluates to.'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--load=" -d 'create environment for the package that the code within FILE evaluates to.'
complete -f -c guix -n '__fish_guix_using_command environment' -l ad-hoc -d 'include all specified packages in the environment instead of only their inputs'
complete -f -c guix -n '__fish_guix_using_command environment' -l pure -d 'unset existing environment variables'
complete -f -c guix -n '__fish_guix_using_command environment' -l search-paths -d 'display needed environment variable definitions'
complete -f -c guix -n '__fish_guix_using_command environment' -s s -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--system=" -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command environment' -s r -d 'make FILE a symlink to the result, and register it as a garbage collector root'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--root=" -d 'make FILE a symlink to the result, and register it as a garbage collector root'
complete -f -c guix -n '__fish_guix_using_command environment' -s C -l container -d 'run command within an isolated container'
complete -f -c guix -n '__fish_guix_using_command environment' -s N -l network -d 'allow containers to access the network'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--share=" -d 'for containers, share writable host file system according to SPEC'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--expose=" -d 'for containers, expose read-only host file system according to SPEC'
complete -f -c guix -n '__fish_guix_using_command environment' -l bootstrap -d 'use bootstrap binaries to build the environment'
complete -f -c guix -n '__fish_guix_using_command environment' -s L -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command environment' -s K -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command environment' -s k -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command environment' -s n -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command environment' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command environment' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command environment' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command environment' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--timeout=" -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command environment' -s c -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command environment' -s M -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command environment' -a "--max-jobs=" -d 'allow at most N build jobs'

#### edit
complete -f -c guix -n '__fish_guix_needs_command' -a edit -d 'Start $VISUAL or $EDITOR to edit the definitions of PACKAGE.'

#### copy
set -l remotecommands to= from= load-path= keep-failed keep-going dry-run fallback no-substitutes substitute-urls= no-grafts no-offload max-silent-time= timeout= verbosity= rounds= cores= max-jobs=
complete -f -c guix -n '__fish_guix_needs_command' -a copy -d 'Copy ITEMS to or from the specified host over SSH.'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--to=" -d 'send ITEMS to HOST'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--from=" -d 'receive ITEMS from HOST'
complete -f -c guix -n '__fish_guix_using_command copy' -s L -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command copy' -s K -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command copy' -s k -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command copy' -s n -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command copy' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command copy' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command copy' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command copy' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--timeout=" -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command copy' -s c -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command copy' -s M -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command copy' -a "--max-jobs=" -d 'allow at most N build jobs'

#### container
set -l remotecommands exec
complete -f -c guix -n '__fish_guix_needs_command' -a container -d 'Build and manipulate Linux containers.'
complete -f -c guix -n '__fish_guix_using_command container' -l exec -d 'Execute a command inside of an existing container.'

#### challenge
set -l remotecommands substitute-urls verbose
complete -f -c guix -n '__fish_guix_needs_command' -a challenge -d 'Challenge the substitutes for PACKAGE provided by one or more servers.'
complete -f -c guix -n '__fish_guix_using_command challenge' -a "--substitute-urls=" -d 'compare build results with those at URLS'
complete -f -c guix -n '__fish_guix_using_command challenge' -s v -l verbose -d 'show details about successful comparisons'

#### archive
set -l remotecommands export format= recursive import missing extract= generate-key authorize expression= source system= target= load-path= keep-failed keep-going dry-run fallback no-substitutes substitute-urls= no-grafts no-offload max-silent-time= timeout= verbosity= rounds= cores= max-jobs=
complete -f -c guix -n '__fish_guix_needs_command' -a archive -d 'Export/import one or more packages from/to the store.'
complete -f -c guix -n '__fish_guix_using_command archive' -l export -d 'export the specified files/packages to stdout'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--format=" -d 'export files/packages in the specified format FMT'
complete -f -c guix -n '__fish_guix_using_command archive' -l recursive -d 'combined with \'--export\', include dependencies'
complete -f -c guix -n '__fish_guix_using_command archive' -l import -d 'import from the archive passed on stdin'
complete -f -c guix -n '__fish_guix_using_command archive' -l missing -d 'print the files from stdin that are missing'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--extract=" -d 'extract the archive on stdin to DIR'
complete -f -c guix -n '__fish_guix_using_command archive' -l generate-key -d 'generate a key pair with the given parameters'
complete -f -c guix -n '__fish_guix_using_command archive' -l authorize -d 'authorize imports signed by the public key on stdin'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--expression=" -d 'build the package or derivation EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command archive' -l source -d 'build the packages\' source derivations'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--system=" -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--target=" -d 'cross-build for TRIPLET--e.g., "armel-linux-gnu"'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command archive' -l keep-failed -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command archive' -l keep-going -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command archive' -l dry-run -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command archive' -l fallback -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command archive' -l no-substitutes -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command archive' -l no-grafts -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command archive' -l no-offload -d 'do not attempt to offload builds'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--timeout=" -f -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command archive' -a "--max-jobs=" -d 'allow at most N build jobs'

#### pack
set -l remotecommands --load-path= --keep-failed --keep-going --dry-run --fallback --no-substitutes --substitute-urls= --no-grafts --no-offload --max-silent-time= --timeout= --verbosity= --rounds= --cores= --max-jobs= --with-source= --with-input= --with-graft= --format= --expression= --system= --target= --compression= --symlink= --localstatedir --help --version
complete -f -c guix -n '__fish_guix_needs_command' -a pack -d 'Create a bundle of PACKAGE.'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--load-path=" -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command pack' -s L -d 'prepend DIR to the package module search path'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--keep-failed" -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command pack' -s K -d 'keep build tree of failed builds'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--keep-going" -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command pack' -s k -d 'keep going when some of the derivations fail'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--dry-run" -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command pack' -s n -d 'do not build the derivations'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--fallback" -d 'fall back to building when the substituter fails'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--no-substitutes" -d 'build instead of resorting to pre-built substitutes'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--substitute-urls=" -d 'fetch substitute from URLS if they are authorized'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--no-grafts" -d 'do not graft packages'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--no-offload" -d 'do not attempt to offload builds via the build hook'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--max-silent-time=" -d 'mark the build as failed after SECONDS of silence'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--timeout=" -d 'mark the build as failed after SECONDS of activity'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--verbosity=" -d 'use the given verbosity LEVEL'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--rounds=" -d 'build N times in a row to detect non-determinism'
complete -f -c guix -n '__fish_guix_using_command pack' -s c -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--cores=" -d 'allow the use of up to N CPU cores for the build'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--max-jobs=" -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command pack' -s M -d 'allow at most N build jobs'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--with-source=" -d 'use SOURCE when building the corresponding package'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--with-input=PACKAGE=REPLACEMENT" -d 'replace dependency PACKAGE by REPLACEMENT'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--with-graft=PACKAGE=REPLACEMENT" -d 'graft REPLACEMENT on packages that refer to PACKAGE'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--format=" -d 'build a pack in the given FORMAT'
complete -f -c guix -n '__fish_guix_using_command pack' -s f -d 'build a pack in the given FORMAT'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--expression=" -d 'consider the package EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command pack' -s e -d 'consider the package EXPR evaluates to'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--system=" -d 'attempt to build for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command pack' -s s -d 'attempt to build for SYSTEM--eg., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--target=" -d 'cross-build for TRIPLET--e.g., "armel-linux-gnu"'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--compression=" -d 'compress using TOOL--e.g., "lzip"'
complete -f -c guix -n '__fish_guix_using_command pack' -s C -d 'compress using TOOL--e.g., "lzip"'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--symlink=" -d 'create symlinks to the profile according to SPEC'
complete -f -c guix -n '__fish_guix_using_command pack' -s S -d 'create symlinks to the profile according to SPEC'
complete -f -c guix -n '__fish_guix_using_command pack' -a "--localstatedir" -d 'include /var/guix in the resulting pack'

## weather
set -l remotecommands substitute-urls manifest system
complete -f -c guix -n '__fish_guix_needs_command' -a weather -d 'Report the availability of substitutes-'
complete -f -c guix -n '__fish_guix_using_command weather' -a "--substitute-urls=" -d 'check for available substitutes at URLS'
complete -f -c guix -n '__fish_guix_using_command weather' -s m -d 'look up substitutes for packages specified in MANIFEST'
complete -f -c guix -n '__fish_guix_using_command weather' -a "--manifest=" -d 'look up substitutes for packages specified in MANIFEST'
complete -f -c guix -n '__fish_guix_using_command weather' -s s -d 'consider substitutes for SYSTEM--e.g., "i686-linux"'
complete -f -c guix -n '__fish_guix_using_command weather' -a "--system=" -d 'consider substitutes for SYSTEM--e.g., "i686-linux"'


code:
#compdef guix
#
# GNU Guix --- Functional package management for GNU
# Copyright © 2016 Eric Le Bihan <eric.le.bihan.dev@free.fr>
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

_guix_caching_policy()
{
    local -a old_policy
    old_policy=( "$1"(Nmh+24) )
    (( $#old_policy ))
}

_guix_list_actions()
{
    _guix_actions=( $(guix system --help | sed -n 's/^   \([a-z-]\+\)\s\+.\+/\1/p') )
}

_guix_list_checkers()
{
    _guix_checkers=( $(guix lint -l | sed -n 's/^- \(.\+\): .\+/\1/p') )
}

_guix_list_graph_types()
{
    _guix_graph_types=( $(guix graph --list-types | sed -n 's/^  - \(.\+\): .\+/\1/p') )
}

_guix_list_importers()
{
    _guix_importers=( $(guix import --help | sed -n 's/^\s\+\([a-z]\+\)$/\1/p') )
}

_guix_list_updaters()
{
    _guix_updaters=( $(guix lint -l | sed -n 's/^- \(.\+\): .\+/\1/p') )
}

_guix_list_available_packages()
{
    if ( [[ ${+_guix_available_packages} -eq 0 ]] || _cache_invalid GUIX_AVAILABLE_PACKAGES ) \
       && ! _retrieve_cache GUIX_AVAILABLE_PACKAGES; then
        _guix_available_packages=(${${(f)"$(guix package -A | cut -f1)"}})
        _store_cache GUIX_AVAILABLE_PACKAGES _guix_available_packages
    fi
}

_guix_list_installed_packages()
{
    _guix_installed_packages=( $(guix package -I "^${prefix}" | cut -f1) )
}

(( $+functions[_guix_build] )) || _guix_build()
{
    _arguments \
        '--expression=[build the package matching EXPR]:EXPR' \
        '--file=[build the package matching code evaluated from FILE]:FILE:_files' \
        '--source[build the packages source derivations]' \
        '--sources=[build source derivations]:TYPE:(all package transitive)' \
        '--system=[attempt to build for SYSTEM (e.g. "i686-linux")]:SYSTEM' \
        '--target=[cross-build for TRIPLET (e.g. "armel-linux-gnu")]:TRIPLET' \
        '--derivations[return the derivation paths of the given packages]' \
        '--check[rebuild items to check for non-determinism issues]' \
        '--root=[symlink result to FILE and register it as GC root]:FILE:_files' \
        '--quiet[do not show the build log]' \
        '--log-file[return the log file names for the given derivations]' \
        '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
        '--keep-failed[keep build tree of failed builds]' \
        '--keep-going[keep going when some of the derivations fail]' \
        '--dry-run[do not build the derivations]' \
        '--fallback[fall back to building when the substituter fails]' \
        '--no-substitutes[build instead of resorting to pre-built substitutes]' \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
        '--no-grafts[do not graft packages]' \
        '--no-offload[do not attempt to offload builds]' \
        '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
        '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
        '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
        '--rounds=[build N times in a row to detect non-determinism]:N' \
        '--cores=[allow the use of up to N CPU cores for the build]:N' \
        '--max-jobs=[allow at most N build jobs]:N' \
        '--with-source=[use SOURCE when building the corresponding package]:SOURCE' \
        '--with-input=[replace dependency PACKAGE by REPLACEMENT]:PACKAGE=REPLACEMENT' \
        '*:package:->packages'

    if [[ "$state" = packages ]]; then
        _guix_list_available_packages
        compadd -a -- _guix_available_packages
    fi
}

(( $+functions[_guix_challenge] )) || _guix_challenge()
{
    _arguments \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
        '*:package:->packages'

    if [[ "$state" = packages ]]; then
        _guix_list_available_packages
        compadd -a -- _guix_available_packages
    fi
}

(( $+functions[_guix_container] )) || _guix_container()
{
    _arguments \
        ':action:(exec)' \
        '*:args'
}

(( $+functions[_guix_download] )) || _guix_download()
{
    _arguments \
        '--format=[write the hash in the given format]:FMT:(nix-base32 base16 base32 hex)' \
        '1:URL:_urls'
}

(( $+functions[_guix_edit] )) || _guix_edit()
{
    _guix_list_available_packages
    compadd -a -- _guix_available_packages
}

(( $+functions[_guix_environment] )) || _guix_environment()
{
    _arguments \
        '--expression=[create environment for the package evaluated from EXPR]:EXPR' \
        '--load=[create environment for the package evaluated from FILE]:FILE:_files' \
        '--ad-hoc[include all specified packages, not only their inputs]' \
        '--pure[unset existing environment variables]' \
        '--search-paths[display needed environment variable definitions]' \
        '--system=[attempt to build for SYSTEM (e.g. "i686-linux")]:SYSTEM' \
        '--container[run command within an isolated container]' \
        '--network[allow containers to access the network]' \
        '--share=[share writable host file system according to SPEC]:SPEC' \
        '--expose=[expose read-only host file system according to SPEC]:SPEC' \
        '--bootstrap[use bootstrap binaries to build the environment]' \
        '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
        '--keep-failed[keep build tree of failed builds]' \
        '--keep-going[keep going when some of the derivations fail]' \
        '--dry-run[do not build the derivations]' \
        '--fallback[fall back to building when the substituter fails]' \
        '--no-substitutes[build instead of resorting to pre-built substitutes]' \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
        '--no-grafts[do not graft packages]' \
        '--no-offload[do not attempt to offload builds]' \
        '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
        '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
        '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
        '--rounds=[build N times in a row to detect non-determinism]:N' \
        '--cores=[allow the use of up to N CPU cores for the build]:N' \
        '--max-jobs=[allow at most N build jobs]:N' \
        '*:package:->packages'

    if [[ "$state" = packages ]]; then
        _guix_list_available_packages
        compadd -a -- _guix_available_packages
    fi

}

(( $+functions[_guix_gc] )) || _guix_gc()
{
    _arguments \
        '--collect-garbage=[collect at least MIN bytes of garbage]:MIN' \
        '--free-space=[attempt to reach FREE available space in the store]:FREE' \
        '--delete[attempt to delete PATHS]' \
        '--optimize[optimize the store by deduplicating identical files]' \
        '--list-dead[list dead paths]' \
        '--list-live[list live paths]' \
        '--references[list the references of PATHS]' \
        '--requisites[list the requisites of PATHS]' \
        '--referrers[list the referrers of PATHS]' \
        '--verify=[verify the integrity of the store]:OPTS:(contents repair)' \
        '--list-failures[list cached build failures]' \
        '--clear-failures[remove PATHS from the set of cached failures]' \
        '1:PATH:_dirs'
}

(( $+functions[_guix_graph] )) || _guix_graph()
{
    _arguments \
        '--type=[represent nodes of the given TYPE]:TYPE:->types' \
        '--list-types[list the available graph types]' \
        '--expression=[consider the package EXPR evaluates to]:EXPR' \
        '1:PACKAGE:->packages'

    case "$state" in
        types)
            _guix_list_graph_types
            compadd -a -- _guix_graph_types
            ;;
        packages)
            _guix_list_available_packages
            compadd -a -- _guix_available_packages
            ;;
    esac

}

(( $+functions[_guix_hash] )) || _guix_hash()
{
    _arguments \
        '--format=[write the hash in the given format]:FMT:(nix-base32 base16 base32 hex)' \
        '--recursive[compute the hash on FILE recursively]'\
        '1:FILE:_files'
}

(( $+functions[_guix_import] )) || _guix_import()
{
    _arguments \
        '1:IMPORTER:->importer' \
        '*:args:'

    if [[ "$state" = importer ]]; then
        _guix_list_importers
        compadd -a -- _guix_importers
    fi
}

(( $+functions[_guix_lint] )) || _guix_lint()
{
    _arguments \
        '--checkers=[only run the specified checkers]:CHECKERS:->checkers' \
        '--list-checkers[display the list of available lint checkers]' \
        '1:PACKAGE:->packages'

    case "$state" in
        checkers)
            _guix_list_checkers
            compadd -a -- _guix_checkers
            ;;
        packages)
            _guix_list_available_packages
            compadd -a -- _guix_available_packages
            ;;
    esac
}

(( $+functions[_guix_package] )) || _guix_package()
{
    _arguments \
        '--install[install one or more packages]: :->install' \
        '--install-from-expression=[install the package EXP evaluates to]:EXP' \
        '--install-from-file=[install the package evaluated from FILE]:FILE:_files' \
        '--remove[remove one or more packages]: :->remove' \
        '--upgrade=[upgrade all the installed packages matching REGEXP]:REGEXP' \
        '--manifest=[create a new profile generation from FILE]:FILE:_files' \
        '--do-not-upgrade=[do not upgrade any packages matching REGEXP]:REGEXP' \
        '--roll-back[roll back to the previous generation]' \
        '--search-paths=[display needed environment variable definitions]:KINDS' \
        '--list-generations=[list generations matching PATTERN]:PATTERN' \
        '--delete-generations=[delete generations matching PATTERN]:PATTERN' \
        '--switch-generation=[switch to a generation matching PATTERN]:PATTERN' \
        '--profile=[use PROFILE instead of the default profile]:PROFILE' \
        '--bootstrap[use the bootstrap Guile to build the profile]' \
        '--verbose[produce verbose output]' \
        '--search=[search in synopsis and description using REGEXP]:REGEXP' \
        '--list-installed=[list installed packages matching REGEXP]:REGEXP' \
        '--list-available=[list available packages matching REGEXP]:REGEXP' \
        '--show=[show details about a package]: :->show' \
        '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
        '--keep-failed[keep build tree of failed builds]' \
        '--keep-going[keep going when some of the derivations fail]' \
        '--dry-run[do not build the derivations]' \
        '--fallback[fall back to building when the substituter fails]' \
        '--no-substitutes[build instead of resorting to pre-built substitutes]' \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URLS:_urls' \
        '--no-grafts[do not graft packages]' \
        '--no-offload[do not attempt to offload builds]' \
        '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
        '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
        '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
        '--rounds=[build N times in a row to detect non-determinism]:N' \
        '--cores=[allow the use of up to N CPU cores for the build]:N' \
        '--max-jobs=[allow at most N build jobs]:N' \
        '--with-source=[use SOURCE when building the corresponding package]:SOURCE' \
        '--with-input=[replace dependency PACKAGE by REPLACEMENT]:PACKAGE=REPLACEMENT'

    case "$state" in
        install|show)
            _guix_list_available_packages
            compadd -a -- _guix_available_packages
            ;;
        remove)
            _guix_list_installed_packages
             compadd -a -- _guix_installed_packages
            ;;
        esac
}

(( $+functions[_guix_publish] )) || _guix_publish()
{
    _arguments \
        '--port=[listen on PORT]:PORT:' \
        '--listen=[listen on the network interface for HOST]:HOST:_hosts' \
        '--user=[change privileges to USER as soon as possible]:USER:_users' \
        '--compression=[compress archives at LEVEL]:LEVEL' \
        '--ttl=[announce narinfos can be cached for TTL seconds]:TTL' \
        '--repl=[spawn REPL server on PORT]:PORT'
}

(( $+functions[_guix_pull] )) || _guix_pull()
{
    _arguments \
        '--verbose[produce verbose output]' \
        '--url=[download the Guix tarball from URL]:URL:_urls' \
        '--bootstrap[use the bootstrap Guile to build the new Guix]'
}

(( $+functions[_guix_refresh] )) || _guix_refresh()
{
    _arguments \
        '--expression=[consider the package EXPR evaluates to]:EXPR' \
        '--update[update source files in place]' \
        '--select=[select all the packages in SUBSET]:SUBSET:(core non-core)' \
        '--type=[restrict to updates from the specified updaters]:UPDATER:->updaters' \
        '--list-updaters[list available updaters and exit]' \
        '--list-dependent[list top-level dependent packages]' \
        '--key-server=[use HOST as the OpenPGP key server]:HOST:_hosts' \
        '--gpg=[use COMMAND as the GnuPG 2.x command]:COMMAND' \
        '--key-download=[policy to handle missing OpenPGP keys]:POLICY:(always interactive never)' \
        '*:package:->packages'

    case "$state" in
        updaters)
            _guix_list_updaters
            compadd -a -- _guix_updaters
            ;;
        packages)
            _guix_list_available_packages
            compadd -a -- _guix_available_packages
            ;;
    esac
}

(( $+functions[_guix_size] )) || _guix_size()
{
    _arguments \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
        '-system=[consider packages for SYSTEM--e.g., "i686-linux"]:SYSTEM' \
        '--map-file=[write to FILE a graphical map of disk usage]:FILE:_files' \
        '*:package:->packages'

        if [[ "$state" = packages ]]; then
            _guix_list_available_packages
            compadd -a -- _guix_available_packages
        fi
}

(( $+functions[_guix_system] )) || _guix_system()
{
    _arguments \
        '--load-path=[prepend DIR to the package module search path]:DIR:_dirs' \
        '--keep-failed[keep build tree of failed builds]' \
        '--keep-going[keep going when some of the derivations fail]' \
        '--dry-run[do not build the derivations]' \
        '--fallback[fall back to building when the substituter fails]' \
        '--no-substitutes[build instead of resorting to pre-built substitutes]' \
        '--substitute-urls=[fetch substitute from URLS if they are authorized]:URL:_urls' \
        '--no-grafts[do not graft packages]' \
        '--no-offload[do not attempt to offload builds]' \
        '--max-silent-time=[mark the build as failed after SECONDS of silence]:SECONDS' \
        '--timeout=[mark the build as failed after SECONDS of activity]:SECONDS' \
        '--verbosity=[use the given verbosity LEVEL]:LEVEL' \
        '--rounds=[build N times in a row to detect non-determinism]:N' \
        '--cores=[allow the use of up to N CPU cores for the build]:N' \
        '--max-jobs=[allow at most N build jobs]:N' \
        '--derivation[return the derivation of the given system]' \
        '--on-error=[apply STRATEGY when an error occurs while reading FILE]:STRATEGY' \
        '--image-size=[for "image", produce an image of SIZE]:SIZE' \
        '--no-grub[for "init", do not install GRUB]' \
        '--share=[for "vm", share host file system according to SPEC]:SPEC' \
        '--expose=[for "vm", expose host file system according to SPEC]:SPEC' \
        '--full-boot[for "vm", make a full boot sequence]' \
        '1:action:->actions' \
        '*:file:_files'

    if [[ "$state" = actions ]]; then
        _guix_list_actions
        compadd -a -- _guix_actions
    fi
}

(( $+functions[_guix_command] )) || _guix_command()
{
    local -a _guix_cmds
    _guix_cmds=(
        "archive:Export/import one or more packages from/to the store"
        "build:Build a given package"
        "challenge:Challenge the substitutes for a package"
        "container:Build and manipulate Linux containers"
        "download:Download the file at given URL and add it to the store"
        "edit:Edit the definitions of a package"
        "environment:Build an environment with a package and its dependencies"
        "gc:Invoke the garbage collector"
        "graph:Emit a DOT representation of the dependencies of a package"
        "hash:Return the cryptographic hash of a file"
        "import:Run an importer"
        "lint:Run a set of checkers on a package"
        "package:Install, remove, or upgrade packages"
        "publish:Publish /gnu/store over HTTP."
        "pull:Download and deploy the latest version of Guix"
        "refresh:Update package definitions to match the latest version"
        "size:Report the size of a package and its dependencies"
        "system:Build the operating system"
    )

    if (( CURRENT == 1 )); then
        _describe -t commands 'guix command' _guix_cmds || compadd "$@"
    else
        local curcontext="$curcontext"

        cmd="${${_guix_cmds[(r)$words[1]:*]%%:*}}"

        if (( $#cmd )); then
            local cache_policy

            zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
            if [[ -z "$cache_policy" ]]; then
                zstyle ":completion:${curcontext}:" cache-policy _guix_caching_policy
            fi

            curcontext="${curcontext%:*:*}:guix-${cmd}:"

            _call_function ret _guix_${cmd} || _message 'no more arguments'
        else
            _message "unknown guix command: $words[1]"
        fi
        return ret
    fi
}

_arguments \
    '(--version)--version[Display version information and exit]' \
    '*::guix command:_guix_command'

# vim: ts=4 sts=4 sw=4 et ai
# Local variables:
# mode: sh
# End:


code:
;;; copyright.el --- Insert a Guix copyright.

;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>

;; This file is part of GNU Guix.

;; GNU Guix is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Guix is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This package provides skeleton to insert a copyright with `guix-copyright'.

;;; Code:

(define-skeleton guix-copyright
  "Insert a copyright by $USER notice at cursor."
  "FULL_NAME <MAIL_ADDRESS>: "
  comment-start
  ";; Copyright © " `(format-time-string "%Y") " "
  (or (format "%s <%s>" user-full-name user-mail-address) str)
  comment-end)

;;; copyright.el ends here


code:
#!/bin/sh

# This hook script prevents the user from pushing to Savannah if any of the new
# commits' OpenPGP signatures cannot be verified, or if a commit is signed
# with an unauthorized key.

# Called by "git push" after it has checked the remote status, but before
# anything has been pushed.  If this script exits with a non-zero status nothing
# will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
#   <local ref> <local sha1> <remote ref> <remote sha1>

# This is the "empty hash" used by Git when pushing a branch deletion.
z40=0000000000000000000000000000000000000000

while read local_ref local_hash remote_ref remote_hash
do
	# When deleting a remote branch, no commits are pushed to the remote, and
	# thus there are no signatures to be verified.
	if [ "$local_hash" != $z40 ]
	then
		# Only use the hook when pushing to Savannah.
		case "$2" in
		    *.gnu.org*)
			exec make authenticate check-channel-news
			exit 127
			;;
		    *)
			exit 0
			;;
		esac
	fi
done

exit 0

path: etc/git/pre-push


code:
[Unit]
Description=Read-only @storedir@ for GNU Guix
DefaultDependencies=no
ConditionPathExists=@storedir@
Before=guix-daemon.service

[Install]
WantedBy=guix-daemon.service

[Mount]
What=@storedir@
Where=@storedir@
Type=none
Options=bind,ro