From 5817fe7cb357359b169d0c023223f27b33d0dd80 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Thu, 10 Aug 2023 00:57:17 +0900 Subject: [PATCH] WIP --- flake.nix | 19 ++++++++++++++- home-manager/git.nix | 56 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index fa689f8a..50bd222d 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; in - { + rec { devShells.default = with pkgs; mkShell { buildInputs = [ @@ -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"; + }; + }; } ); } + diff --git a/home-manager/git.nix b/home-manager/git.nix index 5f8bbad7..9993d973 100644 --- a/home-manager/git.nix +++ b/home-manager/git.nix @@ -1,9 +1,59 @@ -{ ... }: +{ config, ... }: -# 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; + + extraConfig = { + user = { + email = "kachick1@gmail.com"; + name = "Kenichi Kamiya"; + # TODO: Share code to get the path with ./ssh.nix + signingkey = "${config.home.homeDirectory}/.ssh/id_ed25519.pub"; + }; + + core = { + editor = "vim"; + quotepath = false; + }; + init = { + defaultBranch = "main"; + }; + color = { + ui = true; + }; + grep = { + lineNumber = true; + }; + pull = { + ff = "only"; + }; + alias = { + 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"; + }; + gpg = { + format = "ssh"; + }; + "credential \"https-github.com\"" = { + helper = "!gh auth git-credential"; + }; + "credential \"https-gist.github.com\"" = { + helper = "!gh auth git-credential"; + }; + }; + }; + # https://github.com/nix-community/home-manager/blob/master/modules/programs/lazygit.nix programs.lazygit = { enable = true;