QOL oizys-go

This commit is contained in:
Daylin Morgan 2024-06-17 16:15:37 -05:00
parent c51da5dacf
commit 0e132b9372
Signed by: daylin
GPG key ID: 950D13E9719334AD
7 changed files with 90 additions and 10 deletions

View file

@ -56,7 +56,7 @@ in
oizys-zig = pkgs.callPackage ../pkgs/oizys/oizys-zig { inherit zig2nix; };
oizys-nim = pkgs.callPackage ../pkgs/oizys/oizys-nim { };
oizys-rs = pkgs.callPackage ../pkgs/oizys/oizys-rs { };
oizys-go = pkgs.callPackage ../pkgs/oizys/oizys-go { };
oizys-go = pkgs.callPackage ../pkgs/oizys/oizys-go { inherit self;};
default = oizys-go;
});
devShells = forAllSystems (pkgs: {

View file

@ -24,6 +24,9 @@
environment.systemPackages = [
pkgs.nixd
pkgs.nixfmt-rfc-style
pkgs.nix-output-monitor
self.packages.${pkgs.system}.default
];

View file

@ -8,10 +8,11 @@ var buildCmd = &cobra.Command{
Use: "build",
Short: "nix build",
Run: func(cmd *cobra.Command, args []string) {
oizys.NixBuild(args...)
oizys.NixBuild(nom, args...)
},
}
func init() {
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
}

View file

@ -0,0 +1,18 @@
package cmd
import (
"github.com/spf13/cobra"
)
var checksCmd = &cobra.Command{
Use: "checks",
Short: "nix build checks",
Run: func(cmd *cobra.Command, args []string) {
oizys.Checks(nom, args...)
},
}
func init() {
rootCmd.AddCommand(checksCmd)
checksCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
}

View file

@ -31,6 +31,7 @@ var (
host string
cacheName string
verbose bool
nom bool
)
var oizys = o.NewOizys()

View file

@ -1,14 +1,25 @@
{
self,
lib,
installShellFiles,
buildGoModule,
makeWrapper,
gh,
nix-output-monitor,
...
}:
let
mkDate =
longDate:
(lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
in
buildGoModule {
pname = "oizys";
version = "unstable";
version = "date=${mkDate self.lastModifiedDate}";
src = lib.cleanSource ./.;
vendorHash = "sha256-Geqcp0/7I1IF2IfaYyIChz7SOCF+elIEdcz2VsAU0hQ=";
@ -25,6 +36,6 @@ buildGoModule {
postFixup = ''
wrapProgram $out/bin/oizys \
--prefix PATH ${lib.makeBinPath [ gh ]}
--prefix PATH ':' ${lib.makeBinPath [ gh nix-output-monitor ]}
'';
}

View file

@ -1,6 +1,7 @@
package oizys
import (
"encoding/json"
"errors"
"fmt"
"io/fs"
@ -24,7 +25,6 @@ type Oizys struct {
verbose bool
}
func NewOizys() *Oizys {
hostname, err := os.Hostname()
if err != nil {
@ -246,13 +246,59 @@ func runCommand(cmd *exec.Cmd) {
}
}
func (o *Oizys) NixBuild(rest ...string) {
args := []string{"build", o.Output()}
args = append(args, rest...)
cmd := exec.Command("nix", args...)
// func runBuildWithNom(buildCmd *exec.Cmd) {
// log.Println("starting build?")
// nomCmd := exec.Command("nom","--json")
// var err error
// buildCmd.Args = append(buildCmd.Args, "--log-format", "internal-json", "-v")
// nomCmd.Stdin, err = buildCmd.StderrPipe()
// if err != nil {
// log.Fatal(err)
// }
// nomCmd.Stdout = os.Stdout
// nomCmd.Start()
// log.Println("starting buildcmd?")
// buildCmd.Run()
// nomCmd.Wait()
// }
func (o *Oizys) NixBuild(nom bool, rest ...string) {
var cmdName string
if nom {
cmdName = "nom"
} else {
cmdName = "nix"
}
cmd := exec.Command(cmdName, "build")
cmd.Args = append(cmd.Args, rest...)
runCommand(cmd)
}
func (o *Oizys) getChecks() []string {
attrName := fmt.Sprintf("%s#%s", o.flake, "checks.x86_64-linux")
cmd := exec.Command("nix", "eval", attrName, "--apply", "builtins.attrNames", "--json")
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
var checks []string
if err := json.Unmarshal(out, &checks); err != nil {
log.Fatal(err)
}
return checks
}
func (o *Oizys) checkPath(name string) string {
return fmt.Sprintf("%s#checks.x86_64-linux.%s", o.flake, name)
}
func (o *Oizys) Checks(nom bool, rest ...string) {
checks := o.getChecks()
for _, check := range checks {
o.NixBuild(nom, o.checkPath(check))
}
}
func (o *Oizys) CacheBuild(rest ...string) {
args := []string{
"watch-exec", o.cache, "--", "nix",
@ -289,7 +335,7 @@ func Output(flake string, host string) string {
func nixSpinner(host string) *spinner.Spinner {
msg := fmt.Sprintf("%s %s", " evaluating derivation for:",
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("6")).Render(host),
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("6")).Render(host),
)
s := spinner.New(
spinner.CharSets[14],