add system-path to build

This commit is contained in:
Daylin Morgan 2024-06-19 14:03:14 -05:00
parent 22c9a5b420
commit ddcc88fd17
Signed by: daylin
GPG key ID: 950D13E9719334AD
7 changed files with 18 additions and 16 deletions

View file

@ -15,4 +15,5 @@ var buildCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
buildCmd.Flags().BoolVar(&systemPath, "system-path", false, "show system-path drv")
}

View file

@ -3,6 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"
)
// gh workflow run build.yml -F lockFile=@flake.lock
var ciCmd = &cobra.Command{
@ -13,7 +14,6 @@ var ciCmd= &cobra.Command{
},
}
func init() {
rootCmd.AddCommand(ciCmd)

View file

@ -12,7 +12,6 @@ var dryCmd = &cobra.Command{
},
}
func init() {
rootCmd.AddCommand(dryCmd)

View file

@ -14,7 +14,6 @@ var outputCmd = &cobra.Command{
},
}
func init() {
rootCmd.AddCommand(outputCmd)
outputCmd.Flags().BoolVar(&systemPath, "system-path", false, "show system-path drv")

View file

@ -13,7 +13,7 @@ let
in
buildGoModule {
pname = "oizys";
version = "d${mkDate self.lastModifiedDate}";
version = "${self.shortRev or "dirty"}";
src = cleanSource ./.;
vendorHash = "sha256-/JVXhXrU2np/ty7AGFy+LPZCo1NaLYl9NAyD9+FJYBI=";

View file

@ -62,7 +62,8 @@ func parseSystemPath(derivation map[string]Derivation) (string, error) {
// nix derivation show `oizys output` | jq -r '.[].inputDrvs | with_entries(select(.key|match("system-path";"i"))) | keys | .[]'
func (o *Oizys) getSystemPath() string {
cmd := exec.Command("nix", "derivation", "show", o.nixosConfigAttr())
log.Info("evaluating to get system-path")
logCmd(cmd)
// TODO: add spinner?
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
@ -189,6 +190,9 @@ func (p *packages) summary() {
Render(fmt.Sprint(len(p.names))),
)
}
func logCmd(cmd *exec.Cmd) {
log.Debugf("CMD: %s", strings.Join(cmd.Args, " "))
}
func (o *Oizys) git(rest ...string) *exec.Cmd {
args := []string{"-C", o.flake}
@ -256,10 +260,6 @@ func showDryRunResult(nixOutput string, verbose bool) {
toFetch.show(verbose)
}
func logCmd(cmd *exec.Cmd) {
log.Debugf("CMD: %s %s", cmd.Path, strings.Join(cmd.Args, " "))
}
func (o *Oizys) NixDryRun(verbose bool, rest ...string) {
args := []string{
"build", o.nixosConfigAttr(), "--dry-run",
@ -288,11 +288,11 @@ func (o *Oizys) NixosRebuild(subcmd string, rest ...string) {
if o.verbose {
cmd.Args = append(cmd.Args, "--print-build-logs")
}
logCmd(cmd)
runCommand(cmd)
}
func runCommand(cmd *exec.Cmd) {
logCmd(cmd)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
@ -308,6 +308,9 @@ func (o *Oizys) NixBuild(nom bool, rest ...string) {
cmdName = "nix"
}
cmd := exec.Command(cmdName, "build")
if o.systemPath {
cmd.Args = append(cmd.Args, fmt.Sprintf("%s^*", o.getSystemPath()))
}
cmd.Args = append(cmd.Args, rest...)
runCommand(cmd)
}