diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-09-07 02:38:53 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-09-07 02:38:53 +0900 |
| commit | 6a7baab2da521c9564a2408d60d885816f1a1be6 (patch) | |
| tree | 59f49a19f231182c1d1ec86c04222bf3c7c85e30 | |
| parent | 53bd8c469f6d7129658badd92f02d91496ff5647 (diff) | |
| download | dotfiles-6a7baab2da521c9564a2408d60d885816f1a1be6.tar.gz dotfiles-6a7baab2da521c9564a2408d60d885816f1a1be6.tar.zst dotfiles-6a7baab2da521c9564a2408d60d885816f1a1be6.zip | |
mitamae: introduce mitamae to provision
| -rw-r--r-- | INSTALL.txt | 6 | ||||
| -rwxr-xr-x | bootstrap | 130 | ||||
| -rw-r--r-- | flake.nix | 23 | ||||
| -rw-r--r-- | home-manager/home.nix | 30 | ||||
| -rw-r--r-- | mitamae/default.rb | 87 | ||||
| -rw-r--r-- | mitamae/node.private-hotaru.json | 17 | ||||
| -rw-r--r-- | mitamae/node.work-pc168.json | 17 |
7 files changed, 184 insertions, 126 deletions
diff --git a/INSTALL.txt b/INSTALL.txt index c4f8951..34ce101 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -4,7 +4,6 @@ macOS (homebrew) $ brew update $ brew install \ python \ - zsh \ ; $ brew install --cask \ @@ -38,12 +37,8 @@ $ sudo apt update $ sudo apt upgrade $ sudo apt install \ python-is-python3 \ - zsh \ ; -# Change login shell to zsh -$ chsh - $ sudo adduser $(whoami) docker $ cargo install hgrep @@ -54,6 +49,7 @@ $ go install github.com/rhysd/vim-startuptime@latest ``` +# ./bootstrap <host> # nix flake update # nix store gc # home-manager switch --flake ".#ken" @@ -1,113 +1,41 @@ #!/bin/sh +MITAMAE_VERSION=v1.14.0 + +usage() { + echo "Usage: $0 <host>" + echo "Availabel hosts:" + find mitamae -name 'node.*.json' | sed -e 's#^mitamae/node[.]##' -e 's#.json##' | sort | sed -e 's/^/ * /' +} + +# Check arguments. if [ $# != 1 ]; then - echo "Usage: $0 <host>" >&2 - echo "Availabel hosts:" >&2 - grep '= mkHomeConfiguration' flake.nix | cut -d '=' -f 1 | sed -e 's/^ */ * /' >&2 + usage >&2 exit 1 fi +target_host="$1" +if [ ! -f "mitamae/node.${target_host}.json" ]; then + usage >&2 + exit 1 +fi +target_arch="$(grep targetArch "mitamae/node.${target_host}.json" | sed -e 's/.*: "//' -e 's/",//')" -export XDG_CONFIG_HOME="$HOME/.config" -export XDG_CACHE_HOME="$HOME/.cache" -export XDG_DATA_HOME="$HOME/.local/share" -export XDG_STATE_HOME="$HOME/.local/state" - -for dir in \ - "$XDG_CONFIG_HOME" \ - "$XDG_CACHE_HOME" \ - "$XDG_DATA_HOME" \ - "$XDG_STATE_HOME" \ - ; \ -do - if [ ! -d "$dir" ]; then - mkdir -p "$dir" - fi -done +# Prepare directory. if [ ! -d .bootstrap ]; then mkdir .bootstrap fi -if [ ! -f .bootstrap/nix-install ]; then - curl -o .bootstrap/nix-install -L https://nixos.org/nix/install -fi -if [ ! -d /nix ]; then - sh .bootstrap/nix-install --daemon - hash -r -fi -if ! grep -q "nix-command flakes" /etc/nix/nix.conf; then - echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf > /dev/null -fi -if [ ! -d "$HOME/.local/state/nix/profiles" ]; then - mkdir -p "$HOME/.local/state/nix/profiles" -fi -if ! type home-manager > /dev/null 2>&1; then - nix run "nixpkgs#home-manager" -- switch --flake ".#$1" -fi -# These dotfiles are not managed by home-manager. -for name in \ - .vimrc \ - .zshenv \ - .zshrc \ - ; \ -do - if [ ! -L ~/"$name" ]; then - ln -s -f ~/dotfiles/"$name" ~/"$name" - fi -done -for name in \ - alacritty \ - git \ - nvim \ - ; \ -do - if [ ! -L ~/.config/"$name" ]; then - ln -s -f ~/dotfiles/.config/"$name" ~/.config/"$name" - fi -done - -# Go -for name in \ - gitalias/git-extract-issue \ - gitalias/git-sw \ - ; \ -do - src_file="src/$name.go" - bin_file="bin/$name" - if [ "$bin_file" -ot "$src_file" ]; then - go build -o "$bin_file" "$src_file" - fi -done -if [ ! -d ~/bin ]; then - mkdir ~/bin -fi -if [ ! -d ~/bin/gitalias ]; then - mkdir ~/bin/gitalias +# Install mitamae. +if [ ! -f .bootstrap/mitamae.tar.gz ]; then + curl -L -o .bootstrap/mitamae.tar.gz \ + "https://github.com/itamae-kitchen/mitamae/releases/download/${MITAMAE_VERSION}/mitamae-${target_arch}.tar.gz" fi -for name in \ - tmux-pane-idx \ - gitalias/git-extract-issue \ - gitalias/git-sw \ - ; \ -do - if [ ! -L ~/bin/"$name" ]; then - ln -s -f ~/dotfiles/bin/"$name" ~/bin/"$name" - fi -done -if [ ! -f ~/.config/alacritty/alacritty.local.yml ]; then - if [ "$(uname)" = "Darwin" ]; then - ln -s -f ~/.config/alacritty/alacritty.macos.yml ~/.config/alacritty/alacritty.local.yml - else - ln -s -f ~/.config/alacritty/alacritty.linux.yml ~/.config/alacritty/alacritty.local.yml - fi -fi -if [ ! -d ~/.config/skk ]; then - mkdir ~/.config/skk -fi -if [ ! -f ~/.config/skk/jisyo.L ]; then - _compressed_jisyo="$(mktemp)" - curl -fL -o "$_compressed_jisyo" https://skk-dev.github.io/dict/SKK-JISYO.L.unannotated.gz - gunzip -cd "$_compressed_jisyo" > ~/.config/skk/jisyo.L -fi -if [ ! -d "$XDG_STATE_HOME/zsh" ]; then - mkdir -p "$XDG_STATE_HOME/zsh" +if [ ! -f .bootstrap/mitamae ]; then + tar xf .bootstrap/mitamae.tar.gz -C .bootstrap + mv ".bootstrap/mitamae-${target_arch}" .bootstrap/mitamae fi + +# Run mitamae. +.bootstrap/mitamae local \ + --node-json "mitamae/node.${target_host}.json" \ + mitamae/default.rb @@ -42,23 +42,12 @@ ]; }; in { - homeConfigurations = { - privateHotaru = mkHomeConfiguration { - system = "x86_64-linux"; - env = { - username = "ken"; - homeDirectory = "/home/ken"; - gui.clipboard.copyCommand = null; - }; - }; - workPc168 = mkHomeConfiguration { - system = "aarch64-darwin"; - env = { - username = "ken"; - homeDirectory = "/Users/ken"; - gui.clipboard.copyCommand = "pbcopy"; - }; - }; + homeConfigurations = let + readJSON = p: builtins.fromJSON (builtins.readFile p); + mkHomeConfigurationFromJSON = p: mkHomeConfiguration (readJSON p).flake; + in { + private-hotaru = mkHomeConfigurationFromJSON ./mitamae/node.private-hotaru.json; + work-pc168 = mkHomeConfigurationFromJSON ./mitamae/node.work-pc168.json; }; }; } diff --git a/home-manager/home.nix b/home-manager/home.nix index da6601e..0d5eaa7 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -36,7 +36,6 @@ in pkgs.tokei pkgs.tree pkgs.zig - # pkgs.zsh pkgs.nodePackages.typescript-language-server ] ++ pkgs.lib.optional requiresWlClipboard pkgs.wl-clipboard; @@ -45,8 +44,23 @@ in # "hoge".source = dotfiles/piyo; }; - home.sessionVariables = { - # EDITOR = "nvim"; + home.sessionVariables = rec { + # XDG Base Directories + # See: https://wiki.archlinux.org/title/XDG_Base_Directory + XDG_CONFIG_HOME = "${homeDirectory}/.config"; + XDG_CACHE_HOME = "${homeDirectory}/.cache"; + XDG_DATA_HOME = "${homeDirectory}/.local/share"; + XDG_STATE_HOME = "${homeDirectory}/.local/state"; + # XDG Base Directories: Node.js + NODE_REPL_HISTORY = "${XDG_CACHE_HOME}/node_repl_history"; + # XDG Base Directories: SQLite + SQLITE_HISTORY = "${XDG_CACHE_HOME}/sqlite_history"; + + # Local + LANG = "en_US.UTF-8"; + LC_ALL = ""; + # Locale: Less + LESSCHARSET = "utf-8"; }; programs.direnv = { @@ -80,4 +94,14 @@ in in commonConfig + extraConfig; }; + + programs.zsh = { + enable = true; + + envExtra = '' + export PATH="$HOME/bin:$HOME/.local/bin:$PATH" + ''; + + initExtra = builtins.readFile ../.zshrc; + }; } diff --git a/mitamae/default.rb b/mitamae/default.rb new file mode 100644 index 0000000..ea2859a --- /dev/null +++ b/mitamae/default.rb @@ -0,0 +1,87 @@ +http_request ".bootstrap/nix-install" do + url "https://nixos.org/nix/install" +end + +execute "nix-install" do + command "sh .bootstrap/nix-install --daemon" + not_if "test -d /nix" +end + +file "/etc/nix/nix.conf" do + action :edit + block do |content| + content + "experimental-features = nix-command flakes\n" + end + not_if "grep -q 'nix-command flakes' /etc/nix/nix.conf" +end + +home = ENV['HOME'] + +directory "#{home}/.local/state/nix/profiles" + +# XDG Base Directories +directory "#{home}/.config" +directory "#{home}/.cache" +directory "#{home}/.local/share" +directory "#{home}/.local/state" + +directory "#{home}/bin" + +execute "home-manager" do + command "nix run 'nixpkgs#home-manager' -- switch --flake '.##{node[:name]}'" + not_if "type home-manager" +end + +# These dotfiles are not managed by home-manager for now. + +link "#{home}/.vimrc" do + to "#{home}/dotfiles/.vimrc" +end +link "#{home}/.config/alacritty" do + to "#{home}/dotfiles/.config/alacritty" +end +link "#{home}/.config/git" do + to "#{home}/dotfiles/.config/git" +end +link "#{home}/.config/nvim" do + to "#{home}/dotfiles/.config/nvim" +end + +# Go +execute "go" do + command "go build -o bin/gitalias/git-extract-issue src/gitalias/git-extract-issue.go" + not_if "test -f bin/gitalias/git-extract-issue" +end +execute "go" do + command "go build -o bin/gitalias/git-sw src/gitalias/git-sw.go" + not_if "test -f bin/gitalias/git-sw" +end + +directory "#{home}/bin/gitalias" + +link "#{home}/bin/gitalias/git-extract-issue" do + to "#{home}/dotfiles/bin/gitalias/git-extract-issue" +end +link "#{home}/bin/gitalias/git-sw" do + to "#{home}/dotfiles/bin/gitalias/git-sw" +end +link "#{home}/bin/tmux-pane-idx" do + to "#{home}/dotfiles/bin/tmux-pane-idx" +end + +directory "#{home}/.local/state/zsh" + +# SKK +directory "#{home}/.config/skk" +http_request "#{home}/.config/skk/SKK-JISYO.L.unannotated.gz" do + url "https://skk-dev.github.io/dict/SKK-JISYO.L.unannotated.gz" +end +execute "unzip skk" do + command "gunzip -cd #{home}/.config/skk/SKK-JISYO.L.unannotated.gz > #{home}/.config/skk/jisyo.L" + not_if "test -f #{home}/.config/skk/jisyo.L" +end + +link "#{home}/.config/alacritty/alacritty.local.yml" do + is_macos = node[:targetArch].include?("darwin") + to "#{home}/.config/alacritty/alacritty.#{is_macos ? "macos" : "linux"}.yml" +end diff --git a/mitamae/node.private-hotaru.json b/mitamae/node.private-hotaru.json new file mode 100644 index 0000000..60cec07 --- /dev/null +++ b/mitamae/node.private-hotaru.json @@ -0,0 +1,17 @@ +{ + "name": "private-hotaru", + "use": "private", + "targetArch": "x86_64-linux", + "flake": { + "system": "x86_64-linux", + "env": { + "username": "ken", + "homeDirectory": "/home/ken", + "gui": { + "clipboard": { + "copyCommand": null + } + } + } + } +} diff --git a/mitamae/node.work-pc168.json b/mitamae/node.work-pc168.json new file mode 100644 index 0000000..2ef46e1 --- /dev/null +++ b/mitamae/node.work-pc168.json @@ -0,0 +1,17 @@ +{ + "name": "work-pc168", + "use": "work", + "targetArch": "aarch64-darwin", + "flake": { + "system": "aarch64-darwin", + "env": { + "username": "ken", + "homeDirectory": "/Users/ken", + "gui": { + "clipboard": { + "copyCommand": "pbcopy" + } + } + } + } +} |
