From 8c1b8fbdd3f225e388e25c30e9569ff5d52e2758 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 3 Mar 2023 12:11:32 +0100 Subject: [PATCH] remove the CLI The CLI is just another thing to install and that makes the bootstrapping process longer. It also doesn't do much aside being yet another frontend to Nix. Just use flakes. --- .github/workflows/goreleaser.yml | 34 ---------- .github/workflows/nix.yml | 2 +- README.md | 2 +- bors.toml | 2 - default.nix | 3 - devshell/.golangci.yml | 9 --- devshell/README.md | 3 - devshell/cmd/cmd.go | 21 ------ devshell/cmd/enter.go | 108 ------------------------------- devshell/cmd/init.go | 54 ---------------- devshell/config/config.go | 65 ------------------- devshell/config/init.go | 41 ------------ devshell/config/search.go | 55 ---------------- devshell/default.nix | 20 ------ devshell/go.mod | 8 --- devshell/go.sum | 16 ----- devshell/main.go | 23 ------- flake.nix | 1 - template/devshell.toml | 3 +- 19 files changed, 3 insertions(+), 467 deletions(-) delete mode 100644 .github/workflows/goreleaser.yml delete mode 100644 devshell/.golangci.yml delete mode 100644 devshell/README.md delete mode 100644 devshell/cmd/cmd.go delete mode 100644 devshell/cmd/enter.go delete mode 100644 devshell/cmd/init.go delete mode 100644 devshell/config/config.go delete mode 100644 devshell/config/init.go delete mode 100644 devshell/config/search.go delete mode 100644 devshell/default.nix delete mode 100644 devshell/go.mod delete mode 100644 devshell/go.sum delete mode 100644 devshell/main.go diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml deleted file mode 100644 index 2fba93dc..00000000 --- a/.github/workflows/goreleaser.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: goreleaser -on: - push: - branches: - - main - tags: - - 'v*' - workflow_dispatch: -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.15 - - name: Import GPG key - id: import_gpg - uses: crazy-max/ghaction-import-gpg@v5.2.0 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v4 - with: - version: "v0.149.0" - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 176e4a8a..7b174e86 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -22,7 +22,7 @@ jobs: authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - run: | export PRJ_ROOT=$PWD - $(./shell.nix)/entrypoint --pure bash -c "cd devshell && golangci-lint run" + $(./shell.nix)/entrypoint --pure bash -c "echo OK" - run: nix-shell --run "echo OK" - run: nix-build flakes: diff --git a/README.md b/README.md index 2b5bb964..f8f8a38e 100644 --- a/README.md +++ b/README.md @@ -138,4 +138,4 @@ direnv mode. 1. Change files in `docs/` 2. Run `docs/serve.sh` (or the task in VSCode) -3. Visit [`localhost:8000`](http://localhost:8000) \ No newline at end of file +3. Visit [`localhost:8000`](http://localhost:8000) diff --git a/bors.toml b/bors.toml index c4c37ec1..2430c61f 100644 --- a/bors.toml +++ b/bors.toml @@ -4,8 +4,6 @@ status = [ "build (macos-latest)", "build (ubuntu-20.04)", "default devShell [x86_64-linux]", - "default package [x86_64-linux]", "docs (ubuntu-20.04)", "flakes (ubuntu-20.04)", - "goreleaser" ] diff --git a/default.nix b/default.nix index d92fef85..462c977c 100644 --- a/default.nix +++ b/default.nix @@ -25,9 +25,6 @@ let builtins.foldl' op [ ] (builtins.attrNames data); in rec { - # CLI - cli = nixpkgs.callPackage ./devshell { }; - # Folder that contains all the extra modules extraModulesDir = toString ./extra; diff --git a/devshell/.golangci.yml b/devshell/.golangci.yml deleted file mode 100644 index e1da3280..00000000 --- a/devshell/.golangci.yml +++ /dev/null @@ -1,9 +0,0 @@ -linters: - presets: - - bugs - - unused - enable: - - gofmt - - golint - - misspell - - stylecheck diff --git a/devshell/README.md b/devshell/README.md deleted file mode 100644 index ca97df75..00000000 --- a/devshell/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# The devshell CLI - -An optional CLI that can be used to make the devshell usage simpler. diff --git a/devshell/cmd/cmd.go b/devshell/cmd/cmd.go deleted file mode 100644 index c0b21d55..00000000 --- a/devshell/cmd/cmd.go +++ /dev/null @@ -1,21 +0,0 @@ -package cmd - -import ( - "os" - - "github.com/urfave/cli/v2" -) - -// Execute the main command -func Execute() error { - app := &cli.App{ - Name: "devshell", - Description: "THE developer shell", - Commands: []*cli.Command{ - Enter, - Init, - }, - } - - return app.Run(os.Args) -} diff --git a/devshell/cmd/enter.go b/devshell/cmd/enter.go deleted file mode 100644 index b9559115..00000000 --- a/devshell/cmd/enter.go +++ /dev/null @@ -1,108 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - "os/exec" - "path/filepath" - "strings" - - "github.com/numtide/devshell/devshell/config" - - "github.com/urfave/cli/v2" -) - -// TODO: embed with the executable. -const shellNix = ` -let - pkgs = import {}; -in -pkgs.mkDevShell.fromTOML %s -` - -func run(name string, args ...string) (string, error) { - cmd := exec.Command(name, args...) - cmd.Stderr = os.Stderr - out, err := cmd.Output() - if err != nil { - return "", fmt.Errorf("%s: %w", name, err) - } - return strings.TrimSpace(string(out)), nil -} - -// Enter command -var Enter = &cli.Command{ - Name: "enter", - Aliases: []string{"run", "e"}, - Usage: "builds and enters the shell", - Description: ` - Enter the shell. If extra arguments are passed, run as a command inside - the development environment instead. - `, - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "path", - Usage: "path to the project root", - Value: "", - }, - &cli.StringSliceFlag{ - Name: "I", - Usage: "Add a path to the NIX_PATH", - Value: cli.NewStringSlice("devshell=https://github.com/numtide/devshell/archive/main.tar.gz"), - }, - }, - Action: func(c *cli.Context) error { - var err error - - args := []string{"--show-trace"} - path := c.String("path") - paths := c.StringSlice("I") - - if path == "" { - path, err = os.Getwd() - if err != nil { - return err - } - } - path, err = filepath.Abs(path) - if err != nil { - return err - } - - // Search for the config if it doesn't exist - file, ret := config.Search(path) - - // Prepare arguments - switch ret { - case config.SearchNix: - args = append(args, file) - case config.SearchTOML: - args = append(args, "--expr", fmt.Sprintf(shellNix, file)) - case config.SearchNone: - return fmt.Errorf("no devshell found in %s", path) - } - - for _, p := range paths { - args = append(args, "-I", p) - } - - // Instantiate eval - drvPath, err := run("nix-instantiate", args...) - if err != nil { - return err - } - // Remove the surrounding quotes - drvPath = strings.Trim(drvPath, "\"") - // Realize - outPath, err := run("nix-store", "--realize", drvPath) - if err != nil { - return err - } - // Execute - cmd := exec.Command(outPath, c.Args().Slice()...) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return cmd.Run() - }, -} diff --git a/devshell/cmd/init.go b/devshell/cmd/init.go deleted file mode 100644 index fb3c59c4..00000000 --- a/devshell/cmd/init.go +++ /dev/null @@ -1,54 +0,0 @@ -package cmd - -import ( - "fmt" - "path/filepath" - - "github.com/numtide/devshell/devshell/config" - - "github.com/urfave/cli/v2" -) - -// Init command -var Init = &cli.Command{ - Name: "init", - Usage: "creates a new " + config.FileName + " file", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "name", - Usage: "name of the project", - }, - &cli.StringFlag{ - Name: "path", - Usage: "project folder", - Value: ".", - }, - &cli.BoolFlag{ - Name: "force", - Usage: "override the file if it already exists", - }, - }, - Action: func(c *cli.Context) error { - // Load the arguments - p := c.String("path") - name := c.String("name") - force := c.Bool("force") - - // Default name based on the current folder name - if name == "" { - p2, err := filepath.Abs(p) - if err != nil { - return err - } - name = filepath.Base(p2) - } - - err := config.Init(p, name, force) - if err != nil { - return err - } - fmt.Println("config file created") - - return nil - }, -} diff --git a/devshell/config/config.go b/devshell/config/config.go deleted file mode 100644 index 7d3820f3..00000000 --- a/devshell/config/config.go +++ /dev/null @@ -1,65 +0,0 @@ -package config - -import ( - "os" - - "github.com/pelletier/go-toml" -) - -// FileName ... -const FileName = "devshell.toml" - -// Bash ... -type Bash struct { - Extra string `toml:"extra,omitempty"` - Interactive string `toml:"interactive,omitempty"` -} - -// Command ... -type Command struct { - Category string `toml:"category,omitempty"` - Command string `toml:"command,omitempty"` - Help string `toml:"help,omitempty"` - Name string `toml:"name"` - Package string `toml:"package,omitempty"` -} - -// Devshell ... -type Devshell struct { - Name string `toml:"name"` - Packages []string `toml:"packages"` - Motd *string `toml:"motd"` -} - -// Config ... -type Config struct { - Bash Bash `toml:"bash,omitempty"` - Commands []Command `toml:"commands"` - Devshell Devshell `toml:"devshell,omitempty"` - Env map[string]interface{} `toml:"env"` -} - -// Load ... -func Load(path string) (*Config, error) { - r, err := os.Open(path) - if err != nil { - return nil, err - } - - c := &Config{} - err = toml.NewDecoder(r).Decode(c) - if err != nil { - return nil, err - } - - return c, err -} - -// Print ... -func Print(c *Config) string { - b, err := toml.Marshal(c) - if err != nil { - panic(err) // should never happen - } - return string(b) -} diff --git a/devshell/config/init.go b/devshell/config/init.go deleted file mode 100644 index 0383b892..00000000 --- a/devshell/config/init.go +++ /dev/null @@ -1,41 +0,0 @@ -package config - -import ( - "fmt" - "os" - "path/filepath" -) - -const initHeader = `# See https://github.com/numtide/devshell -` - -// Init ... -func Init(path string, name string, force bool) error { - // Generate the config - cfg := &Config{ - Devshell: Devshell{ - Name: name, - }, - } - cfgStr := initHeader + Print(cfg) - - // File path - file := filepath.Join(path, FileName) - - // Abort if the file already exists - _, err := os.Stat(file) - if err == nil && !force { - return fmt.Errorf("%s already exists", file) - } - - // Write the config file - w, err := os.Create(file) - if err != nil { - return err - } - _, err = w.WriteString(cfgStr) - if err != nil { - return err - } - return w.Close() -} diff --git a/devshell/config/search.go b/devshell/config/search.go deleted file mode 100644 index 82ee43a3..00000000 --- a/devshell/config/search.go +++ /dev/null @@ -1,55 +0,0 @@ -package config - -import ( - "os" - "path/filepath" -) - -// SearchResult is an "enum" returned by the Search function -type SearchResult int - -const ( - // SearchNone is returned if no result is found - SearchNone = SearchResult(0) - // SearchNix is returned if a shell.nix is found - SearchNix = SearchResult(1) - // SearchTOML is returned if a devshell.toml is found - SearchTOML = SearchResult(2) -) - -// Search for a config file from `path` to up. -func Search(path string) (string, SearchResult) { - for _, dir := range splitPath(path) { - file := filepath.Join(dir, "shell.nix") - if fileReadable(file) { - return file, SearchNix - } - file = filepath.Join(dir, "devshell.toml") - if fileReadable(file) { - return file, SearchTOML - } - } - return "", SearchNone -} - -// fileReadable checks that the file will be accessible. The most reliable way -// to do this is to actually open the file. -func fileReadable(path string) bool { - f, err := os.Open(path) - if err != nil { - return false - } - f.Close() - return true -} - -func splitPath(path string) []string { - path = filepath.Clean(path) - paths := []string{path} - for i := len(path) - 1; i > 0; i-- { - if path[i] == filepath.Separator { - paths = append(paths, path[:i]) - } - } - return paths -} diff --git a/devshell/default.nix b/devshell/default.nix deleted file mode 100644 index 3b2b61ed..00000000 --- a/devshell/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ buildGoModule }: -let - # Small src cleaner. - source = import ../nix/source.nix; -in -buildGoModule { - pname = "devshell"; - version = "0+git"; - src = source.filter { - path = ./.; - allow = [ - ./go.mod - ./go.sum - ./cmd - ./config - (source.matchExt "go") - ]; - }; - vendorSha256 = "sha256-NFsQoPDXEeOmyLR2bCgKuRHw2sjhGQbUmHV8bMJzANw="; -} diff --git a/devshell/go.mod b/devshell/go.mod deleted file mode 100644 index 4d0ac240..00000000 --- a/devshell/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/numtide/devshell/devshell - -go 1.15 - -require ( - github.com/pelletier/go-toml v1.8.1 - github.com/urfave/cli/v2 v2.2.0 -) diff --git a/devshell/go.sum b/devshell/go.sum deleted file mode 100644 index f63949b5..00000000 --- a/devshell/go.sum +++ /dev/null @@ -1,16 +0,0 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= -github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= -github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= -github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/devshell/main.go b/devshell/main.go deleted file mode 100644 index 0c65dc87..00000000 --- a/devshell/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "log" - - "github.com/numtide/devshell/devshell/cmd" -) - -// These values are automatically set by `goreleaser` or can be set with -// `go build -ldflags="-X main.version=something"` for example. -var ( -// version = "dev" -// commit = "unknown" -// date = "unknown" -// builtBy = "unknown" -) - -func main() { - err := cmd.Execute() - if err != nil { - log.Fatal(err) - } -} diff --git a/flake.nix b/flake.nix index d6da6b69..57337261 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,6 @@ }; in { - packages.default = pkgs.cli; legacyPackages = pkgs; devShells.default = pkgs.fromTOML ./devshell.toml; } diff --git a/template/devshell.toml b/template/devshell.toml index 4b8c8bff..62379554 100644 --- a/template/devshell.toml +++ b/template/devshell.toml @@ -1,4 +1,3 @@ # https://numtide.github.io/devshell [[commands]] -package = "devshell.cli" -help = "Per project developer environments" +package = "devshell.hello"