From 94142ef5780de4a049436de08b8d7e0cd3d04245 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 14 Dec 2023 06:19:50 -0800 Subject: simplify the layout --- home/darwin.nix | 36 ++++++++++++++++++++++ home/dev.nix | 47 +++++++++++++++++++++++++++++ home/emacs.nix | 12 ++++++++ home/git.nix | 77 +++++++++++++++++++++++++++++++++++++++++++++++ home/home.nix | 69 ++++++++++++++++++++++++++++++++++++++++++ home/profiles/darwin.nix | 36 ---------------------- home/profiles/dev.nix | 47 ----------------------------- home/profiles/emacs.nix | 12 -------- home/profiles/git.nix | 77 ----------------------------------------------- home/profiles/home.nix | 69 ------------------------------------------ home/profiles/ssh.nix | 21 ------------- home/profiles/tmux.nix | 20 ------------ home/profiles/yubikey.nix | 28 ----------------- home/profiles/zsh.nix | 45 --------------------------- home/ssh.nix | 21 +++++++++++++ home/tmux.nix | 20 ++++++++++++ home/yubikey.nix | 28 +++++++++++++++++ home/zsh.nix | 45 +++++++++++++++++++++++++++ hosts/mba/default.nix | 2 +- 19 files changed, 356 insertions(+), 356 deletions(-) create mode 100644 home/darwin.nix create mode 100644 home/dev.nix create mode 100644 home/emacs.nix create mode 100644 home/git.nix create mode 100644 home/home.nix delete mode 100644 home/profiles/darwin.nix delete mode 100644 home/profiles/dev.nix delete mode 100644 home/profiles/emacs.nix delete mode 100644 home/profiles/git.nix delete mode 100644 home/profiles/home.nix delete mode 100644 home/profiles/ssh.nix delete mode 100644 home/profiles/tmux.nix delete mode 100644 home/profiles/yubikey.nix delete mode 100644 home/profiles/zsh.nix create mode 100644 home/ssh.nix create mode 100644 home/tmux.nix create mode 100644 home/yubikey.nix create mode 100644 home/zsh.nix diff --git a/home/darwin.nix b/home/darwin.nix new file mode 100644 index 0000000..ef2787d --- /dev/null +++ b/home/darwin.nix @@ -0,0 +1,36 @@ +{ config, pkgs, ... }: +{ + home.stateVersion = "23.05"; + + imports = [ + ./git.nix + ./zsh.nix + ./dev.nix + ./tmux.nix + ./ssh.nix + ]; + + home.packages = with pkgs; [ + direnv + jq + nixd + nix-direnv + nixfmt + nixpkgs-fmt + ripgrep + rnix-lsp + tree + ]; + + programs = { + direnv = { + enable = true; + nix-direnv.enable = true; + enableZshIntegration = true; + config = { + global.disable_stdin = true; + global.strict_env = true; + }; + }; + }; +} diff --git a/home/dev.nix b/home/dev.nix new file mode 100644 index 0000000..a860027 --- /dev/null +++ b/home/dev.nix @@ -0,0 +1,47 @@ +{ pkgs, config, ... }: +let + pythonEnv = pkgs.python3.withPackages (p: with p; [ + black + click + isort + pylsp-mypy + requests + types-requests + pip + ipython + virtualenv + ]); +in +{ + programs.go = { + enable = true; + goPath = ".local/share/pkg.go"; + goBin = ".local/bin.go"; + package = pkgs.go_1_20; + }; + + home.packages = with pkgs; [ + go-tools + golangci-lint + gopls + + dive # explore layers in docker images + + pythonEnv + + google-cloud-sdk + + ]; + + home.sessionPath = [ + config.home.sessionVariables.GOBIN + ]; + + home.sessionVariables = with config.xdg; { + IPYTHONDIR = "${cacheHome}/ipython"; + PIP_LOG = "${cacheHome}/pip/pip.log"; + PYLINTHOME = "${cacheHome}/pylint"; + PYTHON_EGG_CACHE = "${cacheHome}/python-eggs"; + MYPY_CACHE_DIR = "${cacheHome}/mypy"; + }; +} diff --git a/home/emacs.nix b/home/emacs.nix new file mode 100644 index 0000000..dbc5411 --- /dev/null +++ b/home/emacs.nix @@ -0,0 +1,12 @@ +{ lib, config, pkgs, ... }: +{ + home.packages = with pkgs; [ + # see https://github.com/hlissner/doom-emacs/issues/4138 + (aspellWithDicts (dicts: with dicts; [ en en-computers en-science ])) + ]; + + home.sessionVariables = { + EDITOR = "emacsclient -a="; + VISUAL = "emacsclient -a="; + }; +} diff --git a/home/git.nix b/home/git.nix new file mode 100644 index 0000000..2c69c64 --- /dev/null +++ b/home/git.nix @@ -0,0 +1,77 @@ +{ lib, pkgs, config, ... }: +let + sshPub = builtins.fromTOML ( + builtins.readFile ../configs/ssh-pubkeys.toml + ); +in +{ + home.file.".ssh/allowed_signers".text = lib.concatMapStrings (x: "franck@fcuny.net ${x}\n") (with sshPub; [ aptos work git ykey-laptop op ]); + + programs.git = { + enable = true; + userName = "Franck Cuny"; + userEmail = "franck@fcuny.net"; + + signing = { + key = "key::${sshPub.op}"; + signByDefault = true; + }; + + aliases = { + amend = "commit --amend"; + ll = "log --pretty=\"format:%h %G? %aN %s\""; + }; + + extraConfig = { + core.whitespace = "trailing-space,space-before-tab"; + color.ui = "true"; + + gpg.format = "ssh"; + gpg.ssh.allowedSignersFile = "~/.ssh/allowed_signers"; + gpg.ssh.program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"; + + # abort if the remote branch does not match the local one + push.default = "simple"; + + init.defaultBranch = "main"; + + pull.rebase = true; + rebase = { + # Automatically create a temporary stash entry before the + # operation begins, and apply it after the operation ends. + autoStash = true; + # Print a warning if some commits are removed + missingCommitsCheck = "warn"; + }; + + branch.autosetuprebase = "remote"; + branch.sort = "authordate"; + + commit.template = "${config.xdg.dataHome}/git/commit.template"; + }; + + ignores = [ + "*~" + ".direnv" + "__pycache__" + ]; + }; + + xdg.dataFile."git/commit.template".source = pkgs.writeText "commit.template" '' + + # (If applied, this commit will...) + + # Explain why this change is being made + + # --- COMMIT END --- + # Remember to + # Use the imperative mood, present tense: `change' not `changed' nor `changes' + # Do not end the subject line with a period + # Use the body to explain what and why vs. how + # Can use multiple lines with "-" for bullet points in body +''; + + home.packages = with pkgs; [ + gitAndTools.pre-commit + ]; +} diff --git a/home/home.nix b/home/home.nix new file mode 100644 index 0000000..42517b9 --- /dev/null +++ b/home/home.nix @@ -0,0 +1,69 @@ +{ config, lib, pkgs, ... }: +{ + imports = [ + ./git.nix + ./ssh.nix + ./zsh.nix + ]; + + home.packages = with pkgs; [ + dive # explore layers in docker images + jq + ripgrep + util-linux + xdg-utils + + age + rage + age-plugin-yubikey + + # tools inside the tools directory + tools.git-blame-stats + tools.git-broom + tools.ipconverter + tools.seqstat + + # tools from external repositories + # x509-info + # gh-ssh-keys + # masked-emails + ]; + + programs.direnv = { + enable = true; + nix-direnv.enable = true; + config = { + global.disable_stdin = true; + global.strict_env = true; + }; + }; + + xdg = { + enable = true; + # File types + mime.enable = true; + # File associatons + mimeApps = { enable = true; }; + # User directories + userDirs = { + enable = true; + createDirectories = true; + desktop = "${config.home.homeDirectory}/documents"; + documents = "${config.home.homeDirectory}/documents"; + download = "${config.home.homeDirectory}/downloads"; + music = "${config.home.homeDirectory}/media/music"; + pictures = "${config.home.homeDirectory}/media/pictures"; + publicShare = "${config.home.homeDirectory}/documents/public"; + templates = "${config.home.homeDirectory}/documents/templates"; + videos = "${config.home.homeDirectory}/media/videos"; + }; + }; + + home.sessionVariables = with config.xdg; { + LESS = "-FRSXM"; + LESSCHARSET = "utf-8"; + LESSHISTFILE = "${dataHome}/less/history"; + LESSKEY = "${configHome}/less/lesskey"; + PAGER = "less"; + }; +} diff --git a/home/profiles/darwin.nix b/home/profiles/darwin.nix deleted file mode 100644 index ef2787d..0000000 --- a/home/profiles/darwin.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ config, pkgs, ... }: -{ - home.stateVersion = "23.05"; - - imports = [ - ./git.nix - ./zsh.nix - ./dev.nix - ./tmux.nix - ./ssh.nix - ]; - - home.packages = with pkgs; [ - direnv - jq - nixd - nix-direnv - nixfmt - nixpkgs-fmt - ripgrep - rnix-lsp - tree - ]; - - programs = { - direnv = { - enable = true; - nix-direnv.enable = true; - enableZshIntegration = true; - config = { - global.disable_stdin = true; - global.strict_env = true; - }; - }; - }; -} diff --git a/home/profiles/dev.nix b/home/profiles/dev.nix deleted file mode 100644 index a860027..0000000 --- a/home/profiles/dev.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ pkgs, config, ... }: -let - pythonEnv = pkgs.python3.withPackages (p: with p; [ - black - click - isort - pylsp-mypy - requests - types-requests - pip - ipython - virtualenv - ]); -in -{ - programs.go = { - enable = true; - goPath = ".local/share/pkg.go"; - goBin = ".local/bin.go"; - package = pkgs.go_1_20; - }; - - home.packages = with pkgs; [ - go-tools - golangci-lint - gopls - - dive # explore layers in docker images - - pythonEnv - - google-cloud-sdk - - ]; - - home.sessionPath = [ - config.home.sessionVariables.GOBIN - ]; - - home.sessionVariables = with config.xdg; { - IPYTHONDIR = "${cacheHome}/ipython"; - PIP_LOG = "${cacheHome}/pip/pip.log"; - PYLINTHOME = "${cacheHome}/pylint"; - PYTHON_EGG_CACHE = "${cacheHome}/python-eggs"; - MYPY_CACHE_DIR = "${cacheHome}/mypy"; - }; -} diff --git a/home/profiles/emacs.nix b/home/profiles/emacs.nix deleted file mode 100644 index dbc5411..0000000 --- a/home/profiles/emacs.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ lib, config, pkgs, ... }: -{ - home.packages = with pkgs; [ - # see https://github.com/hlissner/doom-emacs/issues/4138 - (aspellWithDicts (dicts: with dicts; [ en en-computers en-science ])) - ]; - - home.sessionVariables = { - EDITOR = "emacsclient -a="; - VISUAL = "emacsclient -a="; - }; -} diff --git a/home/profiles/git.nix b/home/profiles/git.nix deleted file mode 100644 index f26b3eb..0000000 --- a/home/profiles/git.nix +++ /dev/null @@ -1,77 +0,0 @@ -{ lib, pkgs, config, ... }: -let - sshPub = builtins.fromTOML ( - builtins.readFile ../../configs/ssh-pubkeys.toml - ); -in -{ - home.file.".ssh/allowed_signers".text = lib.concatMapStrings (x: "franck@fcuny.net ${x}\n") (with sshPub; [ aptos work git ykey-laptop op ]); - - programs.git = { - enable = true; - userName = "Franck Cuny"; - userEmail = "franck@fcuny.net"; - - signing = { - key = "key::${sshPub.op}"; - signByDefault = true; - }; - - aliases = { - amend = "commit --amend"; - ll = "log --pretty=\"format:%h %G? %aN %s\""; - }; - - extraConfig = { - core.whitespace = "trailing-space,space-before-tab"; - color.ui = "true"; - - gpg.format = "ssh"; - gpg.ssh.allowedSignersFile = "~/.ssh/allowed_signers"; - gpg.ssh.program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"; - - # abort if the remote branch does not match the local one - push.default = "simple"; - - init.defaultBranch = "main"; - - pull.rebase = true; - rebase = { - # Automatically create a temporary stash entry before the - # operation begins, and apply it after the operation ends. - autoStash = true; - # Print a warning if some commits are removed - missingCommitsCheck = "warn"; - }; - - branch.autosetuprebase = "remote"; - branch.sort = "authordate"; - - commit.template = "${config.xdg.dataHome}/git/commit.template"; - }; - - ignores = [ - "*~" - ".direnv" - "__pycache__" - ]; - }; - - xdg.dataFile."git/commit.template".source = pkgs.writeText "commit.template" '' - - # (If applied, this commit will...) - - # Explain why this change is being made - - # --- COMMIT END --- - # Remember to - # Use the imperative mood, present tense: `change' not `changed' nor `changes' - # Do not end the subject line with a period - # Use the body to explain what and why vs. how - # Can use multiple lines with "-" for bullet points in body -''; - - home.packages = with pkgs; [ - gitAndTools.pre-commit - ]; -} diff --git a/home/profiles/home.nix b/home/profiles/home.nix deleted file mode 100644 index 42517b9..0000000 --- a/home/profiles/home.nix +++ /dev/null @@ -1,69 +0,0 @@ -{ config, lib, pkgs, ... }: -{ - imports = [ - ./git.nix - ./ssh.nix - ./zsh.nix - ]; - - home.packages = with pkgs; [ - dive # explore layers in docker images - jq - ripgrep - util-linux - xdg-utils - - age - rage - age-plugin-yubikey - - # tools inside the tools directory - tools.git-blame-stats - tools.git-broom - tools.ipconverter - tools.seqstat - - # tools from external repositories - # x509-info - # gh-ssh-keys - # masked-emails - ]; - - programs.direnv = { - enable = true; - nix-direnv.enable = true; - config = { - global.disable_stdin = true; - global.strict_env = true; - }; - }; - - xdg = { - enable = true; - # File types - mime.enable = true; - # File associatons - mimeApps = { enable = true; }; - # User directories - userDirs = { - enable = true; - createDirectories = true; - desktop = "${config.home.homeDirectory}/documents"; - documents = "${config.home.homeDirectory}/documents"; - download = "${config.home.homeDirectory}/downloads"; - music = "${config.home.homeDirectory}/media/music"; - pictures = "${config.home.homeDirectory}/media/pictures"; - publicShare = "${config.home.homeDirectory}/documents/public"; - templates = "${config.home.homeDirectory}/documents/templates"; - videos = "${config.home.homeDirectory}/media/videos"; - }; - }; - - home.sessionVariables = with config.xdg; { - LESS = "-FRSXM"; - LESSCHARSET = "utf-8"; - LESSHISTFILE = "${dataHome}/less/history"; - LESSKEY = "${configHome}/less/lesskey"; - PAGER = "less"; - }; -} diff --git a/home/profiles/ssh.nix b/home/profiles/ssh.nix deleted file mode 100644 index 47aee8a..0000000 --- a/home/profiles/ssh.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ ... }: -{ - programs.ssh = { - enable = true; - forwardAgent = true; - serverAliveInterval = 60; - controlMaster = "auto"; - controlPersist = "30m"; - extraConfig = '' - IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" - ''; - matchBlocks = { - "github.com" = { - hostname = "github.com"; - user = "git"; - forwardAgent = false; - extraOptions = { preferredAuthentications = "publickey"; }; - }; - }; - }; -} diff --git a/home/profiles/tmux.nix b/home/profiles/tmux.nix deleted file mode 100644 index 22f8683..0000000 --- a/home/profiles/tmux.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ ... }: -{ - programs.tmux = { - enable = true; - - terminal = "xterm-256color"; - escapeTime = 0; - aggressiveResize = true; - baseIndex = 1; - shortcut = "z"; - clock24 = true; - historyLimit = 50000; # Bigger buffer - - extraConfig = '' - setw -g mouse on - - set-option -g renumber-windows on - ''; - }; -} diff --git a/home/profiles/yubikey.nix b/home/profiles/yubikey.nix deleted file mode 100644 index b18ce5d..0000000 --- a/home/profiles/yubikey.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ pkgs, lib, config, ... }: -{ - home.packages = with pkgs; [ yubikey-manager yubikey-touch-detector ]; - - systemd.user.sockets.yubikey-touch-detector = { - Unit.Description = "Unix socket activation for YubiKey touch detector service"; - Socket = { - ListenStream = "%t/yubikey-touch-detector.socket"; - RemoveOnStop = true; - }; - Install.WantedBy = [ "sockets.target" ]; - }; - - systemd.user.services.yubikey-touch-detector = { - Unit = { - Description = "Detects when your YubiKey is waiting for a touch"; - Requires = "yubikey-touch-detector.socket"; - }; - Service = { - ExecStart = "${pkgs.yubikey-touch-detector}/bin/yubikey-touch-detector --libnotify"; - EnvironmentFile = "-%E/yubikey-touch-detector/service.conf"; - }; - Install = { - Also = "yubikey-touch-detector.socket"; - WantedBy = [ "default.target" ]; - }; - }; -} diff --git a/home/profiles/zsh.nix b/home/profiles/zsh.nix deleted file mode 100644 index 0cc20eb..0000000 --- a/home/profiles/zsh.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ config, pkgs, lib, ... }: -{ - home.packages = with pkgs; [ zsh-completions ]; - - programs.zsh = { - enable = true; - dotDir = ".config/zsh"; - - defaultKeymap = "emacs"; - enableCompletion = true; - enableAutosuggestions = true; - - history = { - size = 500000; - save = 500000; - extended = true; - ignoreSpace = true; - ignoreDups = true; - share = true; - # see - # https://github.com/nix-community/home-manager/blob/32a7da69dc53c9eb5ad0675eb7fdc58f7fe35272/modules/programs/zsh.nix#L537 - path = "${config.xdg.dataHome}/zsh/zsh_history"; - }; - - localVariables = { - # Print timing statistics for everything which takes longer than - # 5 seconds of user + system time. - REPORTTIME = 5; - }; - - shellAliases = { - ll = "ls -l --color=auto"; - lt = "ls -ltrh --color=auto"; - la = "ls -ltrha --color=auto"; - pkgsearch = "nix search nixpkgs"; - flup = "nix flake update --commit-lock-file"; - }; - - oh-my-zsh = { - enable = true; - plugins = [ "git" ]; - theme = "robbyrussell"; - }; - }; -} diff --git a/home/ssh.nix b/home/ssh.nix new file mode 100644 index 0000000..47aee8a --- /dev/null +++ b/home/ssh.nix @@ -0,0 +1,21 @@ +{ ... }: +{ + programs.ssh = { + enable = true; + forwardAgent = true; + serverAliveInterval = 60; + controlMaster = "auto"; + controlPersist = "30m"; + extraConfig = '' + IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" + ''; + matchBlocks = { + "github.com" = { + hostname = "github.com"; + user = "git"; + forwardAgent = false; + extraOptions = { preferredAuthentications = "publickey"; }; + }; + }; + }; +} diff --git a/home/tmux.nix b/home/tmux.nix new file mode 100644 index 0000000..22f8683 --- /dev/null +++ b/home/tmux.nix @@ -0,0 +1,20 @@ +{ ... }: +{ + programs.tmux = { + enable = true; + + terminal = "xterm-256color"; + escapeTime = 0; + aggressiveResize = true; + baseIndex = 1; + shortcut = "z"; + clock24 = true; + historyLimit = 50000; # Bigger buffer + + extraConfig = '' + setw -g mouse on + + set-option -g renumber-windows on + ''; + }; +} diff --git a/home/yubikey.nix b/home/yubikey.nix new file mode 100644 index 0000000..b18ce5d --- /dev/null +++ b/home/yubikey.nix @@ -0,0 +1,28 @@ +{ pkgs, lib, config, ... }: +{ + home.packages = with pkgs; [ yubikey-manager yubikey-touch-detector ]; + + systemd.user.sockets.yubikey-touch-detector = { + Unit.Description = "Unix socket activation for YubiKey touch detector service"; + Socket = { + ListenStream = "%t/yubikey-touch-detector.socket"; + RemoveOnStop = true; + }; + Install.WantedBy = [ "sockets.target" ]; + }; + + systemd.user.services.yubikey-touch-detector = { + Unit = { + Description = "Detects when your YubiKey is waiting for a touch"; + Requires = "yubikey-touch-detector.socket"; + }; + Service = { + ExecStart = "${pkgs.yubikey-touch-detector}/bin/yubikey-touch-detector --libnotify"; + EnvironmentFile = "-%E/yubikey-touch-detector/service.conf"; + }; + Install = { + Also = "yubikey-touch-detector.socket"; + WantedBy = [ "default.target" ]; + }; + }; +} diff --git a/home/zsh.nix b/home/zsh.nix new file mode 100644 index 0000000..0cc20eb --- /dev/null +++ b/home/zsh.nix @@ -0,0 +1,45 @@ +{ config, pkgs, lib, ... }: +{ + home.packages = with pkgs; [ zsh-completions ]; + + programs.zsh = { + enable = true; + dotDir = ".config/zsh"; + + defaultKeymap = "emacs"; + enableCompletion = true; + enableAutosuggestions = true; + + history = { + size = 500000; + save = 500000; + extended = true; + ignoreSpace = true; + ignoreDups = true; + share = true; + # see + # https://github.com/nix-community/home-manager/blob/32a7da69dc53c9eb5ad0675eb7fdc58f7fe35272/modules/programs/zsh.nix#L537 + path = "${config.xdg.dataHome}/zsh/zsh_history"; + }; + + localVariables = { + # Print timing statistics for everything which takes longer than + # 5 seconds of user + system time. + REPORTTIME = 5; + }; + + shellAliases = { + ll = "ls -l --color=auto"; + lt = "ls -ltrh --color=auto"; + la = "ls -ltrha --color=auto"; + pkgsearch = "nix search nixpkgs"; + flup = "nix flake update --commit-lock-file"; + }; + + oh-my-zsh = { + enable = true; + plugins = [ "git" ]; + theme = "robbyrussell"; + }; + }; +} diff --git a/hosts/mba/default.nix b/hosts/mba/default.nix index 4110f41..3ba0ab6 100644 --- a/hosts/mba/default.nix +++ b/hosts/mba/default.nix @@ -49,5 +49,5 @@ home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.fcuny = import ../../home/profiles/darwin.nix; + home-manager.users.fcuny = import ../../home/darwin.nix; } -- cgit 1.4.1