Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from ublue-os/init-clone-new-machine
Browse files Browse the repository at this point in the history
fix: create machine specific override file on clone
  • Loading branch information
bketelsen authored Mar 21, 2023
2 parents 0dc7818 + 6b0a23b commit 2735e3e
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions core/flake.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func InitFlake(force bool) error {
return err
}
for _, sys := range data.Config.Systems {
err = writeSystem(sys, t, true, force)
err = writeSystem(sys, t, force)
if err != nil {
return err
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func WriteFlake() error {
return err
}
for _, sys := range data.Config.Systems {
err = writeSystem(sys, t, false, true)
err = writeSystem(sys, t, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func writeFile(fname string, t *template.Template, d Data, force bool) error {
}
return nil
}
func writeSystem(sys System, t *template.Template, user, force bool) error {
func writeSystem(sys System, t *template.Template, force bool) error {
fleekPath, err := FlakeLocation()
if err != nil {
return err
Expand All @@ -263,22 +263,18 @@ func writeSystem(sys System, t *template.Template, user, force bool) error {
} else {
return errors.New("cowardly refusing to overwrite existing file without --force flag")
}
if user {
upath := filepath.Join(hostPath, "user.nix")
_, err = os.Stat(upath)
if force || os.IsNotExist(err) {
upath := filepath.Join(hostPath, "user.nix")
_, err = os.Stat(upath)
if force || os.IsNotExist(err) {

f, err := os.Create(upath)
if err != nil {
return err
}
defer f.Close()
tmplName := "user.nix.tmpl"
if err = t.ExecuteTemplate(f, tmplName, sys); err != nil {
return err
}
} else {
return errors.New("cowardly refusing to overwrite existing file without --force flag")
f, err := os.Create(upath)
if err != nil {
return err
}
defer f.Close()
tmplName := "user.nix.tmpl"
if err = t.ExecuteTemplate(f, tmplName, sys); err != nil {
return err
}
}
return nil
Expand Down

0 comments on commit 2735e3e

Please sign in to comment.