Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5817fe7
WIP
kachick Aug 9, 2023
302039d
Translate git config with home-manager and add ssh siginign
kachick Aug 9, 2023
9e88958
Add an empty commit
kachick Aug 9, 2023
355c8cb
Test commit sign with empty commit
kachick Aug 9, 2023
66bfec7
Test commit sign with empty commit
kachick Aug 9, 2023
c694ee9
Test commit sign with empty commit
kachick Aug 9, 2023
de766dd
Always sign for commits
kachick Aug 9, 2023
3cd9350
Enable IdentitiesOnly in ssh
kachick Aug 9, 2023
59d1a79
Is this actually enabling?
kachick Aug 9, 2023
f7d83aa
Enable openssh package again
kachick Aug 9, 2023
d80ca8b
Bump home-manager
kachick Aug 9, 2023
1e2fab1
Need to bump also pkgs
kachick Aug 9, 2023
2a0ee52
Test commit sign with empty commit
kachick Aug 9, 2023
c65d753
Test commit sign with empty commit
kachick Aug 9, 2023
e77c8b2
Test commit sign with empty commit
kachick Aug 9, 2023
88b70dc
Fix for mac
kachick Aug 9, 2023
a86c6ae
Manage gnome-keyring
kachick Aug 10, 2023
0a9b27f
Specify conponents
kachick Aug 10, 2023
fd259b3
Is this the answer for services?
kachick Aug 10, 2023
b1f640b
Fix merge miss
kachick Aug 10, 2023
e966da7
Using keychain looks fixed the problems, but makes 2x slower shell ex…
kachick Aug 10, 2023
366e9fa
Revert "Using keychain looks fixed the problems, but makes 2x slower …
kachick Aug 10, 2023
12a0962
Add script to remember WSL systemd problems
kachick Aug 10, 2023
4732d2d
Remove unintended appended whitspaces
kachick Aug 10, 2023
48faafb
Remove unused gnome-keyring
kachick Aug 10, 2023
e477796
Run development tasks in both macOS and Linux
kachick Aug 10, 2023
53b4432
Avoid to use uname syscall for macOS
kachick Aug 10, 2023
9183192
Suppress new nixpkgs alerts as non default exe
kachick Aug 10, 2023
589c238
Revert "Is this the answer for services?"
kachick Aug 10, 2023
9cba602
Test commit sign with empty commit
kachick Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ on:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-13
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- ubuntu-22.04
- macos-13
home-manager-channel-ref:
- 729ab77f9e998e0989fa30140ecc91e738bc0cb1 # Pinned for current use
- a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04 # Pinned for current use
- master # unstable nixpkgs

runs-on: ${{ matrix.os }}
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Register Nix Channels
run: |
nix-channel --add https://releases.nixos.org/nixpkgs/nixpkgs-23.11pre509044.3acb5c4264c4/nixexprs.tar.xz nixpkgs
nix-channel --add https://releases.nixos.org/nixpkgs/nixpkgs-23.11pre511546.844ffa82bbe2/nixexprs.tar.xz nixpkgs
nix-channel --add https://github.com/nix-community/home-manager/archive/${{ matrix.home-manager-channel-ref }}.tar.gz home-manager
nix-channel --update
nix-channel --list
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ on:

jobs:
tasks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-13
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions cmd/enable_nix_login_shells/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func main() {
log.Fatalf("failed - could you correctly run this with sudo? - %v\n", err)
}

