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 #3 from ublue-os/profiles
Browse files Browse the repository at this point in the history
feat: starter set of profiles
  • Loading branch information
bketelsen authored Mar 17, 2023
2 parents 8a533a6 + defae22 commit 2235cd3
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 33 deletions.
3 changes: 2 additions & 1 deletion clean.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh

rm ~/.fleek.yml
rm -rf ~/.config/home-manager
rm -rf ~/.config/home-manager
rm -rf dist
62 changes: 40 additions & 22 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ package core
import (
"errors"
"os"
"strings"

"gopkg.in/yaml.v3"
)

var (
shells = []string{"bash", "zsh"}
blingLevels = []string{"low", "default", "high"}
lowPackages = []string{"htop"}
defaultPackages = []string{"fzf", "ripgrep", "vscode"}
highPackages = []string{"lazygit", "jq", "yq", "neovim", "neofetch", "btop", "cheat"}
lowPrograms = []string{"starship"}
defaultPrograms = []string{"gh", "direnv"}
highPrograms = []string{"exa", "bat", "atuin", "zoxide"}
)

// Config holds the options that will be
// merged into the home-manager flake.
type Config struct {
Unfree bool `yaml:"unfree"`
Unfree bool `yaml:"unfree"`
// bash or zsh
Shell string `yaml:"shell"`
// low, default, high
Bling string `yaml:"bling"`
Repository string `yaml:"repo"`
Name string `yaml:"name"`
Packages []string `yaml:",flow"`
Expand All @@ -24,6 +40,25 @@ type Me struct {
Email string `yaml:"email"`
}

func (c Config) Validate() error {
if !isValueInList(c.Shell, shells) {
return errors.New("fleek.yml: invalid shell, valid shells are: " + strings.Join(shells, ", "))
}
if !isValueInList(c.Bling, blingLevels) {
return errors.New("fleek.yml: invalid bling level, valid levels are: " + strings.Join(blingLevels, ", "))
}
return nil
}

func isValueInList(value string, list []string) bool {
for _, v := range list {
if v == value {
return true
}
}
return false
}

// ReadConfig returns the configuration data
// stored in $HOME/.fleek.yml
func ReadConfig() (*Config, error) {
Expand All @@ -50,32 +85,15 @@ func WriteSampleConfig(email, name string, force bool) error {
aliases["cdfleek"] = "cd ~/.config/home-manager"
c := Config{
Unfree: true,
Shell: "bash",
Bling: "default",
Name: "My Fleek Configuration",
Repository: "git@github.com/my/homeconfig",
Packages: []string{
"neovim",
"fzf",
"nixfmt",
"lazygit",
"ripgrep",
"jq",
"dive",
"htop",
"yq",
"vscode",
"go_1_20",
"gnumake",
"gcc",
"statix",
"rustup",
"goreleaser",
"helix",
},
Programs: []string{
"direnv",
"starship",
"atuin",
"gh",
"zellij",
"dircolors",
},
Aliases: aliases,
Paths: []string{
Expand Down
48 changes: 39 additions & 9 deletions core/flake.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import (
)

type Data struct {
Config *Config
UserName string
Home string
Config *Config
UserName string
Home string
LowPackages []string
DefaultPackages []string
HighPackages []string
LowPrograms []string
DefaultPrograms []string
HighPrograms []string
}

// InitFlake writes the first flake configuration
Expand All @@ -26,6 +32,10 @@ func InitFlake(force bool) error {
if err != nil {
return err
}
err = conf.Validate()
if err != nil {
return err
}
user, err := user.Current()
if err != nil {
return err
Expand All @@ -38,9 +48,15 @@ func InitFlake(force bool) error {
return err
}
data := Data{
Config: conf,
UserName: username,
Home: home,
Config: conf,
UserName: username,
Home: home,
LowPackages: lowPackages,
DefaultPackages: defaultPackages,
HighPackages: highPackages,
LowPrograms: lowPrograms,
DefaultPrograms: defaultPrograms,
HighPrograms: highPrograms,
}

err = writeFile("flake.nix", t, data, force)
Expand Down Expand Up @@ -86,6 +102,10 @@ func WriteFlake() error {
if err != nil {
return err
}
err = conf.Validate()
if err != nil {
return err
}
user, err := user.Current()
if err != nil {
return err
Expand All @@ -98,9 +118,15 @@ func WriteFlake() error {
return err
}
data := Data{
Config: conf,
UserName: username,
Home: home,
Config: conf,
UserName: username,
Home: home,
LowPackages: lowPackages,
DefaultPackages: defaultPackages,
HighPackages: highPackages,
LowPrograms: lowPrograms,
DefaultPrograms: defaultPrograms,
HighPrograms: highPrograms,
}

err = writeFile("home.nix", t, data, true)
Expand Down Expand Up @@ -131,6 +157,10 @@ func ApplyFlake() error {
if err != nil {
return err
}
err = conf.Validate()
if err != nil {
return err
}
workdir, err := FlakeLocation()
if err != nil {
return err
Expand Down
14 changes: 13 additions & 1 deletion core/home.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@
# packages are just installed
home.packages = [{{ range .Config.Packages }}
pkgs.{{ . }}{{ end }}
(pkgs.nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" ]; })
{{ range .LowPackages }}
pkgs.{{ . }}{{end}}
{{ if eq .Config.Bling "default" }}
{{ range .DefaultPackages }}
pkgs.{{ . }}{{end}}
{{ end }}
{{ if eq .Config.Bling "high" }}
{{ range .DefaultPackages }}
pkgs.{{ . }}{{end}}
{{ range .HighPackages }}
pkgs.{{ . }}{{end}}
{{ end }}
(pkgs.nerdfonts.override { fonts = [ "FiraCode" ]; })
];
fonts.fontconfig.enable = true;
home.stateVersion =
Expand Down
16 changes: 16 additions & 0 deletions core/programs.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@
# programs are installed and configured.
# add your program configuration in ./user.nix{{ range .Config.Programs }}
programs.{{ . }}.enable = true;{{ end }}
# low bling
{{ range .LowPrograms }}
programs.{{ . }}.enable = true;{{ end }}
{{ if eq .Config.Bling "default" }}
# default bling
{{ range .DefaultPrograms }}
programs.{{ . }}.enable = true;{{ end }}
{{ end }}
{{ if eq .Config.Bling "high" }}
# default bling
{{ range .DefaultPrograms }}
programs.{{ . }}.enable = true;{{ end }}
# high bling
{{ range .HighPrograms }}
programs.{{ . }}.enable = true;{{ end }}
{{ end }}
}
9 changes: 9 additions & 0 deletions core/shell.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
programs.git.userEmail = "{{.Config.Me.Email}}";
programs.git.userName = "{{.Config.Me.Name}}";

# {{ .Config.Shell }}
{{ if eq .Config.Shell "bash" }}
programs.bash.profileExtra = ". {{.Home}}/.nix-profile/etc/profile.d/nix.sh";
programs.bash.enableCompletion = true;
programs.bash.enableVteIntegration = true;
programs.bash.enable = true;
{{ end }}

{{ if eq .Config.Shell "zsh" }}
programs.zsh.profileExtra = ". {{.Home}}/.nix-profile/etc/profile.d/nix.sh";
programs.zsh.enableCompletion = true;
programs.zsh.enable = true;
{{ end }}
}

0 comments on commit 2235cd3

Please sign in to comment.