Home

nixfig @main - refs - log -
-
https://git.jolheiser.com/nixfig.git
Nix as a Config
tree log patch
fix: always enable nix-command Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQNSEdoOJWmlzG0EwgPzyPrh94qHPjfSzzCzClai4eMoGG6sP6G6+W9hbKdOs9lQE0h ee/b+XkVyOuhQlptlBGgQ= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
2 months ago
3 changed files, 2 additions(+), 125 deletions(-)
D cmd/nixfig/main.go
diff --git a/cmd/nixfig/main.go b/cmd/nixfig/main.go
deleted file mode 100644
index f36d962fbc2f0401e42ae3fa6b7fe6fa1dda0f30..0000000000000000000000000000000000000000
--- a/cmd/nixfig/main.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package main
-
-import (
-	"encoding/json"
-	"errors"
-	"fmt"
-	"os"
-	"path/filepath"
-
-	"go.jolheiser.com/nixfig"
-)
-
-func maine() error {
-	if len(os.Args) != 2 {
-		return errors.New("nixfig requires 1 argument")
-	}
-	fn := os.Args[1]
-
-	data, err := os.ReadFile(fn)
-	if err != nil {
-		return fmt.Errorf("could not read file %q: %w", fn, err)
-	}
-
-	var out []byte
-	var a any
-	switch ext := filepath.Ext(fn); ext {
-	case ".json":
-		if err := json.Unmarshal(data, &a); err != nil {
-			return fmt.Errorf("invalid JSON file: %w", err)
-		}
-		out, err = nixfig.Marshal(a)
-	case ".nix":
-		if err := nixfig.Unmarshal(data, &a); err != nil {
-			return fmt.Errorf("invalid nix file: %w", err)
-		}
-		out, err = json.Marshal(a)
-	default:
-		return fmt.Errorf("unknown extension %q, must be json or nix", ext)
-	}
-	if err != nil {
-		return err
-	}
-
-	fmt.Print(string(out))
-	return nil
-}
-
-func main() {
-	if err := maine(); err != nil {
-		fmt.Println(err)
-		os.Exit(1)
-	}
-}
D cmd/nixgen/main.go
diff --git a/cmd/nixgen/main.go b/cmd/nixgen/main.go
deleted file mode 100644
index c76bc456d59f37bb2d34dfc0733644899d85ec50..0000000000000000000000000000000000000000
--- a/cmd/nixgen/main.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package main
-
-import (
-	"encoding/json"
-	"errors"
-	"flag"
-	"fmt"
-	"os"
-	"strings"
-
-	"github.com/pelletier/go-toml/v2"
-	"go.jolheiser.com/nixfig"
-	"gopkg.in/yaml.v3"
-)
-
-func maine() error {
-	fs := flag.NewFlagSet("nixgen", flag.ExitOnError)
-
-	format := func(v any) ([]byte, error) {
-		return json.MarshalIndent(v, "", "\t")
-	}
-	formatFunc := func(s string) error {
-		switch strings.ToLower(s) {
-		case "json":
-			// Default
-		case "yaml":
-			format = yaml.Marshal
-		case "toml":
-			format = toml.Marshal
-		default:
-			return fmt.Errorf("unknown format %q, should be one of [json yaml toml]", s)
-		}
-		return nil
-	}
-	fs.Func("format", "Output format [json, yaml, toml]: default 'json'", formatFunc)
-	fs.Func("f", "--format", formatFunc)
-	if err := fs.Parse(os.Args[1:]); err != nil {
-		return err
-	}
-
-	if len(fs.Args()) < 1 {
-		return errors.New("nixgen requires a file")
-	}
-
-	fp := fs.Arg(0)
-	data, err := os.ReadFile(fp)
-	if err != nil {
-		return err
-	}
-
-	var nix map[string]any
-	if err := nixfig.Unmarshal(data, &nix); err != nil {
-		return err
-	}
-
-	out, err := format(nix)
-	if err != nil {
-		return err
-	}
-	fmt.Println(string(out))
-
-	return nil
-}
-
-func main() {
-	if err := maine(); err != nil {
-		fmt.Println(err)
-		os.Exit(1)
-	}
-}
M nixfig.go -> nixfig.go
diff --git a/nixfig.go b/nixfig.go
index e1597bcf2f5021c3365345d9329920f92503260c..91a746eb6b67841fae8929b12438850e2f93622d 100644
--- a/nixfig.go
+++ b/nixfig.go
@@ -46,7 +46,7 @@ 		return ErrNixNotFound
 	}
 
 	var stdout, stderr bytes.Buffer
-	cmd := exec.Command(Nix, "eval", "--json", "--expr", string(data))
+	cmd := exec.Command(Nix, "--extra-experimental-features", "nix-command", "eval", "--json", "--expr", string(data))
 	cmd.Stdout = &stdout
 	cmd.Stderr = &stderr
 	if err := cmd.Run(); err != nil {
@@ -74,7 +74,7 @@ 		return nil, fmt.Errorf("could not marshal JSON: %w", err)
 	}
 
 	var stdout, stderr bytes.Buffer
-	cmd := exec.Command(Nix, "eval", "--expr", fmt.Sprintf(`(builtins.fromJSON %q)`, string(data)))
+	cmd := exec.Command(Nix, "--extra-experimental-features", "nix-command", "eval", "--expr", fmt.Sprintf(`(builtins.fromJSON %q)`, string(data)))
 	cmd.Stdout = &stdout
 	cmd.Stderr = &stderr
 	if err := cmd.Run(); err != nil {