diff --git a/common/default.nix b/common/default.nix index cc9e7ed..fadb249 100644 --- a/common/default.nix +++ b/common/default.nix @@ -1,4 +1,16 @@ { lib, inputs, pkgs, ... }: { + imports = [ + inputs.home-manager.nixosModules.home-manager + ./users + ]; + + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = { inherit inputs; }; + sharedModules = [ ./hm-modules inputs.nixvim.homeManagerModules.nixvim ]; + }; + virtualisation.oci-containers.backend = lib.mkDefault "podman"; # Set your time zone. diff --git a/common/hm-modules/catppuccin.nix b/common/hm-modules/catppuccin.nix new file mode 100644 index 0000000..68c7191 --- /dev/null +++ b/common/hm-modules/catppuccin.nix @@ -0,0 +1,40 @@ +{ config, pkgs, lib, ... }: +with lib; +let cfg = config.themes.v.catppuccin; +in { + options.themes.v.catppuccin = { enable = mkEnableOption "catppuccin"; }; + config = + let + theme = "Catppuccin-Pink-Dark"; + cursorTheme = config.home.pointerCursor.name; + in + mkIf cfg.enable { + home.pointerCursor = { + name = "Bibata_Ghost"; + size = 24; + package = pkgs.bibata-cursors-translucent; + }; + + gtk = { + enable = true; + theme = { + name = theme; + package = pkgs.catppuccin-gtk; + }; + iconTheme = { + name = "Papirus-Dark"; + package = pkgs.papirus-icon-theme.override { color = "violet"; }; + }; + cursorTheme = { + name = cursorTheme; + inherit (config.home.pointerCursor) package size; + }; + }; + + programs.vscode = { + userSettings."workbench.colorTheme" = "Catppuccin Frappé"; + extensions = [ pkgs.vscode-extensions.catppuccin.catppuccin-vsc ]; + }; + }; +} + diff --git a/common/hm-modules/default.nix b/common/hm-modules/default.nix new file mode 100644 index 0000000..2dbbe8f --- /dev/null +++ b/common/hm-modules/default.nix @@ -0,0 +1,3 @@ +{ ... }: { + imports = [ ./catppuccin.nix ./nvim.nix ./riff.nix ./vscode.nix ./git.nix ./rust.nix ]; +} diff --git a/common/hm-modules/git.nix b/common/hm-modules/git.nix new file mode 100644 index 0000000..febbd3b --- /dev/null +++ b/common/hm-modules/git.nix @@ -0,0 +1,31 @@ +{ config, pkgs, lib, ... }: +with lib; +let cfg = config.programs.v.git; +in { + options.programs.v.git = { enable = mkEnableOption "git"; }; + config = mkIf cfg.enable { + programs.git = { + enable = true; + package = pkgs.gitAndTools.gitFull; + userName = "Vivian"; + userEmail = "vivian@0x76.dev"; + lfs.enable = true; + extraConfig = { + push.autoSetupRemote = true; + init.defaultBranch = "main"; + # Git merge driver that always grabs upstream changes + # Useful for e.g. lock files + merge.ours = { + name = "Overwrite Upstream Changes"; + driver = "cp -f '%A' '%B'"; + }; + }; + + difftastic.enable = true; + }; + + home.file.".config/git/attributes".text = '' + flake.lock merge=ours + ''; + }; +} diff --git a/common/hm-modules/nvim.nix b/common/hm-modules/nvim.nix new file mode 100644 index 0000000..7172324 --- /dev/null +++ b/common/hm-modules/nvim.nix @@ -0,0 +1,190 @@ +{ config, pkgs, lib, ... }: +let cfg = config.programs.v.nvim; +in with lib; { + options.programs.v.nvim = { enable = mkEnableOption "nvim"; }; + config = mkIf cfg.enable { + programs.nixvim = { + enable = true; + package = pkgs.neovim-unwrapped; + vimAlias = true; + luaLoader.enable = true; + + globals.mapleader = " "; + + options.number = true; + + clipboard = { providers.wl-copy.enable = true; }; + + keymaps = [ + { + mode = "n"; + key = "ff"; + action = "require('telescope.builtin').find_files"; + lua = true; + } + { + mode = "n"; + key = "fg"; + action = "require('telescope.builtin').live_grep"; + lua = true; + } + { + mode = "n"; + key = ""; + action = "require('Comment.api').toggle.linewise.current"; + lua = true; + } + { + mode = "x"; + key = ""; + action = '' + function() + local esc = vim.api.nvim_replace_termcodes( + '', true, false, true + ) + vim.api.nvim_feedkeys(esc, 'nx', false) + require('Comment.api').toggle.linewise(vim.fn.visualmode()) + end + ''; + lua = true; + } + { + mode = "n"; + key = "g="; + action = "vim.lsp.buf.format"; + lua = true; + } + { + mode = "n"; + key = "t"; + action = ":FloatermToggle myfloat"; + } + { + mode = "t"; + key = ""; + action = "function() vim.cmd(':FloatermToggle myfloat') end"; + lua = true; + } + ]; + + extraPlugins = with pkgs.vimPlugins; [ + FixCursorHold-nvim + luasnip + plenary-nvim + neotest + neotest-plenary + neotest-rust + ]; + + colorschemes.catppuccin = { + enable = true; + flavour = "frappe"; + }; + + extraConfigLua = '' + require("neotest").setup({ + adapters = { + require("neotest-plenary"), + require("neotest-rust") { + args = { "--no-capture" }, + } + }, + }) + ''; + + plugins = { + bufferline.enable = true; + none-ls = { + enable = true; + sources = { + formatting.nixpkgs_fmt.enable = true; + code_actions.shellcheck.enable = true; + code_actions.statix.enable = true; + diagnostics = { + statix.enable = true; + deadnix.enable = true; + shellcheck.enable = true; + }; + }; + }; + nix.enable = true; + treesitter = { + enable = true; + nixGrammars = true; + disabledLanguages = [ "latex" ]; + }; + surround.enable = true; + fugitive.enable = true; + gitgutter.enable = true; + lualine = { + enable = true; + theme = "catppuccin"; + }; + telescope = { + enable = true; + extensions.fzf-native.enable = true; + extensions.fzf-native.fuzzy = true; + }; + comment-nvim = { enable = true; }; + lsp = { + enable = true; + servers = { + nil_ls.enable = true; + rust-analyzer = { + installCargo = false; + installRustc = false; + }; + pyright.enable = true; + elixirls.enable = true; + clangd.enable = true; + yamlls.enable = true; + }; + }; + trouble.enable = true; + lspkind.enable = true; + + vimtex.enable = true; + + floaterm.enable = true; + + nvim-cmp = { + enable = true; + autoEnableSources = true; + sources = [ + { name = "nvim_lsp"; } + { + name = "luasnip"; + option = { show_autosnippets = true; }; + } + { name = "cmp-spell"; } + { name = "cmp-rg"; } + { name = "path"; } + { name = "buffer"; } + ]; + snippet.expand = "luasnip"; + mappingPresets = [ "insert" "cmdline" ]; + mapping = { + "" = "cmp.mapping.confirm({ select = true })"; + "" = { + modes = [ "i" "s" ]; + action = '' + function(fallback) + local luasnip = require('luasnip') + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end + ''; + }; + }; + }; + }; + }; + }; +} diff --git a/common/hm-modules/riff.nix b/common/hm-modules/riff.nix new file mode 100644 index 0000000..509a782 --- /dev/null +++ b/common/hm-modules/riff.nix @@ -0,0 +1,28 @@ +{ config, pkgs, lib, inputs, ... }: +with lib; +let cfg = config.programs.riff; +in { + options.programs.riff = { + enable = mkEnableOption "riff"; + direnv = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable direnv support + ''; + }; + }; + config = mkIf cfg.enable { + home.packages = [ inputs.riff.packages.${pkgs.system}.riff ]; + + xdg.configFile."direnv/lib/riff.sh" = mkIf cfg.direnv { + executable = true; + text = '' + use_riff() { + watch_file Cargo.toml watch_file Cargo.lock + eval "$(riff --offline print-dev-env)" + } + ''; + }; + }; +} diff --git a/common/hm-modules/rust.nix b/common/hm-modules/rust.nix new file mode 100644 index 0000000..f489bd3 --- /dev/null +++ b/common/hm-modules/rust.nix @@ -0,0 +1,26 @@ +{ pkgs, lib, config, ... }: +with lib; +let cfg = config.programs.v.rust; +in { + options.programs.v.rust = { enable = mkEnableOption "rust"; }; + config = mkIf cfg.enable { + home = { + packages = with pkgs; [ rustup cargo-nextest cargo-msrv cargo-dist cargo-cross]; + + file = { + ".cargo/config.toml".text = '' + [registries.crates-io] + protocol = "sparse" + + [build] + rustc-wrapper = "${pkgs.sccache}/bin/sccache" + + [profile.rust-analyzer] + inherits = "dev" + ''; + }; + + sessionPath = [ "$HOME/.cargo/bin" ]; + }; + }; +} diff --git a/common/hm-modules/vscode.nix b/common/hm-modules/vscode.nix new file mode 100644 index 0000000..1cc5dd9 --- /dev/null +++ b/common/hm-modules/vscode.nix @@ -0,0 +1,79 @@ +{ config, pkgs, lib, ... }: +with lib; +let cfg = config.programs.v.vscode; +in { + options.programs.v.vscode = { enable = mkEnableOption "vscode"; }; + config = mkIf cfg.enable { + programs.vscode = { + enable = true; + package = pkgs.vscode; + userSettings = { + "ltex.language" = "en-GB"; + "latex-workshop.linting.chktex.enabled" = true; + "latex-workshop.latex.clean.subfolder.enabled" = true; + "latex-workshop.latex.outDir" = "%TMPDIR%/%RELATIVE_DOC%"; + "editor.fontFamily" = + "'DejaVuSansMono Nerd Font', 'monospace', monospace"; + "keyboard.dispatch" = "keyCode"; + "rust-analyzer.server.path" = "${pkgs.rust-analyzer}/bin/rust-analyzer"; + "rust-analyzer.check.extraArgs" = ["--profile" "rust-analyzer"]; + "rust-analyzer.check.command" = "clippy"; + "terminal.integrated.defaultProfile.linux" = "zsh"; + "nix.enableLanguageServer" = true; # Enable LSP. + "nix.serverPath" = "${pkgs.nil}/bin/nil"; + "[nix]" = { "editor.defaultFormatter" = "brettm12345.nixfmt-vscode"; }; + "[python]" = { "editor.formatOnType" = true; }; + "debug.allowBreakpointsEverywhere" = true; + "C_Cpp.clang_format_fallbackStyle" = + "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}"; + "crates.compatibleDecorator" = "✓"; + "crates.errorDecorator" = "✗"; + "crates.incompatibleDecorator" = "🛇"; + # Don't index unecessary things + "files.exclude" = { + "**/.vscode" = true; + "**/.git" = true; + "**/.svn" = true; + "**/.hg" = true; + "**/.deps" = true; + "**/CVS" = true; + "**/.DS_Store" = true; + "/bin" = true; + "/boot" = true; + "/cdrom" = true; + "/dev" = true; + "/proc" = true; + "/etc" = true; + "/nix" = true; + }; + }; + extensions = with pkgs.vscode-extensions; + with pkgs.v.vscode-extensions; [ + brettm12345.nixfmt-vscode + codezombiech.gitignore + editorconfig.editorconfig + foxundermoon.shell-format + james-yu.latex-workshop + jnoortheen.nix-ide + matklad.rust-analyzer + mkhl.direnv + ms-vscode-remote.remote-ssh + ms-vscode.cpptools + platformio.platformio-ide + redhat.vscode-yaml + redhat.vscode-xml + tamasfe.even-better-toml + valentjn.vscode-ltex + vscodevim.vim + vadimcn.vscode-lldb + xaver.clang-format + sumneko.lua + davidlday.languagetool-linter + serayuzgur.crates + skellock.just + ]; + }; + + }; +} + diff --git a/nixos/common/users/default.nix b/common/users/default.nix similarity index 100% rename from nixos/common/users/default.nix rename to common/users/default.nix diff --git a/nixos/common/users/jonathan.nix b/common/users/jonathan.nix similarity index 100% rename from nixos/common/users/jonathan.nix rename to common/users/jonathan.nix diff --git a/nixos/common/users/laura.nix b/common/users/laura.nix similarity index 100% rename from nixos/common/users/laura.nix rename to common/users/laura.nix diff --git a/nixos/common/users/vivian.nix b/common/users/vivian.nix similarity index 99% rename from nixos/common/users/vivian.nix rename to common/users/vivian.nix index a625a24..862ff07 100644 --- a/nixos/common/users/vivian.nix +++ b/common/users/vivian.nix @@ -41,6 +41,5 @@ homeDirectory = "/home/vivian"; stateVersion = "23.05"; }; - }; }