fmt.Printf(`
Done! Set one of your favorite shell as follows
fmt.Printf(`Done! Set one of your favorite shell as follows

chsh -s %s "$(whoami)"
`, examplePath)
Expand Down
70 changes: 70 additions & 0 deletions cmd/enable_wsl_systemd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"fmt"
"log"
"os"
"strings"

"golang.org/x/sys/unix"
)

// Exists for remember https://github.com/kachick/dotfiles/pull/264#discussion_r1289600371

// This script requires sudo execution

func main() {
// wsl.exe returns non English even in called on the VM https://github.com/microsoft/WSL/issues/9242
// And always having non ASCII, annoy to depend with the output :<
uname := unix.Utsname{}
err := unix.Uname(&uname)
if err != nil {
log.Fatalf("cannot get uname: %+v\n", err)
}
unameStr := ""
// So here, using uname, as I understand it is same as `uname -r`
for _, i8 := range uname.Release {
unameStr += string(rune(int(i8)))
}
if !strings.Contains(unameStr, "microsoft-standard-WSL2") {
log.Fatalf("Looks executed on non WSL systems: %s", unameStr)
}

const path = "/etc/wsl.conf"

const systemdEnablingEntry = `[boot]
systemd=true`

wslConfigBytes, err := os.ReadFile(path)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("%v\n", err)
}

wslConfig := ""

if wslConfigBytes != nil {
wslConfig = string(wslConfigBytes) + "\n"
}

if strings.Contains(wslConfig, "systemd") {
log.Fatalf("Looks areleady exists the systemd config")
}

dirty := strings.Clone(wslConfig)

dirty += fmt.Sprintln(systemdEnablingEntry)

if dirty != wslConfig {
err = os.WriteFile(path, []byte(dirty), os.ModePerm)
if err != nil {
log.Fatalf("failed - could you correctly run this with sudo? - %v\n", err)
}

fmt.Printf(`Done! Restart wsl.exe as follows in your Windows PowerShell

wsl.exe --shutdown

See https://learn.microsoft.com/ja-jp/windows/wsl/systemd for further detail
`)
}
}
19 changes: 18 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
rec {
devShells.default = with pkgs;
mkShell {
buildInputs = [
Expand All @@ -36,6 +36,23 @@
jq
];
};

# https://gist.github.com/Scoder12/0538252ed4b82d65e59115075369d34d?permalink_comment_id=4650816#gistcomment-4650816
packages.json2nix = pkgs.writeScriptBin "json2nix" ''
${pkgs.python3}/bin/python ${pkgs.fetchurl {
url = "https://gist.githubusercontent.com/Scoder12/0538252ed4b82d65e59115075369d34d/raw/e86d1d64d1373a497118beb1259dab149cea951d/json2nix.py";
hash = "sha256-ROUIrOrY9Mp1F3m+bVaT+m8ASh2Bgz8VrPyyrQf9UNQ=";
}} $@
'';

apps = {
# nix run .#json2nix
json2nix = {
type = "app";
program = "${packages.json2nix}/bin/json2nix";
};
};
}
);
}

5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/kachick/dotfiles

go 1.20

require golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
require (
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
golang.org/x/sys v0.11.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
68 changes: 65 additions & 3 deletions home-manager/git.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
{ ... }:
{ config, pkgs, ... }:

# https://github.com/nix-community/home-manager/blob/master/modules/programs/lazygit.nix
{
xdg.configFile."git/config".source = ../home/.config/git/config;
# https://github.com/nix-community/home-manager/blob/master/modules/programs/git.nix
# xdg will be used in home-manager: https://github.com/nix-community/home-manager/blob/7b8d43fbaf8450c30caaed5eab876897d0af891b/modules/programs/git.nix#L417-L418
programs.git = {
enable = true;

userEmail = "kachick1@gmail.com";
userName = "Kenichi Kamiya";

aliases = {
fixup = "commit --all --amend";
empty = "commit --allow-empty -m 'Add an empty commit'";
current = "symbolic-ref --short HEAD";
switch-default = "!git checkout main 2>/dev/null || git checkout master 2>/dev/null";
upstream = "!git remote | grep -E '^upstream$'|| git remote | grep -E '^origin$'";
duster = "remote update origin --prune";
refresh = "!git switch-default && git pull \"$(git upstream)\" \"$(git current)\"";
all = "!git refresh && gh poi";
gui = "!lazygit";
};

extraConfig = {
user = {
# https://stackoverflow.com/questions/48065535/should-i-keep-gitconfigs-signingkey-private
# TODO: Share code to get the path with ./ssh.nix
signingkey = "${config.home.homeDirectory}/.ssh/id_ed25519.pub";
};

core = {
editor = "vim";
quotepath = false;
};

gpg = {
format = "ssh";
};

commit = {
# https://stackoverflow.com/questions/10161198/is-there-a-way-to-autosign-commits-in-git-with-a-gpg-key
gpgsign = true;
};

init = {
defaultBranch = "main";
};

color = {
ui = true;
};

grep = {
lineNumber = true;
};

pull = {
ff = "only";
};

credential = {
"https://github.com".helper = "!${pkgs.gh}/bin/gh auth git-credential";
"https://gist.github.com".helper = "!${pkgs.gh}/bin/gh auth git-credential";
};
};
};

# https://github.com/nix-community/home-manager/blob/master/modules/programs/lazygit.nix
programs.lazygit = {
enable = true;

Expand Down
2 changes: 2 additions & 0 deletions home-manager/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# TODO: How to cover lima? The default is /home/kachick.local
home.homeDirectory = if pkgs.stdenv.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}";

systemd.user.startServices = "sd-switch";

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes following error after several changes, I know nothing about them 🤷‍♂️

thread 'main' panicked at 'Error switching: Failed to connect to socket /run/user/1000/bus


# https://github.com/nix-community/home-manager/blob/master/modules/misc/xdg.nix
xdg.enable = true;

Expand Down
7 changes: 3 additions & 4 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
# Required in many asdf plugins
unzip

# In macOS, starting ssh-agent is still /usr/bin/ssh-agent even added the nixpkgs
# So avoiding to add it for now
# openssh

git
tig
lazygit
Expand Down Expand Up @@ -97,6 +93,9 @@
[
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
glibc

# https://github.com/nix-community/home-manager/blob/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04/modules/services/ssh-agent.nix#L37
openssh
]
) ++ (lib.optionals stdenv.isDarwin
[
Expand Down
6 changes: 6 additions & 0 deletions home-manager/ssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ let
# - id_*.pub: I CAN register them for different services.
in
{
# https://github.com/nix-community/home-manager/blob/master/modules/services/ssh-agent.nix
services.ssh-agent.enable = if pkgs.stdenv.isLinux then true else false;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://unix.stackexchange.com/a/390631

> bat ~/.config/systemd/user/ssh-agent.service
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /home/kachick/.config/systemd/user/ssh-agent.service
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [Install]
   2   │ WantedBy=default.target
   3   │
   4   │ [Service]
   5   │ ExecStart=/nix/store/11p34v2dfzjavry4kmwlp4d8jhjz4c6c-openssh-9.3p2/bin/ssh-agent -D -a %t/ssh-agent
   6   │
   7   │ [Unit]
   8   │ Description=SSH authentication agent
   9   │ Documentation=man:ssh-agent(1)

Already exists 🤔

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After it

> ps -ef | grep ssh
kachick      516     504  0 15:06 ?        00:00:00 /nix/store/11p34v2dfzjavry4kmwlp4d8jhjz4c6c-openssh-9.3p2/bin/ssh-agent -D -a /run/user/1000/ssh-agent
kachick     1225     652  0 15:07 pts/0    00:00:00 grep ssh


# These hosts are taken from the public resources of each provider.
# - https://docs.github.com/ja/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
# - https://docs.gitlab.com/ee/user/gitlab_com/#ssh-known_hosts-entries
Expand Down Expand Up @@ -70,16 +73,19 @@ in
matchBlocks = {
"github.com" = {
identityFile = "${sshDir}/id_ed25519";
identitiesOnly = true;
user = "git";
};

"gitlab.com" = {
identityFile = "${sshDir}/id_ed25519";
identitiesOnly = true;
user = "git";
};

"bitbucket.org" = {
identityFile = "${sshDir}/id_ed25519";
identitiesOnly = true;
user = "git";
};
};
Expand Down
32 changes: 0 additions & 32 deletions home/.config/git/config

This file was deleted.

4 changes: 2 additions & 2 deletions home/.local/share/homemade/bin/add_nix_channels.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ set -euxo pipefail
# List of official resources:
# - https://channels.nixos.org
# - https://releases.nixos.org
nix-channel --add https://releases.nixos.org/nixpkgs/nixpkgs-23.11pre509044.3acb5c4264c4/nixexprs.tar.xz nixpkgs
nix-channel --add https://releases.nixos.org/nixpkgs/nixpkgs-23.11pre511546.844ffa82bbe2/nixexprs.tar.xz nixpkgs
# nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
# nix-channel --add https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager
nix-channel --add https://github.com/nix-community/home-manager/archive/729ab77f9e998e0989fa30140ecc91e738bc0cb1.tar.gz home-manager
nix-channel --add https://github.com/nix-community/home-manager/archive/a8f8f48320c64bd4e3a266a850bbfde2c6fe3a04.tar.gz home-manager
nix-channel --update

nix-channel --list