diff --git a/README.md b/README.md index a192c0a5..f7ef2b40 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Fleek - "Home as Code" for Humans -![FlakeHub](https://img.shields.io/endpoint?url=https://flakehub.com/f/ublue-os/fleek/badge) + +[![FlakeHub](https://img.shields.io/endpoint?url=https://flakehub.com/f/ublue-os/fleek/badge)](https://flakehub.com/flake/ublue-os/fleek) @@ -44,49 +45,7 @@ Fleek is a user-friendly wrapper around Nix and Nix Home Manager, but the friend ## Getting Started -You need `nix`. We love the [Determinate Systems Installer](https://zero-to-nix.com/), but any `nix` installer is good. If you're on Fedora Silverblue, [this script](https://github.com/dnkmmr69420/nix-installer-scripts/blob/main/installer-scripts/silverblue-nix-installer.sh) is the good stuff. - -After Nix is installed you need to enable [flakes and the nix command](https://nixos.wiki/wiki/Flakes). It can be as simple as this: - -```shell -mkdir -p ~/.config/nix -echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf -``` - -Install `fleek`: - -```shell -curl -fsSL https://getfleek.dev/installer | bash -``` - -Run `fleek init`: - -```shell -fleek init -``` - - -This will create your configuration file and symlink it to `$HOME/.fleek.yml`. Open it with your favorite editor and take a look. - -Make any changes to the `~/.fleek.yml` file you want... we recommend Bling Level `high` for the best experience. - -Now let's apply your configuration: - -```shell -fleek apply -``` -It will take a bit to download and install everything, but when it's done you should see something like this: - -```shell -... more text above this ... -Activating onFilesChange -Activating reloadSystemd - [✓] Operation completed successfully -``` - -*What happened here?* We just installed Nix Home Manager, configured it with your preferences, and applied it to your system. - -You may need to close and re-open your terminal or even log out to see the changes. +See [the installation instructions](https://getfleek.dev/docs/installation). ## ~/.fleek.yml diff --git a/internal/flake/flake.go b/internal/flake/flake.go index 9d2494ff..a12e594e 100644 --- a/internal/flake/flake.go +++ b/internal/flake/flake.go @@ -537,6 +537,21 @@ func (f *Flake) writeUser(sys fleek.System, user fleek.User, template string, fo return nil } + +func (f *Flake) WriteTemplates() error { + + writeCmdLine := []string{"run", ".#fleek", "--", "write"} + err := f.runNix(nixbin, writeCmdLine) + if err != nil { + return err + } + err = f.mayCommit("fleek: update templates") + + if err != nil { + return err + } + return nil +} func (f *Flake) Apply() error { fin.Info.Println(f.app.Trans("flake.apply")) diff --git a/internal/flake/templates/flake.nix.tmpl b/internal/flake/templates/flake.nix.tmpl index 6b608671..8c224869 100644 --- a/internal/flake/templates/flake.nix.tmpl +++ b/internal/flake/templates/flake.nix.tmpl @@ -7,11 +7,11 @@ nixpkgs.url = "github:nixos/nixpkgs/{{ .Config.Tracks }}"; # Home manager - home-manager.url = "github:nix-community/home-manager"; + home-manager.url = "https://flakehub.com/f/nix-community/home-manager/0.1.tar.gz"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; # Fleek - fleek.url = "github:ublue-os/fleek"; + fleek.url = "https://flakehub.com/f/ublue-os/fleek/*.tar.gz"; # Overlays {{ range $index, $element := .Config.Overlays }} @@ -22,7 +22,9 @@ }; outputs = { self, nixpkgs, home-manager, fleek, ... }@inputs: { - + {{ range .Config.Systems }} + packages.{{ .Arch }}-{{ .OS }}.fleek = fleek.packages.{{ .Arch }}-{{ .OS }}.default; + {{ end }} # Available through 'home-manager --flake .#your-username@your-hostname' {{ $overlays := .Config.Overlays }} homeConfigurations = { @@ -41,6 +43,11 @@ ./{{.Hostname}}/{{.Username}}.nix ./{{.Hostname}}/custom.nix # self-manage fleek + { + home.packages = [ + fleek.packages.{{ .Arch }}-{{ .OS }}.default + ]; + } ({ nixpkgs.overlays = [{{ range $index, $element := $overlays }}inputs.{{$index}}.overlay {{ end }}]; }) diff --git a/internal/fleek/config.go b/internal/fleek/config.go index d6b07248..0aafc011 100644 --- a/internal/fleek/config.go +++ b/internal/fleek/config.go @@ -59,6 +59,7 @@ type Config struct { Users []*User `yaml:",flow"` Track string `yaml:"track"` AllowBroken bool `yaml:"allow_broken"` + AutoGC bool `yaml:"auto_gc"` } func Levels() []string { @@ -120,6 +121,19 @@ func NewSystem() (*System, error) { Username: user, }, nil } + +// CollectGarbage runs nix-collect-garbage +func CollectGarbage() error { + + command := exec.Command("nix-collect-garbage", "-d") + command.Stdin = os.Stdin + command.Stderr = os.Stderr + command.Stdout = os.Stdout + command.Env = os.Environ() + + return command.Run() + +} func NewUser() (*User, error) { fin.Info.Println("Enter User Details for Git Configuration:") user := &User{} @@ -460,6 +474,7 @@ func (c *Config) WriteInitialConfig(force bool, symlink bool) error { return err } c.Unfree = true + c.AutoGC = true c.Name = "Fleek Configuration" c.Packages = []string{ "helix", diff --git a/internal/fleekcli/root.go b/internal/fleekcli/root.go index 05d874ab..6063a6ac 100644 --- a/internal/fleekcli/root.go +++ b/internal/fleekcli/root.go @@ -101,6 +101,13 @@ func RootCmd() *cobra.Command { fin.Debug.Printfln("git autopush: %v", cfg.Git.AutoPush) fin.Debug.Printfln("git autocommit: %v", cfg.Git.AutoCommit) fin.Debug.Printfln("git autopull: %v", cfg.Git.AutoPull) + fin.Debug.Printfln("auto gc: %v", cfg.AutoGC) + + if cfg.AutoGC { + fin.Info.Println("Running nix-collect-garbage") + // we don't care too much if there's an error here + _ = fleek.CollectGarbage() + } }, RunE: func(cmd *cobra.Command, args []string) error { @@ -152,6 +159,8 @@ func RootCmd() *cobra.Command { infoCmd := InfoCommand() infoCmd.GroupID = packageGroup.ID + writeCmd := WriteCommand() + writeCmd.GroupID = fleekGroup.ID manCmd := ManCommand() docsCmd := genDocsCmd() @@ -171,7 +180,7 @@ func RootCmd() *cobra.Command { command.AddCommand(searchCmd) command.AddCommand(infoCmd) command.AddCommand(generateCmd) - + command.AddCommand(writeCmd) command.AddCommand(VersionCmd()) command.PersistentFlags().BoolVarP( diff --git a/internal/fleekcli/update.go b/internal/fleekcli/update.go index 29e41c86..bc5331dd 100644 --- a/internal/fleekcli/update.go +++ b/internal/fleekcli/update.go @@ -48,6 +48,12 @@ func update(cmd *cobra.Command) error { if err := fl.Update(); err != nil { return err } + // We just updated the flake lock, which might pull a new + // version of fleek in. Update the system templates to + // get new fixes without having to update/apply twice + if err := fl.WriteTemplates(); err != nil { + return err + } if cmd.Flag(app.Trans("update.applyFlag")).Changed { if err := fl.Apply(); err != nil { return err diff --git a/internal/fleekcli/version.go b/internal/fleekcli/version.go index cc6626c1..e8eb0927 100644 --- a/internal/fleekcli/version.go +++ b/internal/fleekcli/version.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/cobra" "github.com/ublue-os/fleek/internal/build" - "github.com/ublue-os/fleek/internal/vercheck" ) type versionFlags struct { @@ -27,7 +26,6 @@ func VersionCmd() *cobra.Command { command.Flags().BoolVarP(&flags.verbose, app.Trans("version.flagVerbose"), "v", false, // value app.Trans("version.flagVerboseDescription"), ) - command.AddCommand(selfUpdateCmd()) return command } @@ -47,18 +45,6 @@ func versionCmdFunc(cmd *cobra.Command, _ []string, flags versionFlags) error { } return nil } -func selfUpdateCmd() *cobra.Command { - command := &cobra.Command{ - Use: "update", - Short: "Update fleek launcher and binary", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - return vercheck.SelfUpdate(cmd.OutOrStdout(), cmd.OutOrStderr()) - }, - } - - return command -} type versionInfo struct { Version string diff --git a/internal/fleekcli/write.go b/internal/fleekcli/write.go new file mode 100644 index 00000000..d455a0d1 --- /dev/null +++ b/internal/fleekcli/write.go @@ -0,0 +1,48 @@ +/* +Copyright © 2023 NAME HERE +*/ +package fleekcli + +import ( + "github.com/spf13/cobra" + "github.com/ublue-os/fleek/fin" + "github.com/ublue-os/fleek/internal/flake" +) + +// WriteCommand is an internal hidden command that +// gets run after an update. +func WriteCommand() *cobra.Command { + command := &cobra.Command{ + Hidden: true, + Use: app.Trans("write.use"), + Short: app.Trans("write.short"), + Long: app.Trans("write.long"), + RunE: func(cmd *cobra.Command, args []string) error { + return write(cmd) + }, + } + + return command +} + +// writeCmd represents the write command +func write(cmd *cobra.Command) error { + fin.Description.Println(cmd.Short) + err := mustConfig() + if err != nil { + return err + } + fl, err := flake.Load(cfg, app) + if err != nil { + return err + } + + err = fl.Write("flake update", true, false) + if err != nil { + fin.Debug.Printfln("flake write error: %s", err) + return err + } + + fin.Success.Println(app.Trans("write.done")) + return nil +} diff --git a/locales/en.yml b/locales/en.yml index 564bae79..c6be01d2 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -238,6 +238,13 @@ info: notFound: "That program or package is not part of fleek's bling set." aliases: "Shell Aliases" description: "Description" +write: + use: "write" + long: "Apply system templates to existing flake" + example: | + fleek write + short: "Apply system templates to existing flake" + done: "Flake templates written." flake: noConfig: "No configuration files found. Try `fleek init`." configLoaded: "Configuration loaded"