From edcc3acea595d3045253c3c2fe2462599c1c54e0 Mon Sep 17 00:00:00 2001 From: Linnnus Date: Thu, 7 Sep 2023 16:53:41 +0200 Subject: Reorganize everything --- flake.nix | 12 +++-- home/default.nix | 24 +++++++++ home/git/default.nix | 18 +++++++ home/neovim/default.nix | 27 ++++++++++ home/neovim/filetype.nix | 20 ++++++++ home/neovim/lsp.nix | 106 +++++++++++++++++++++++++++++++++++++++ home/zsh/default.nix | 25 +++++++++ home/zsh/plugins.nix | 69 +++++++++++++++++++++++++ hosts/ahmed/configuration.nix | 9 ---- hosts/ahmed/ssh.nix | 4 +- hosts/common.nix | 34 +++++++++++++ hosts/muhammed/configuration.nix | 7 --- lib/default.nix | 8 +++ lib/secrets.nix | 92 --------------------------------- lib/secrets/default.nix | 90 +++++++++++++++++++++++++++++++++ modules/default.nix | 5 ++ use-cases/cli-basics.nix | 23 --------- use-cases/default.nix | 37 -------------- use-cases/dev-cli-basics.nix | 10 ---- use-cases/git/default.nix | 18 ------- use-cases/neovim/default.nix | 27 ---------- use-cases/neovim/filetype.nix | 20 -------- use-cases/neovim/lsp.nix | 106 --------------------------------------- use-cases/zsh/default.nix | 25 --------- use-cases/zsh/plugins.nix | 69 ------------------------- 25 files changed, 436 insertions(+), 449 deletions(-) create mode 100644 home/default.nix create mode 100644 home/git/default.nix create mode 100644 home/neovim/default.nix create mode 100644 home/neovim/filetype.nix create mode 100644 home/neovim/lsp.nix create mode 100644 home/zsh/default.nix create mode 100644 home/zsh/plugins.nix create mode 100644 hosts/common.nix create mode 100644 lib/default.nix delete mode 100644 lib/secrets.nix create mode 100644 lib/secrets/default.nix create mode 100644 modules/default.nix delete mode 100644 use-cases/cli-basics.nix delete mode 100644 use-cases/default.nix delete mode 100644 use-cases/dev-cli-basics.nix delete mode 100644 use-cases/git/default.nix delete mode 100644 use-cases/neovim/default.nix delete mode 100644 use-cases/neovim/filetype.nix delete mode 100644 use-cases/neovim/lsp.nix delete mode 100644 use-cases/zsh/default.nix delete mode 100644 use-cases/zsh/plugins.nix diff --git a/flake.nix b/flake.nix index 4cfe155..0ec1e03 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ let args = { flakeInputs = inputs; - misc.metadata = nixpkgs.lib.importTOML ./metadata.toml; + metadata = nixpkgs.lib.importTOML ./metadata.toml; }; in { @@ -29,8 +29,9 @@ { _module.args = args; } home-manager.darwinModules.home-manager ./hosts/muhammed/configuration.nix - ./use-cases/default.nix - ./services/default.nix + ./hosts/common.nix + ./home + ./lib ]; }; }; @@ -42,7 +43,10 @@ { _module.args = args; } home-manager.nixosModules.home-manager ./hosts/ahmed/configuration.nix - ./use-cases/default.nix + ./hosts/common.nix + ./home + ./lib + ./modules/default.nix ./services/default.nix ]; }; diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..f0aa53b --- /dev/null +++ b/home/default.nix @@ -0,0 +1,24 @@ +{ flakeInputs, metadata, ... }: + +{ + # Use the flake input pkgs so Home Manager configuration can share overlays + # etc. with the rest of the configuration. + home-manager.useGlobalPkgs = true; + + # Pass special arguments from flake.nix further down the chain. I really hate + # this split module system. + home-manager.extraSpecialArgs = { inherit flakeInputs metadata; }; + + # OKAY FUCK THIS SHIT. THERE IS ONE USER. IT IS ME. LINUS. I WILL ADD + # MULTIUSER SUPPORT IF IT EVER BECOMES A REQUIREMENT. + home-manager.users.linus = { + imports = + [ + ./neovim + ./zsh + ./git + ]; + + xdg.enable = true; + }; +} diff --git a/home/git/default.nix b/home/git/default.nix new file mode 100644 index 0000000..8df44db --- /dev/null +++ b/home/git/default.nix @@ -0,0 +1,18 @@ +{ ... }: + +{ + programs.git = { + enable = true; + + # Set privacy-respecting user information. + userName = "Linnnus"; + userEmail = "linnnus@users.noreply.github.com"; + }; + + home.shellAliases = { + gs = "git status"; + gd = "git diff"; + gc = "git commit"; + gap = "git add --patch"; + }; +} diff --git a/home/neovim/default.nix b/home/neovim/default.nix new file mode 100644 index 0000000..883c170 --- /dev/null +++ b/home/neovim/default.nix @@ -0,0 +1,27 @@ +# This file contains the HM configuration options for Neovim. + +{ pkgs, lib, ... }: + +{ + imports = + [ + ./lsp.nix + ./filetype.nix + ]; + + programs.neovim = { + enable = true; + + # Typing `vi`, `vim`, or `vimdiff` will also run neovim. + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + }; + + # Set Neovim as the default editor. + home.sessionVariables.EDITOR = "nvim"; + home.sessionVariables.VISUAL = "nvim"; + + # Use neovim as man pager. + home.sessionVariables.MANPAGER = "nvim +Man!"; +} diff --git a/home/neovim/filetype.nix b/home/neovim/filetype.nix new file mode 100644 index 0000000..66d5e68 --- /dev/null +++ b/home/neovim/filetype.nix @@ -0,0 +1,20 @@ +# This module configures various syntax/filetype plugins for Neovim. + +{ pkgs, ... }: + +let + vim-noweb = pkgs.vimUtils.buildVimPlugin { + pname = "vim-noweb"; + version = "26-08-2023"; # day of retrieval + src = pkgs.fetchzip { + url = "https://metaed.com/papers/vim-noweb/vim-noweb.tgz"; + hash = "sha256-c5eUZiKIjAfjJ33l821h5DjozMpMf0CaK03QIkSUfxg="; + }; + }; +in +{ + programs.neovim.plugins = with pkgs.vimPlugins; [ + vim-nix + vim-noweb + ]; +} diff --git a/home/neovim/lsp.nix b/home/neovim/lsp.nix new file mode 100644 index 0000000..588fb8b --- /dev/null +++ b/home/neovim/lsp.nix @@ -0,0 +1,106 @@ +# This module sets up LSP server configurations for Neovim. It is waaay +# overcomplicated as it kind of turned into an experiment in generating Lua +# code from a Nix attrset. + +{ pkgs, lib, ... }: + +{ + programs.neovim.plugins = [ + { + plugin = pkgs.vimPlugins.nvim-lspconfig; + type = "lua"; + config = '' + local lspconfig = require("lspconfig") + local util = require("lspconfig.util") + + -- Mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + local opts = { noremap=true, silent=true } + vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + + -- Use an on_attach function to only map the following keys + -- after the language server attaches to the current buffer + local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + vim.keymap.set('n', 's', function() vim.cmd[[ClangdSwitchSourceHeader]] end, bufopts) + end + + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + local servers = { + pyright = { cmd = { "${pkgs.pyright}/bin/pyright-langserver" } }, + rnix = { cmd = { "${pkgs.rnix-lsp}/bin/rnix-lsp" } }, + denols = { + init_options = { + enable = true, + unstable = true, + lint = true, + }, + cmd = { "${pkgs.deno}/bin/deno", "lsp", "--unstable" }, + root_dir = function(startpath) + if util.find_package_json_ancestor(startpath) then + -- This is a Node project; let tsserver handle this one. + return nil + else + -- Otherwise, we try to find the root or + -- default to the current directory. + return util.root_pattern("deno.json", "deno.jsonc", ".git")(startpath) + or util.path.dirname(startpath) + end + end, + }, + }; + for server, config in pairs(servers) do + # set common options + config.on_attach = on_attach; + config.debounce_text_changes = 150; + + lspconfig[server].setup(config) + end + ''; + } + ]; +} + +# I spent like an hour writing this, only to find it was a pretty bad idea. +# +# nixToLua = s: +# if builtins.isAttrs s then +# let +# renderAttr = name: value: "[ [==========[" + name + "]==========] ] = " + (nixToLua value); +# attrsList = map (name: renderAttr name s.${name}) (lib.attrNames s); +# attrsListStr = lib.concatStringsSep ", " attrsList; +# in +# "{ ${attrsListStr} }" +# else if builtins.isList s then +# "{ " + (lib.concatStringsSep ", " (map nixToLua s)) + " }" +# else if builtins.isString s then +# # Oh boy I sure hope `s` doesn't contain "]==========]". +# "[==========[" + s + "]==========]" +# else if builtins.isInt s || builtins.isFloat s then +# toString s +# else +# throw "Cannot convert ${builtins.typeOf s} to Lua value!"; diff --git a/home/zsh/default.nix b/home/zsh/default.nix new file mode 100644 index 0000000..1b8ce16 --- /dev/null +++ b/home/zsh/default.nix @@ -0,0 +1,25 @@ +{ pkgs, config, lib, ... }: + +{ + imports = + [ + ./plugins.nix + ]; + + programs.zsh = { + enable = true; + + defaultKeymap = "viins"; + + # Feeble attempt at cleaning up home directory. + # TODO: dotDir = (pathRelativeTo config.xdg.configHome config.home) + "/zsh"; + dotDir = ".config/zsh"; + history.path = config.xdg.cacheHome + "/zsh/history"; + + }; + + programs.fzf = { + enable = true; + enableZshIntegration = true; + }; +} diff --git a/home/zsh/plugins.nix b/home/zsh/plugins.nix new file mode 100644 index 0000000..3bebfce --- /dev/null +++ b/home/zsh/plugins.nix @@ -0,0 +1,69 @@ +{ pkgs, lib, config, ... }: + +let + inherit (lib.strings) concatStringsSep; + inherit (lib.attrsets) catAttrs; + + plugins = + [ + { + name = "autovenv"; + src = pkgs.fetchFromGitHub { + owner = "linnnus"; + repo = "autovenv"; + rev = "d9f0cd7"; + hash = "sha256-GfJIybMYxE97xLSkrOSGsn+AREmnCyqe9n2aZwjw4w4="; + }; + } + { + name = "zsh-cwd-history"; + src = pkgs.stdenvNoCC.mkDerivation rec { + pname = "zsh-cwd-history"; + version = "73afed8"; + + src = pkgs.fetchFromGitHub { + owner = "ericfreese"; + repo = pname; + rev = version; + hash = "sha256-xW11wPFDuFU80AzgAgLwkvK7Qv58fo3i3kSasE3p0zs="; + }; + + fixupPhase = '' + substituteInPlace ${pname}.zsh \ + --replace md5 ${pkgs.outils}/bin/md5 + + mkdir -p $out + mv * $out + ''; + + # This is kind of a weird, useless derivation, so we have to + # manually avoid doing lots of the usual stuff. + dontInstall = true; + }; + config = '' + # Where to but history files + export ZSH_CWD_HISTORY_DIR=${config.xdg.dataHome}/zsh-cwd-history + mkdir -p "$ZSH_CWD_HISTORY_DIR" + + # Toggle between global/local history + bindkey '^G' cwd-history-toggle + ''; + } + { + name = "zsh-vi-mode-cursor"; + src = pkgs.fetchFromGitHub { + owner = "Buckmeister"; + repo = "zsh-vi-mode-cursor"; + rev = "fa7cc0973ee71636e906e25e782d0aea19545d60"; + hash = "sha256-j73M4bvAoHWt5Wwg47hM0p5Or74x/3btTOPnI22SqG8="; + }; + } + ]; +in +{ + programs.zsh = { + plugins = map (p: removeAttrs p ["config"]) plugins; + + initExtra = concatStringsSep "\n" (catAttrs "config" plugins); + }; +} diff --git a/hosts/ahmed/configuration.nix b/hosts/ahmed/configuration.nix index 95561bd..2dbf4e1 100644 --- a/hosts/ahmed/configuration.nix +++ b/hosts/ahmed/configuration.nix @@ -15,14 +15,7 @@ isNormalUser = true; hashedPassword = "$y$j9T$kNJ5L50Si0sAhdrHyO19I1$YcwXZ46dI.ApLMgZSj7qImq9FrSL0CEUeoJUS8P1103"; extraGroups = [ "wheel" ]; - shell = pkgs.zsh; }; - # Following are recommended when changing the default shell. - # https://nixos.wiki/wiki/Command_Shell#Changing_default_shelltrue; - programs.zsh.enable = true; - environment.shells = [ pkgs.zsh ]; - - my.use-cases = [ "development" "sysadmin" ]; # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; @@ -57,8 +50,6 @@ networking.wireless.enable = true; networking.wireless.networks."Rumpenettet_Guest".psk = "Rumpenerglad"; # NOCOMMIT - nix.settings.experimental-features = [ "nix-command" ]; - # Set up Minecraft server. my.services.on-demand-minecraft = { enable = true; diff --git a/hosts/ahmed/ssh.nix b/hosts/ahmed/ssh.nix index 9e34d99..f737437 100644 --- a/hosts/ahmed/ssh.nix +++ b/hosts/ahmed/ssh.nix @@ -1,6 +1,6 @@ # This file configures openSSH on this host. -{ config, pkgs, lib, misc, ... }: +{ lib, metadata, ... }: { # Who is allowed/expected to connect to this machine? @@ -13,7 +13,7 @@ users.users = lib.genAttrs ["root" "linus"] (_: { openssh.authorizedKeys.keys = [ - misc.metadata.hosts.muhammed.sshPubKey + metadata.hosts.muhammed.sshPubKey ]; }); } diff --git a/hosts/common.nix b/hosts/common.nix new file mode 100644 index 0000000..87c6b27 --- /dev/null +++ b/hosts/common.nix @@ -0,0 +1,34 @@ +# Shared configuraion regardless of hosts. + +{ pkgs, ... }: + +{ + # Enable de facto stable features. + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + # Set ZSH as the shell. + # https://nixos.wiki/wiki/Command_Shell#Changing_default_shelltrue + programs.zsh.enable = true; + environment.shells = [ pkgs.zsh ]; + users.users.linus.shell = pkgs.zsh; + + # Very basic system administration tools. + environment.systemPackages = with pkgs; [ + tree + jc + jq + vim + comma + curl + ]; + + # Aliases that are burned into my muscle memory. + environment.shellAliases = { + "mv" = "mv -i"; + "rm" = "rm -i"; + "cp" = "cp -i"; + "ls" = "ls -A --color=auto"; + "grep" = "grep --color=auto"; + "file" = "file --no-dereference"; + }; +} diff --git a/hosts/muhammed/configuration.nix b/hosts/muhammed/configuration.nix index 0e41669..c824eb3 100644 --- a/hosts/muhammed/configuration.nix +++ b/hosts/muhammed/configuration.nix @@ -13,14 +13,7 @@ users.users.linus = { description = "Personal user account"; home = "/Users/linus"; - shell = pkgs.zsh; }; - # Following are recommended when changing the default shell. - # https://nixos.wiki/wiki/Command_Shell#Changing_default_shelltrue; - programs.zsh.enable = true; # TODO: move to common module - environment.shells = [ pkgs.zsh ]; - - my.use-cases = [ "gui" "development" ]; # Should match containing folder. networking.hostName = "muhammed"; diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..d896ce2 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = + [ + ./secrets + ]; +} diff --git a/lib/secrets.nix b/lib/secrets.nix deleted file mode 100644 index 401d4a5..0000000 --- a/lib/secrets.nix +++ /dev/null @@ -1,92 +0,0 @@ -{ pkgs, config, lib, ... }: - -with lib; - -let - cfg = config.my.secrets; - - secret = types.submodule { - options = { - source = mkOption { - type = types.path; - description = "local secret path"; - }; - - dest = mkOption { - type = types.str; - description = "where to write the decrypted secret to"; - }; - - owner = mkOption { - default = "root"; - type = types.str; - description = "who should own the secret"; - }; - - group = mkOption { - default = "root"; - type = types.str; - description = "what group should own the secret"; - }; - - permissions = mkOption { - default = "0400"; - type = types.str; - description = "Permissions expressed as octal."; - }; - }; - }; - - metadata = lib.importTOML ./metadata.toml; - - mkSecretOnDisk = name: - { source, ... }: - pkgs.stdenv.mkDerivation { - name = "${name}-secret"; - phases = "installPhase"; - buildInputs = [ pkgs.rage ]; - installPhase = - let - key = metadata.hosts."${config.networking.hostName}".sshPubKey; - in - '' - rage -a -r '${key}' -o "$out" '${source}' - ''; - }; - - mkService = name: - { source, dest, owner, group, permissions, ... }: { - description = "decrypt secret for ${name}"; - wantedBy = [ "multi-user.target" ]; - - serviceConfig.Type = "oneshot"; - - script = with pkgs; '' - rm -rf ${dest} - "${rage}"/bin/rage -d -i /etc/ssh/ssh_host_ed25519_key -o '${dest}' '${ - mkSecretOnDisk name { inherit source; } - }' - - chown '${owner}':'${group}' '${dest}' - chmod '${permissions}' '${dest}' - ''; - }; -in -{ - options.my.secrets = mkOption { - type = types.attrsOf secret; - description = "secret configuration"; - default = { }; - }; - - config.systemd.services = - let - units = mapAttrs' - (name: info: { - name = "${name}-key"; - value = (mkService name info); - }) - cfg; - in - units; -} diff --git a/lib/secrets/default.nix b/lib/secrets/default.nix new file mode 100644 index 0000000..9592052 --- /dev/null +++ b/lib/secrets/default.nix @@ -0,0 +1,90 @@ +{ pkgs, config, lib, metadata, ... }: + +with lib; + +let + cfg = config.my.secrets; + + secret = types.submodule { + options = { + source = mkOption { + type = types.path; + description = "local secret path"; + }; + + dest = mkOption { + type = types.str; + description = "where to write the decrypted secret to"; + }; + + owner = mkOption { + default = "root"; + type = types.str; + description = "who should own the secret"; + }; + + group = mkOption { + default = "root"; + type = types.str; + description = "what group should own the secret"; + }; + + permissions = mkOption { + default = "0400"; + type = types.str; + description = "Permissions expressed as octal."; + }; + }; + }; + + mkSecretOnDisk = name: + { source, ... }: + pkgs.stdenv.mkDerivation { + name = "${name}-secret"; + phases = "installPhase"; + buildInputs = [ pkgs.rage ]; + installPhase = + let + key = metadata.hosts."${config.networking.hostName}".sshPubKey; + in + '' + rage -a -r '${key}' -o "$out" '${source}' + ''; + }; + + mkService = name: + { source, dest, owner, group, permissions, ... }: { + description = "decrypt secret for ${name}"; + wantedBy = [ "multi-user.target" ]; + + serviceConfig.Type = "oneshot"; + + script = with pkgs; '' + rm -rf ${dest} + "${rage}"/bin/rage -d -i /etc/ssh/ssh_host_ed25519_key -o '${dest}' '${ + mkSecretOnDisk name { inherit source; } + }' + + chown '${owner}':'${group}' '${dest}' + chmod '${permissions}' '${dest}' + ''; + }; +in +{ + options.my.secrets = mkOption { + type = types.attrsOf secret; + description = "secret configuration"; + default = { }; + }; + + config.systemd.services = + let + units = mapAttrs' + (name: info: { + name = "${name}-key"; + value = (mkService name info); + }) + cfg; + in + units; +} diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..f6094ba --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,5 @@ +{ ... }: + +{ + # Empty for now +} diff --git a/use-cases/cli-basics.nix b/use-cases/cli-basics.nix deleted file mode 100644 index 17e29c7..0000000 --- a/use-cases/cli-basics.nix +++ /dev/null @@ -1,23 +0,0 @@ -# This module defines Home Manager configuration options for the 'sysadmin' use -# case. That is, basic system administration. - -{ pkgs, super, lib, ... }: - -{ - home.packages = with pkgs; [ - tree - jc - jq - vim - comma - ]; - - # basic qol shell aliases - home.shellAliases = { - "mv" = "mv -i"; - "rm" = "rm -i"; - "cp" = "cp -i"; - "ls" = "ls -A --color=auto"; - "grep" = "grep --color=auto"; - }; -} diff --git a/use-cases/default.nix b/use-cases/default.nix deleted file mode 100644 index e7a317a..0000000 --- a/use-cases/default.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ config, pkgs, lib, flakeInputs, misc, ... }: - -let - inherit (lib) mkOption types optional elem; - - hasUseCase = c: elem c config.my.use-cases; - development = hasUseCase "development"; - sysadmin = hasUseCase "sysadmin"; - gui = hasUseCase "gui"; -in -{ - options.my.use-cases = mkOption { - description = "use-cases/modules to enable"; - type = types.listOf (types.enum ["gui" "development" "sysadmin"]); - }; - - config = { - home-manager.users.linus = { - imports = (optional development ./neovim) - ++ (optional development ./git) - ++ (optional development ./dev-cli-basics.nix) - #++ (optional (development && gui && pkgs.stdenv.isDarwin) ./iterm2) - #++ (optional (development && gui && pkgs.stdenv.isDarwin) ./st) - ++ (optional (development || sysadmin) ./zsh) - ++ (optional (development || sysadmin) ./cli-basics.nix); - - xdg.enable = true; - }; - - home-manager.extraSpecialArgs = { - super = config; - inherit flakeInputs misc; - }; - - home-manager.useGlobalPkgs = true; - }; -} diff --git a/use-cases/dev-cli-basics.nix b/use-cases/dev-cli-basics.nix deleted file mode 100644 index fae49cd..0000000 --- a/use-cases/dev-cli-basics.nix +++ /dev/null @@ -1,10 +0,0 @@ -# This file specifies a home-manager config for basic development CLI -# applications like interpreters and such. - -{ pkgs, ... }: - -{ - home.packages = with pkgs; [ - deno - ]; -} diff --git a/use-cases/git/default.nix b/use-cases/git/default.nix deleted file mode 100644 index 8df44db..0000000 --- a/use-cases/git/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ ... }: - -{ - programs.git = { - enable = true; - - # Set privacy-respecting user information. - userName = "Linnnus"; - userEmail = "linnnus@users.noreply.github.com"; - }; - - home.shellAliases = { - gs = "git status"; - gd = "git diff"; - gc = "git commit"; - gap = "git add --patch"; - }; -} diff --git a/use-cases/neovim/default.nix b/use-cases/neovim/default.nix deleted file mode 100644 index 883c170..0000000 --- a/use-cases/neovim/default.nix +++ /dev/null @@ -1,27 +0,0 @@ -# This file contains the HM configuration options for Neovim. - -{ pkgs, lib, ... }: - -{ - imports = - [ - ./lsp.nix - ./filetype.nix - ]; - - programs.neovim = { - enable = true; - - # Typing `vi`, `vim`, or `vimdiff` will also run neovim. - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - }; - - # Set Neovim as the default editor. - home.sessionVariables.EDITOR = "nvim"; - home.sessionVariables.VISUAL = "nvim"; - - # Use neovim as man pager. - home.sessionVariables.MANPAGER = "nvim +Man!"; -} diff --git a/use-cases/neovim/filetype.nix b/use-cases/neovim/filetype.nix deleted file mode 100644 index 66d5e68..0000000 --- a/use-cases/neovim/filetype.nix +++ /dev/null @@ -1,20 +0,0 @@ -# This module configures various syntax/filetype plugins for Neovim. - -{ pkgs, ... }: - -let - vim-noweb = pkgs.vimUtils.buildVimPlugin { - pname = "vim-noweb"; - version = "26-08-2023"; # day of retrieval - src = pkgs.fetchzip { - url = "https://metaed.com/papers/vim-noweb/vim-noweb.tgz"; - hash = "sha256-c5eUZiKIjAfjJ33l821h5DjozMpMf0CaK03QIkSUfxg="; - }; - }; -in -{ - programs.neovim.plugins = with pkgs.vimPlugins; [ - vim-nix - vim-noweb - ]; -} diff --git a/use-cases/neovim/lsp.nix b/use-cases/neovim/lsp.nix deleted file mode 100644 index 588fb8b..0000000 --- a/use-cases/neovim/lsp.nix +++ /dev/null @@ -1,106 +0,0 @@ -# This module sets up LSP server configurations for Neovim. It is waaay -# overcomplicated as it kind of turned into an experiment in generating Lua -# code from a Nix attrset. - -{ pkgs, lib, ... }: - -{ - programs.neovim.plugins = [ - { - plugin = pkgs.vimPlugins.nvim-lspconfig; - type = "lua"; - config = '' - local lspconfig = require("lspconfig") - local util = require("lspconfig.util") - - -- Mappings. - -- See `:help vim.diagnostic.*` for documentation on any of the below functions - local opts = { noremap=true, silent=true } - vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) - vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) - vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) - vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) - - -- Use an on_attach function to only map the following keys - -- after the language server attaches to the current buffer - local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap=true, silent=true, buffer=bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) - vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) - vim.keymap.set('n', 's', function() vim.cmd[[ClangdSwitchSourceHeader]] end, bufopts) - end - - -- Use a loop to conveniently call 'setup' on multiple servers and - -- map buffer local keybindings when the language server attaches - local servers = { - pyright = { cmd = { "${pkgs.pyright}/bin/pyright-langserver" } }, - rnix = { cmd = { "${pkgs.rnix-lsp}/bin/rnix-lsp" } }, - denols = { - init_options = { - enable = true, - unstable = true, - lint = true, - }, - cmd = { "${pkgs.deno}/bin/deno", "lsp", "--unstable" }, - root_dir = function(startpath) - if util.find_package_json_ancestor(startpath) then - -- This is a Node project; let tsserver handle this one. - return nil - else - -- Otherwise, we try to find the root or - -- default to the current directory. - return util.root_pattern("deno.json", "deno.jsonc", ".git")(startpath) - or util.path.dirname(startpath) - end - end, - }, - }; - for server, config in pairs(servers) do - # set common options - config.on_attach = on_attach; - config.debounce_text_changes = 150; - - lspconfig[server].setup(config) - end - ''; - } - ]; -} - -# I spent like an hour writing this, only to find it was a pretty bad idea. -# -# nixToLua = s: -# if builtins.isAttrs s then -# let -# renderAttr = name: value: "[ [==========[" + name + "]==========] ] = " + (nixToLua value); -# attrsList = map (name: renderAttr name s.${name}) (lib.attrNames s); -# attrsListStr = lib.concatStringsSep ", " attrsList; -# in -# "{ ${attrsListStr} }" -# else if builtins.isList s then -# "{ " + (lib.concatStringsSep ", " (map nixToLua s)) + " }" -# else if builtins.isString s then -# # Oh boy I sure hope `s` doesn't contain "]==========]". -# "[==========[" + s + "]==========]" -# else if builtins.isInt s || builtins.isFloat s then -# toString s -# else -# throw "Cannot convert ${builtins.typeOf s} to Lua value!"; diff --git a/use-cases/zsh/default.nix b/use-cases/zsh/default.nix deleted file mode 100644 index 1b8ce16..0000000 --- a/use-cases/zsh/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ pkgs, config, lib, ... }: - -{ - imports = - [ - ./plugins.nix - ]; - - programs.zsh = { - enable = true; - - defaultKeymap = "viins"; - - # Feeble attempt at cleaning up home directory. - # TODO: dotDir = (pathRelativeTo config.xdg.configHome config.home) + "/zsh"; - dotDir = ".config/zsh"; - history.path = config.xdg.cacheHome + "/zsh/history"; - - }; - - programs.fzf = { - enable = true; - enableZshIntegration = true; - }; -} diff --git a/use-cases/zsh/plugins.nix b/use-cases/zsh/plugins.nix deleted file mode 100644 index 3bebfce..0000000 --- a/use-cases/zsh/plugins.nix +++ /dev/null @@ -1,69 +0,0 @@ -{ pkgs, lib, config, ... }: - -let - inherit (lib.strings) concatStringsSep; - inherit (lib.attrsets) catAttrs; - - plugins = - [ - { - name = "autovenv"; - src = pkgs.fetchFromGitHub { - owner = "linnnus"; - repo = "autovenv"; - rev = "d9f0cd7"; - hash = "sha256-GfJIybMYxE97xLSkrOSGsn+AREmnCyqe9n2aZwjw4w4="; - }; - } - { - name = "zsh-cwd-history"; - src = pkgs.stdenvNoCC.mkDerivation rec { - pname = "zsh-cwd-history"; - version = "73afed8"; - - src = pkgs.fetchFromGitHub { - owner = "ericfreese"; - repo = pname; - rev = version; - hash = "sha256-xW11wPFDuFU80AzgAgLwkvK7Qv58fo3i3kSasE3p0zs="; - }; - - fixupPhase = '' - substituteInPlace ${pname}.zsh \ - --replace md5 ${pkgs.outils}/bin/md5 - - mkdir -p $out - mv * $out - ''; - - # This is kind of a weird, useless derivation, so we have to - # manually avoid doing lots of the usual stuff. - dontInstall = true; - }; - config = '' - # Where to but history files - export ZSH_CWD_HISTORY_DIR=${config.xdg.dataHome}/zsh-cwd-history - mkdir -p "$ZSH_CWD_HISTORY_DIR" - - # Toggle between global/local history - bindkey '^G' cwd-history-toggle - ''; - } - { - name = "zsh-vi-mode-cursor"; - src = pkgs.fetchFromGitHub { - owner = "Buckmeister"; - repo = "zsh-vi-mode-cursor"; - rev = "fa7cc0973ee71636e906e25e782d0aea19545d60"; - hash = "sha256-j73M4bvAoHWt5Wwg47hM0p5Or74x/3btTOPnI22SqG8="; - }; - } - ]; -in -{ - programs.zsh = { - plugins = map (p: removeAttrs p ["config"]) plugins; - - initExtra = concatStringsSep "\n" (catAttrs "config" plugins); - }; -} -- cgit v1.2.3