Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nixos-rebuild completer #2357

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions completers/nix_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
rootCmd.Flags().String("build-hook", "", "Set the build-hook setting")
rootCmd.Flags().String("build-poll-interval", "", "Set the build-poll-interval setting")
rootCmd.Flags().String("build-users-group", "", "Set the build-users-group setting")
rootCmd.Flags().String("builders", "", "Set the builders setting")
rootCmd.Flags().StringArray("builders", nil, "Set the builders setting")
rootCmd.Flags().Bool("builders-use-substitutes", false, "Enable the builders-use-substitutes setting")
rootCmd.Flags().String("commit-lockfile-summary", "", "Set the commit-lockfile-summary setting")
rootCmd.Flags().Bool("compress-build-log", false, "Enable the compress-build-log setting")
Expand Down Expand Up @@ -167,7 +167,7 @@ func init() {
rootCmd.Flags().String("stalled-download-timeout", "", "Set the stalled-download-timeout setting")
rootCmd.Flags().String("store", "", "Set the store setting")
rootCmd.Flags().Bool("substitute", false, "Enable the substitute setting")
rootCmd.Flags().String("substituters", "", "Set the substituters setting")
rootCmd.Flags().StringArray("substituters", nil, "Set the substituters setting")
rootCmd.Flags().Bool("sync-before-registering", false, "Enable the sync-before-registering setting")
rootCmd.Flags().String("system", "", "Set the system setting")
rootCmd.Flags().String("system-features", "", "Set the system-features setting")
Expand All @@ -193,6 +193,47 @@ func init() {

rootCmd.Flag("option").Nargs = 2

rootCmd.MarkFlagsMutuallyExclusive("accept-flake-config", "no-accept-flake-config")
rootCmd.MarkFlagsMutuallyExclusive("allow-dirty", "no-allow-dirty")
rootCmd.MarkFlagsMutuallyExclusive("allow-import-from-derivation", "no-allow-import-from-derivation")
rootCmd.MarkFlagsMutuallyExclusive("allow-new-privileges", "no-allow-new-privileges")
rootCmd.MarkFlagsMutuallyExclusive("allow-symlinked-store", "no-allow-symlinked-store")
rootCmd.MarkFlagsMutuallyExclusive("allow-unsafe-native-code-during-evaluation", "no-allow-unsafe-native-code-during-evaluation")
rootCmd.MarkFlagsMutuallyExclusive("auto-optimise-store", "no-auto-optimise-store")
rootCmd.MarkFlagsMutuallyExclusive("builders-use-substitutes", "no-builders-use-substitutes")
rootCmd.MarkFlagsMutuallyExclusive("compress-build-log", "no-compress-build-log")
rootCmd.MarkFlagsMutuallyExclusive("enforce-determinism", "no-enforce-determinism")
rootCmd.MarkFlagsMutuallyExclusive("eval-cache", "no-eval-cache")
rootCmd.MarkFlagsMutuallyExclusive("fallback", "no-fallback")
rootCmd.MarkFlagsMutuallyExclusive("filter-syscalls", "no-filter-syscalls")
rootCmd.MarkFlagsMutuallyExclusive("fsync-metadata", "no-fsync-metadata")
rootCmd.MarkFlagsMutuallyExclusive("http2", "no-http2")
rootCmd.MarkFlagsMutuallyExclusive("ignore-try", "no-ignore-try")
rootCmd.MarkFlagsMutuallyExclusive("impersonate-linux-26", "no-impersonate-linux-26")
rootCmd.MarkFlagsMutuallyExclusive("keep-build-log", "no-keep-build-log")
rootCmd.MarkFlagsMutuallyExclusive("keep-derivations", "no-keep-derivations")
rootCmd.MarkFlagsMutuallyExclusive("keep-env-derivations", "no-keep-env-derivations")
rootCmd.MarkFlagsMutuallyExclusive("keep-failed", "no-keep-failed")
rootCmd.MarkFlagsMutuallyExclusive("keep-going", "no-keep-going")
rootCmd.MarkFlagsMutuallyExclusive("keep-outputs", "no-keep-outputs")
rootCmd.MarkFlagsMutuallyExclusive("preallocate-contents", "no-preallocate-contents")
rootCmd.MarkFlagsMutuallyExclusive("print-missing", "no-print-missing")
rootCmd.MarkFlagsMutuallyExclusive("pure-eval", "no-pure-eval")
rootCmd.MarkFlagsMutuallyExclusive("require-sigs", "no-require-sigs")
rootCmd.MarkFlagsMutuallyExclusive("restrict-eval", "no-restrict-eval")
rootCmd.MarkFlagsMutuallyExclusive("run-diff-hook", "no-run-diff-hook")
rootCmd.MarkFlagsMutuallyExclusive("sandbox", "no-sandbox")
rootCmd.MarkFlagsMutuallyExclusive("sandbox-fallback", "no-sandbox-fallback")
rootCmd.MarkFlagsMutuallyExclusive("show-trace", "no-show-trace")
rootCmd.MarkFlagsMutuallyExclusive("substitute", "no-substitute")
rootCmd.MarkFlagsMutuallyExclusive("sync-before-registering", "no-sync-before-registering")
rootCmd.MarkFlagsMutuallyExclusive("trace-function-calls", "no-trace-function-calls")
rootCmd.MarkFlagsMutuallyExclusive("trace-verbose", "no-trace-verbose")
rootCmd.MarkFlagsMutuallyExclusive("use-case-hack", "no-use-case-hack")
rootCmd.MarkFlagsMutuallyExclusive("use-registries", "no-use-registries")
rootCmd.MarkFlagsMutuallyExclusive("use-sqlite-wal", "no-use-sqlite-wal")
rootCmd.MarkFlagsMutuallyExclusive("warn-dirty", "no-warn-dirty")

// TODO find out how flags shall be completed (nix doc insufficient)
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"log-format": carapace.ActionValues("raw", "internal-json", "bar", "bar-with-logs"),
Expand Down
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/boot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var bootCmd = &cobra.Command{
Use: "boot",
Short: "Build the new configuration and make it the boot default, but do not activate it",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(bootCmd).Standalone()
rootCmd.AddCommand(bootCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var buildCmd = &cobra.Command{
Use: "build",
Short: "build the new configuration without activating it or adding it to the boot menu",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(buildCmd).Standalone()
rootCmd.AddCommand(buildCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/buildVm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var buildVmCmd = &cobra.Command{
Use: "build-vm",
Short: "Build a script that starts a NixOS virtual machine with the configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(buildVmCmd).Standalone()
rootCmd.AddCommand(buildVmCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/buildVmWithBootloader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var buildVmWithBootloaderCmd = &cobra.Command{
Use: "build-vm-with-bootloader",
Short: "Like build-vm, but boots with the regular bootloader of your configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(buildVmWithBootloaderCmd).Standalone()
rootCmd.AddCommand(buildVmWithBootloaderCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/dryActivate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var dryActivateCmd = &cobra.Command{
Use: "dry-activate",
Short: "Build the new configuration, but show what changes would occur on activation instead of activating the configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(dryActivateCmd).Standalone()
rootCmd.AddCommand(dryActivateCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/dryBuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var dryBuildCmd = &cobra.Command{
Use: "dry-build",
Short: "Show what store paths would be built or downloaded, but otherwise do nothing",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(dryBuildCmd).Standalone()
rootCmd.AddCommand(dryBuildCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var editCmd = &cobra.Command{
Use: "edit",
Short: "Opens configuration.nix in the default editor",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(editCmd).Standalone()
rootCmd.AddCommand(editCmd)
}
19 changes: 19 additions & 0 deletions completers/nixos-rebuild_completer/cmd/listGenerations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var listGenerationsCmd = &cobra.Command{
Use: "list-generations",
Short: "List the available generations",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(listGenerationsCmd).Standalone()

listGenerationsCmd.Flags().Bool("json", false, "Output in JSON")
rootCmd.AddCommand(listGenerationsCmd)
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/repl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var replCmd = &cobra.Command{
Use: "repl",
Short: "Open the configuration in `nix repl`",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(replCmd).Standalone()
rootCmd.AddCommand(replCmd)
}
75 changes: 75 additions & 0 deletions completers/nixos-rebuild_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/net"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/nix"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "nixos-rebuild",
Short: "reconfigure a NixOS machine",
Long: "https://nixos.org",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.PersistentFlags().String("build-host", "localhost", "Specify host to perform the rebuild with")
rootCmd.PersistentFlags().StringArray("builders", nil, "Specify ad-hoc remote builders")
rootCmd.PersistentFlags().String("commit-lockfile-summary", "", "Set the commit-lockfile-summary setting")
rootCmd.PersistentFlags().Bool("fallback", false, "Enable the fallback setting")
rootCmd.PersistentFlags().Bool("fast", false, "Do not rebuild the 'nixUnstable' nixpkgs attribute before rebuilding")
rootCmd.PersistentFlags().String("flake", "", "Build the NixOS system from specified flake")
rootCmd.PersistentFlags().Bool("help", false, "Show usage information")
rootCmd.PersistentFlags().Bool("install-bootloader", false, "Causes the bootloader to be (re)installed")
rootCmd.PersistentFlags().Bool("keep-failed", false, "Enable the keep-failed setting")
rootCmd.PersistentFlags().Bool("keep-going", false, "Enable the keep-going setting")
rootCmd.PersistentFlags().String("log-format", "", "Set the format of log output")
rootCmd.PersistentFlags().String("max-jobs", "", "Set the max-jobs setting")
rootCmd.PersistentFlags().Bool("no-build-nix", false, "Do not rebuild the 'nixUnstable' nixpkgs attribute before rebuilding")
rootCmd.PersistentFlags().BoolP("no-build-output", "-Q", false, "Do not output on stdout or stderr")
rootCmd.PersistentFlags().Bool("offline", false, "Disable substituters and consider all previously downloaded files up-to-date")
rootCmd.PersistentFlags().StringSlice("option", []string{}, "Set the Nix configuration setting name to value")
rootCmd.PersistentFlags().BoolP("print-build-logs", "L", false, "Print full build logs on standard error")
rootCmd.PersistentFlags().StringP("profile-name", "p", "", "Specify Nix profile to place the new configuration in")
rootCmd.PersistentFlags().Bool("quiet", false, "Decrease the logging verbosity level")
rootCmd.PersistentFlags().Bool("refresh", false, "Consider all previously downloaded files out-of-date")
rootCmd.PersistentFlags().Bool("rollback", false, "Rollback to previous configuration instead of rebuilding")
rootCmd.PersistentFlags().Bool("show-trace", false, "Enable the show-trace setting")
rootCmd.PersistentFlags().StringP("specialisation", "c", "", "Activates given specialisation")
rootCmd.PersistentFlags().String("target-host", "localhost", "Specify host to apply rebuilt configuration to")
rootCmd.PersistentFlags().Bool("upgrade", false, "Update the root user's channel named 'nixos' before rebuilding")
rootCmd.PersistentFlags().Bool("upgrade-all", false, "Update all of the root user's channels before rebuilding")
rootCmd.PersistentFlags().Bool("use-remote-sudo", false, "Prefix activation commands on the target host with `sudo`")
rootCmd.PersistentFlags().Bool("use-substitutes", false, "Use substitue caches when running `nix-copy-closure`")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Increase the logging verbosity level")

rootCmd.MarkFlagsMutuallyExclusive("fast", "no-build-nix") // aliases
rootCmd.MarkFlagsMutuallyExclusive("no-build-output", "verbose", "quiet")

rootCmd.Flag("option").Nargs = 2

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"build-host": net.ActionHosts(),
"flake": nix.ActionFlakes(),
"log-format": carapace.ActionValues("raw", "internal-json", "bar", "bar-with-logs"),
"option": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return nix.ActionConfigKeys()
case 1:
return nix.ActionConfigValues(c.Parts[0])
default:
return carapace.ActionValues()
}
}),
"target-host": net.ActionHosts(),
})
}
17 changes: 17 additions & 0 deletions completers/nixos-rebuild_completer/cmd/switch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var switchCmd = &cobra.Command{
Use: "switch",
Short: "Build and activate the new configuration, making it the boot default",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(switchCmd).Standalone()
rootCmd.AddCommand(switchCmd)
}
7 changes: 7 additions & 0 deletions completers/nixos-rebuild_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/carapace-sh/carapace-bin/completers/nixos-rebuild_completer/cmd"

func main() {
cmd.Execute()
}