diff --git a/flake.lock b/flake.lock index 63b4068..23f937a 100644 --- a/flake.lock +++ b/flake.lock @@ -193,6 +193,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1777699697, + "narHash": "sha256-Eg9b/rq/ECYwNwEXs5i9wHyhxNI0JrYx2srdI2uZMaQ=", + "ref": "refs/heads/main", + "rev": "382052b74656a369c5408822af3f2501e9b1af81", + "revCount": 94, + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + }, + "original": { + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + } + }, "flake-file": { "locked": { "lastModified": 1788209062, @@ -417,6 +433,21 @@ "type": "github" } }, + "mnw": { + "locked": { + "lastModified": 1780772958, + "narHash": "sha256-VKKe8r4pwCGWZ3Yr9CPN129R4S3CKLSrlYqdYz3vKpM=", + "owner": "Gerg-L", + "repo": "mnw", + "rev": "0871dbf63a53610c95db04439ed8ea4d6ec9c160", + "type": "github" + }, + "original": { + "owner": "Gerg-L", + "repo": "mnw", + "type": "github" + } + }, "nixos-hardware": { "inputs": { "nixpkgs": [ @@ -510,6 +541,28 @@ "type": "github" } }, + "nvf": { + "inputs": { + "flake-compat": "flake-compat_2", + "mnw": "mnw", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1788494938, + "narHash": "sha256-ozY1uUiOLXt3KLpUQwu8Y1DG+lKa53Gke7NW9gvUu3I=", + "owner": "notashelf", + "repo": "nvf", + "rev": "5e4f212f8720c17fdd06f5c57591f251aff67453", + "type": "github" + }, + "original": { + "owner": "notashelf", + "repo": "nvf", + "type": "github" + } + }, "pre-commit": { "inputs": { "flake-compat": "flake-compat", @@ -546,6 +599,7 @@ "lanzaboote": "lanzaboote", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs_3", + "nvf": "nvf", "sops-nix": "sops-nix", "spicetify-nix": "spicetify-nix", "stylix": "stylix", diff --git a/flake.nix b/flake.nix index d655199..13807e5 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,10 @@ inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nvf = { + url = "github:notashelf/nvf"; + inputs.nixpkgs.follows = "nixpkgs"; + }; sops-nix = { url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/modules/aspects/apps/direnv.nix b/modules/aspects/apps/direnv.nix new file mode 100644 index 0000000..00f4837 --- /dev/null +++ b/modules/aspects/apps/direnv.nix @@ -0,0 +1,35 @@ +_: { + # direnv, so entering a project directory loads its environment. + # + # This exists because apps/neovim.nix turned on nvf's direnv plugin, which is + # only the direnv.vim wrapper - it shells out to a direnv binary that nothing + # here installed, so every file opened printed "no direnv executable found". + # Anything else looking for it, VSCodium included, failed the same way for the + # same reason. + den.aspects.direnv = { + # The allow list, and the only state direnv keeps. It writes one file per + # approved .envrc under $XDG_DATA_HOME/direnv/allow - verified against + # direnv 2.37, which put .local/share/direnv/allow/ there on a test + # 'direnv allow'. Without this, / going back to a blank snapshot every boot + # means every project asks to be approved again. + persist.home.directories = [ ".local/share/direnv" ]; + + homeManager = _: { + programs.direnv = { + enable = true; + + # Caches the flake's dev shell and keeps a GC root for it, so a cd into + # a project is instant instead of a fresh evaluation, and the closure + # survives the weekly nix.gc in core/nix.nix. The cache lives in a + # .direnv directory inside the project itself, which for everything I + # work on is under ~/Syncthing - already persisted by apps/syncthing.nix. + nix-direnv.enable = true; + }; + + # No shell hook here. enableZshIntegration defaults on whenever zsh is + # enabled, and Home Manager writes the hook into programs.zsh.initContent + # itself - the same reason apps/shell.nix does not repeat what + # den.batteries.user-shell already turned on. + }; + }; +} diff --git a/modules/aspects/apps/ghostty.nix b/modules/aspects/apps/ghostty.nix index 079bad9..cbbdd9a 100644 --- a/modules/aspects/apps/ghostty.nix +++ b/modules/aspects/apps/ghostty.nix @@ -1,8 +1,20 @@ -_: { +{ lib, ... }: +{ # The Ghostty terminal emulator. - den.aspects.ghostty.homeManager = _: { - # Shell integration is already on through home.shell.enableShellIntegration, - # so I don't repeat it here. - programs.ghostty.enable = true; + den.aspects.ghostty = { + # This is the terminal, for anything that needs to wrap a command in a + # window - see the terminal quirk in den/quirks.nix. "-e" is ghostty's way + # of saying "run this instead of a shell"; a different terminal spells it + # differently, which is exactly why the spelling lives here and not in the + # aspects that consume it. + # + # A function of pkgs, applied by the consumer where pkgs is in scope. + terminal.exec = pkgs: "${lib.getExe pkgs.ghostty} -e"; + + homeManager = _: { + # Shell integration is already on through home.shell.enableShellIntegration, + # so I don't repeat it here. + programs.ghostty.enable = true; + }; }; } diff --git a/modules/aspects/apps/neovim.nix b/modules/aspects/apps/neovim.nix new file mode 100644 index 0000000..a374c7f --- /dev/null +++ b/modules/aspects/apps/neovim.nix @@ -0,0 +1,222 @@ +# This is a neovim (nvf) config based on the defaults that Omarchy ships with. +{ inputs, ... }: +let + # The text types Omarchy points at nvim.desktop in + # default/applications/mimeapps.list. That list is neovim's own desktop entry + # MimeType line plus the two xml types, so this is the set that makes + # double-clicking a text file in Files land in the editor. + # + # text/html and application/pdf are deliberately absent: apps/firefox.nix + # claims those, and two aspects claiming one type is a race, not a merge. + textTypes = [ + "text/plain" + "text/english" + "text/x-makefile" + "text/x-c++hdr" + "text/x-c++src" + "text/x-chdr" + "text/x-csrc" + "text/x-java" + "text/x-moc" + "text/x-pascal" + "text/x-tcl" + "text/x-tex" + "text/x-c" + "text/x-c++" + "application/x-shellscript" + "application/xml" + "text/xml" + ]; + + # Same shape desktop/stylix.nix uses for the theme pool: one entry is the only + # sane state. Empty means no terminal aspect is included and the desktop entry + # would have nothing to open a window with; more than one means two terminals + # both claim to be *the* terminal, and the winner would be whichever den + # collected first. + pick = lib: terminal: if terminal == [ ] then null else lib.head terminal; + + guard = lib: terminal: [ + { + assertion = lib.length terminal == 1; + message = "apps.neovim: the terminal quirk pool holds ${toString (lib.length terminal)} entries, not one. It is set by the terminal aspect, e.g. apps/ghostty.nix."; + } + ]; +in +{ + flake-file.inputs.nvf = { + url = "github:notashelf/nvf"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # Neovim through nvf, which is a Nix module system for the editor rather than + # a pile of lua: a plugin is one option, a language is one line that brings + # its LSP, treesitter grammar and formatter together. + # + # Nothing here sets a colour. Stylix's nvf target writes the scheme from the + # theme quirk straight into vim.theme, and it is gated on + # "options.programs ? nvf" - so importing the module below is what switches + # theming on, and setting vim.theme here would fight it. + den.aspects.neovim = { + # Everything nvf configures is rewritten on activation. The state directory + # is the only thing neovim writes at runtime: shada (marks, registers, + # command history, last cursor position) and the undo files that + # vim.undoFile puts under stdpath('state'). + # + # The directory, NOT the files in it - shada is saved by renaming a temp + # file over the target, which is the same trap apps/zsh.nix documents for + # .zsh_history: the rename replaces impermanence's symlink with a real file + # and the next activation dies on "A file already exists at ...". + persist.home.directories = [ ".local/state/nvim" ]; + + homeManager = + { + config, + lib, + pkgs, + terminal, + ... + }: + let + chosen = pick lib terminal; + in + { + imports = [ inputs.nvf.homeManagerModules.nvf ]; + + assertions = guard lib terminal; + + programs.nvf = { + enable = true; + + # Exports EDITOR=nvim. VISUAL is set below - nvf only claims EDITOR, + # and the two disagreeing is how you end up with git using one editor + # and sudoedit another. + defaultEditor = true; + + settings.vim = { + viAlias = true; + vimAlias = true; + + # Persistent undo across sessions, which is what makes the persist + # entry above worth having. + undoFile.enable = true; + + # What this repo is actually made of. Each line brings that + # language's LSP, grammar and formatter, per the enable* flags. + languages = { + enableTreesitter = true; + enableFormat = true; + enableExtraDiagnostics = true; + + nix.enable = true; + bash.enable = true; + lua.enable = true; + markdown.enable = true; + just.enable = true; + json.enable = true; + yaml.enable = true; + toml.enable = true; + }; + + lsp.enable = true; + treesitter.context.enable = true; + + # Completion and snippets. + autocomplete.blink-cmp.enable = true; + snippets.luasnip.enable = true; + + # The bits that make it feel like a configured editor rather than a + # bare nvim: fuzzy finder, file tree, statusline, buffer line, + # git gutter, and which-key so the bindings are discoverable + # instead of memorised. + telescope.enable = true; + filetree.neo-tree.enable = true; + statusline.lualine.enable = true; # theme comes from Stylix + tabline.nvimBufferline.enable = true; + git.gitsigns.enable = true; + binds.whichKey.enable = true; + + autopairs.nvim-autopairs.enable = true; + comments.comment-nvim.enable = true; + utility.surround.enable = true; + utility.motion.flash-nvim.enable = true; + utility.undotree.enable = true; + + # Only the direnv.vim wrapper - it shells out to a direnv binary, + # which apps/direnv.nix installs. Not an include of that aspect: + # direnv is a shell tool in its own right, wanted by the terminal + # and VSCodium too, so it hangs off the user rather than off the + # editor. If this ever prints "no direnv executable found" again, + # den.aspects.direnv has gone missing from users/tomwrw. + utility.direnv.enable = true; + + terminal.toggleterm.enable = true; + + visuals = { + nvim-web-devicons.enable = true; + indent-blankline.enable = true; + fidget-nvim.enable = true; + nvim-cursorline.enable = true; + }; + + ui.noice.enable = true; + notify.nvim-notify.enable = true; + dashboard.alpha.enable = true; + }; + }; + + # nvf sets EDITOR through defaultEditor; VISUAL is ours. + home.sessionVariables.VISUAL = "nvim"; + + # As Omarchy has it. Free: no binary on PATH is called n, and it cannot + # be confused with the nr/nb/nt set in core/nix.nix. + home.shellAliases.n = "nvim"; + + # The entry that makes double-click work, and the reason it names its + # own terminal: nvf's package ships its own share/applications/ + # nvim.desktop with "Terminal=true" and "Exec=nvim %F", and the glib in + # this closure has no terminal-discovery left in libgio - no + # xdg-terminals.list, no hardcoded fallback list - so nothing resolves + # it and double-clicking that entry does nothing at all. + # + # This deliberately reuses the id "nvim" to shadow it: Home Manager + # writes to ~/.local/share/applications, and XDG_DATA_HOME takes + # precedence over the profile in XDG_DATA_DIRS, so ours is the one that + # resolves. A distinct id would leave two "Neovim" entries in the menu, + # one of them the broken one. If a double-click ever silently does + # nothing, this shadowing is the first thing to check. + # + # Store paths rather than bare names, for the reason apps/vscodium.nix + # gives about nix.serverPath: a desktop entry runs with whatever PATH + # the session handed the launcher, not the shell's. + # + # No terminal is named here. Which one to open, and how that one is told + # to run a command, both come from the terminal quirk - so moving to + # alacritty is a change to the terminal aspect and nothing else. + # mkIf and not a bare attrset: with no terminal aspect included the pool + # is empty, chosen is null, and "chosen.exec" would throw before the + # assertion above ever got the chance to say which quirk is missing. + # Same reason desktop/stylix.nix guards its half this way. + xdg.desktopEntries.nvim = lib.mkIf (chosen != null) { + name = "Neovim"; + genericName = "Text Editor"; + comment = "Edit text files"; + icon = "nvim"; + exec = "${chosen.exec pkgs} ${config.programs.nvf.finalPackage}/bin/nvim %F"; + terminal = false; + type = "Application"; + categories = [ + "Utility" + "TextEditor" + "Development" + ]; + mimeType = textTypes; + }; + + # Home Manager only writes mimeapps.list if this is set, and relying on + # desktop/gnome.nix happening to set it is the invisible dependency + # apps/firefox.nix already got caught by. + xdg.mimeApps.enable = true; + xdg.mimeApps.defaultApplications = lib.genAttrs textTypes (_: [ "nvim.desktop" ]); + }; + }; +} diff --git a/modules/den/quirks.nix b/modules/den/quirks.nix index 1e195b4..75f7b60 100644 --- a/modules/den/quirks.nix +++ b/modules/den/quirks.nix @@ -67,6 +67,24 @@ description = ''The look: { scheme = "rose-pine-moon"; wallpaper = ./snake.png; }, optionally polarity''; }; + # The terminal to run a terminal program in, stated once by whichever terminal + # aspect is installed and read by anything that needs to open a window around + # a command - apps/neovim.nix, for its desktop entry. + # + # It carries a function of pkgs rather than a package, because "run this + # command" is not spelled the same way twice: ghostty and alacritty take + # "-e cmd", wezterm takes "start -- cmd", kitty takes the command bare. The + # flag belongs with the terminal that understands it, not with every consumer. + # Applied by the consumer inside a class block, where pkgs exists - the same + # trick desktop/stylix.nix uses for its font set. + # + # Nothing here says which terminal. Swapping ghostty for alacritty is writing + # this quirk from the new aspect and removing the old one from users/tomwrw; + # no consumer changes. + den.quirks.terminal = { + description = ''How to run a command in a terminal window: { exec = pkgs: "\''${terminal} -e"; }''; + }; + # One device in the mesh: { name = "endgame"; id = "O5ZE76L-..."; } and # optionally addresses for a peer local discovery can't find. Produced once # per host, consumed once per user, so it crosses both the fleet and the diff --git a/modules/users/tomwrw/tomwrw.nix b/modules/users/tomwrw/tomwrw.nix index 77e62ca..406c947 100644 --- a/modules/users/tomwrw/tomwrw.nix +++ b/modules/users/tomwrw/tomwrw.nix @@ -28,7 +28,9 @@ in # Shell and terminal den.aspects.btop den.aspects.cli-apps + den.aspects.direnv den.aspects.ghostty + den.aspects.neovim # The parent carries the shell-agnostic aliases, the sub-aspect is the # shell that renders them. A provides child does not pull its parent in, # so both are listed - as roles/base.nix does for den.aspects.boot.