From c0a5d1f8cc7fd2de7ae38ddc373bf6ed04ca8522 Mon Sep 17 00:00:00 2001 From: prescientmoon Date: Sat, 31 Aug 2024 18:38:31 +0200 Subject: [PATCH] Allow choosing between iwd and wpa_supplicant --- flake.lock | 6 +- home/features/desktop/firefox/default.nix | 9 + home/features/neovim/config/lazy-lock.json | 3 + home/features/neovim/default.nix | 49 ++- home/features/persistence.nix | 11 +- hosts/nixos/calypso/default.nix | 3 +- hosts/nixos/common/global/default.nix | 6 - hosts/nixos/common/global/persistence.nix | 5 + hosts/nixos/common/optional/services/iwd.nix | 12 + .../services/wpa_supplicant.nix} | 0 hosts/nixos/common/optional/users/common.nix | 4 + hosts/nixos/common/optional/users/guest.nix | 23 ++ .../common/{ => optional}/users/pilot.nix | 21 +- hosts/nixos/common/users/common.nix | 21 - hosts/nixos/common/users/guest.nix | 13 - hosts/nixos/iso/default.nix | 2 +- hosts/nixos/lapetus/default.nix | 3 +- hosts/nixos/tethys/default.nix | 3 +- modules/common/korora-neovim.nix | 389 +++++++++++------- 19 files changed, 384 insertions(+), 199 deletions(-) create mode 100644 hosts/nixos/common/optional/services/iwd.nix rename hosts/nixos/common/{global/wireless/default.nix => optional/services/wpa_supplicant.nix} (100%) create mode 100644 hosts/nixos/common/optional/users/common.nix create mode 100644 hosts/nixos/common/optional/users/guest.nix rename hosts/nixos/common/{ => optional}/users/pilot.nix (73%) delete mode 100644 hosts/nixos/common/users/common.nix delete mode 100644 hosts/nixos/common/users/guest.nix diff --git a/flake.lock b/flake.lock index 2b813ba..93b6cc7 100644 --- a/flake.lock +++ b/flake.lock @@ -1475,11 +1475,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1720031269, - "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", + "lastModified": 1724819573, + "narHash": "sha256-GnR7/ibgIH1vhoy8cYdmXE6iyZqKqFxQSVkFgosBh6w=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", + "rev": "71e91c409d1e654808b2621f28a327acfdad8dc2", "type": "github" }, "original": { diff --git a/home/features/desktop/firefox/default.nix b/home/features/desktop/firefox/default.nix index aae4b6b..0403497 100644 --- a/home/features/desktop/firefox/default.nix +++ b/home/features/desktop/firefox/default.nix @@ -150,6 +150,15 @@ in type = "options"; }; + "Home-manager options" = mkBasicSearchEngine { + aliases = [ + "@hm" + "@home-manager" + ]; + param = "query"; + url = "https://home-manager-options.extranix.com"; + }; + "Pursuit" = mkBasicSearchEngine { url = "https://pursuit.purescript.org/search"; param = "q"; diff --git a/home/features/neovim/config/lazy-lock.json b/home/features/neovim/config/lazy-lock.json index 439ba1a..7fb53a2 100644 --- a/home/features/neovim/config/lazy-lock.json +++ b/home/features/neovim/config/lazy-lock.json @@ -38,8 +38,11 @@ "navigator": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "neoconf": { "branch": "main", "commit": "23f24edab5f78465a0bc3320678e038664b9aa6e" }, "neodev": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, + "neotest": { "branch": "master", "commit": "6d6ad113f56edc7c3f2a77a0836ea8c1b955ebea" }, + "neotest-haskell": { "branch": "master", "commit": "10cd953fb7c81de82ce8dc618e0614e0ab5fa1e3" }, "nui": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, "null-ls": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, + "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, "plenary": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "purescript": { "branch": "main", "commit": "82348352e6568fcc0385bd7c99a8ead3a479feea" }, "rust-tools": { "branch": "master", "commit": "676187908a1ce35ffcd727c654ed68d851299d3e" }, diff --git a/home/features/neovim/default.nix b/home/features/neovim/default.nix index 774c825..210ae58 100644 --- a/home/features/neovim/default.nix +++ b/home/features/neovim/default.nix @@ -518,7 +518,7 @@ let (nmap "" "find_files" "File finder [p]alette") (nmap "d" "diagnostics" "[D]iagnostics") (nmap "" "live_grep" "[F]ind in project") - (nmap "t" "builtin" "[T]elescope pickers") + (nmap "" "builtin" "[T]elescope pickers") # {{{ Files by extension (findFilesByExtension "tx" "tex" "[t]ex") (findFilesByExtension "ts" "ts" "[t]ypescript") @@ -643,8 +643,14 @@ let # {{{ treesitter treesitter = { # REASON: more grammars - # dir = upkgs.vimPlugins.nvim-treesitter.withAllGrammars; - package = "nvim-treesitter/nvim-treesitter"; + dir = pkgs.symlinkJoin { + name = "treesitter-with-parsers"; + paths = [ + upkgs.vimPlugins.nvim-treesitter.withAllGrammars + upkgs.vimPlugins.nvim-treesitter.withAllGrammars.dependencies + ]; + }; + # package = "nvim-treesitter/nvim-treesitter"; main = "nvim-treesitter.configs"; dependencies.nix = [ pkgs.tree-sitter ]; @@ -1218,6 +1224,43 @@ let config = importFrom ./plugins/cmp.lua "config"; }; # }}} + # {{{ neotest + neotest = { + package = "nvim-neotest/neotest"; + dependencies.lua = [ + # {{{ Adapters + "mrcjkb/neotest-haskell" + # }}} + "plenary" + "treesitter" + "nvim-neotest/nvim-nio" + ]; + + cond = blacklist "vscode"; + config = _: { + setup.neotest.adapters = [ + (require "neotest-haskell" { + build_tools = [ "stack" ]; + frameworks = [ "hspec" ]; + }) + ]; + }; + + # {{{ Keybinds + keys = + let + nmap = + key: arg: desc: + nlib.nmap "t${key}" (thunk "require('neotest').run.${arg}") desc; + in + [ + (nmap "c" "run()" "Run [c]urrent [t]est") + (nmap "f" "run(vim.fn.expand('%'))" "Run [t]ests in [f]ile") + (nmap "s" "stop()" "Run [c]urrent [t]est") + ]; + # }}} + }; + # }}} # }}} # {{{ language support # {{{ haskell support diff --git a/home/features/persistence.nix b/home/features/persistence.nix index b315a95..b8360af 100644 --- a/home/features/persistence.nix +++ b/home/features/persistence.nix @@ -1,6 +1,6 @@ { config, ... }: { - # {{{ Set up my custom imperanence wrapper + # {{{ Set up my custom imperanenceo wrapper satellite.persistence = { enable = true; @@ -46,6 +46,9 @@ "${config.xdg.cacheHome}/ghcide" "${config.xdg.cacheHome}/cabal" ]; + + # TODO: should I move this in it's own haskell-specific file? + home.file.".stack/config.yaml".text = builtins.toJSON { notify-if-nix-on-path = false; }; # }}} # {{{ Nodejs satellite.persistence.at.cache.apps.nodejs = { @@ -135,6 +138,12 @@ "${config.xdg.configHome}/Bitwarden" ]; # }}} + # {{{ Gnome keyring + services.gnome-keyring.enable = true; + satellite.persistence.at.state.apps.gnome-keyring.directories = [ + "${config.xdg.dataHome}/keyrings" + ]; + # }}} # }}} # {{{ Cli # {{{ Sops diff --git a/hosts/nixos/calypso/default.nix b/hosts/nixos/calypso/default.nix index 31f3b79..438ef9a 100644 --- a/hosts/nixos/calypso/default.nix +++ b/hosts/nixos/calypso/default.nix @@ -6,8 +6,8 @@ # {{{ Imports imports = [ ../common/global - ../common/users/pilot.nix + ../common/optional/users/pilot.nix ../common/optional/bluetooth.nix ../common/optional/greetd.nix ../common/optional/oci.nix @@ -17,6 +17,7 @@ ../common/optional/desktop/steam.nix ../common/optional/wayland/hyprland.nix + ../common/optional/services/iwd.nix ../common/optional/services/kanata.nix ../common/optional/services/nginx.nix ../common/optional/services/syncthing.nix diff --git a/hosts/nixos/common/global/default.nix b/hosts/nixos/common/global/default.nix index da71d50..b032ed3 100644 --- a/hosts/nixos/common/global/default.nix +++ b/hosts/nixos/common/global/default.nix @@ -22,7 +22,6 @@ let ./unicode.nix ./persistence.nix ./ports.nix - ./wireless ../../../../common # }}} @@ -48,11 +47,6 @@ in # Boot using systemd boot.initrd.systemd.enable = true; # }}} - # {{{ Disable sudo default lecture - security.sudo.extraConfig = '' - Defaults lecture = never - ''; - # }}} nixpkgs = { # Add all overlays defined in the overlays directory diff --git a/hosts/nixos/common/global/persistence.nix b/hosts/nixos/common/global/persistence.nix index e5b4058..a958519 100644 --- a/hosts/nixos/common/global/persistence.nix +++ b/hosts/nixos/common/global/persistence.nix @@ -22,6 +22,11 @@ # See [the imperanence readme](https://github.com/nix-community/impermanence#home-manager) programs.fuse.userAllowOther = true; + # {{{ Disable sudo default lecture + security.sudo.extraConfig = '' + Defaults lecture = never + ''; + # }}} # {{{ Create home directories systemd.tmpfiles.rules = let diff --git a/hosts/nixos/common/optional/services/iwd.nix b/hosts/nixos/common/optional/services/iwd.nix new file mode 100644 index 0000000..7cad45c --- /dev/null +++ b/hosts/nixos/common/optional/services/iwd.nix @@ -0,0 +1,12 @@ +{ + networking.wireless.iwd = { + enable = true; + + settings = { + IPv6.Enabled = true; + Settings.AutoConnect = true; + }; + }; + + environment.persistence."/persist/state".directories = [ "/var/lib/iwd" ]; +} diff --git a/hosts/nixos/common/global/wireless/default.nix b/hosts/nixos/common/optional/services/wpa_supplicant.nix similarity index 100% rename from hosts/nixos/common/global/wireless/default.nix rename to hosts/nixos/common/optional/services/wpa_supplicant.nix diff --git a/hosts/nixos/common/optional/users/common.nix b/hosts/nixos/common/optional/users/common.nix new file mode 100644 index 0000000..a1753ca --- /dev/null +++ b/hosts/nixos/common/optional/users/common.nix @@ -0,0 +1,4 @@ +{ + authorizedKeys = { outputs, lib }: + +} diff --git a/hosts/nixos/common/optional/users/guest.nix b/hosts/nixos/common/optional/users/guest.nix new file mode 100644 index 0000000..64c2dbd --- /dev/null +++ b/hosts/nixos/common/optional/users/guest.nix @@ -0,0 +1,23 @@ +# For more comments check out [pilot](./pilot.nix) +{ + pkgs, + outputs, + lib, + ... +}: +{ + users.mutableUsers = false; + users.users.guest = { + isNormalUser = true; + shell = pkgs.fish; + extraGroups = [ + "wheel" + "audio" + "video" + "network" + "tty" + ]; + password = "heyo"; + openssh.authorizedKeys.keyFiles = (import ./common.nix).authorizedKeys { inherit outputs lib; }; + }; +} diff --git a/hosts/nixos/common/users/pilot.nix b/hosts/nixos/common/optional/users/pilot.nix similarity index 73% rename from hosts/nixos/common/users/pilot.nix rename to hosts/nixos/common/optional/users/pilot.nix index 6debaa5..47bc217 100644 --- a/hosts/nixos/common/users/pilot.nix +++ b/hosts/nixos/common/optional/users/pilot.nix @@ -47,7 +47,26 @@ hashedPasswordFile = config.sops.secrets.pilot_password.path; shell = pkgs.fish; - openssh.authorizedKeys.keyFiles = (import ./common.nix).authorizedKeys { inherit outputs lib; }; + # {{{ Authorize ssh keys + openssh.authorizedKeys.keyFiles = + let + # Record containing all the hosts + hosts = outputs.nixosConfigurations; + + # Function from hostname to relative path to public ssh key + idKey = host: ../../${host}/keys/id_ed25519.pub; + in + lib.pipe hosts [ + # attrsetof host -> attrsetof path + (builtins.mapAttrs (name: _: idKey name)) # string -> host -> path + + # attrsetof path -> path[] + builtins.attrValues + + # path[] -> path[] + (builtins.filter builtins.pathExists) + ]; + # }}} }; # }}} }; diff --git a/hosts/nixos/common/users/common.nix b/hosts/nixos/common/users/common.nix deleted file mode 100644 index 3d3ba0c..0000000 --- a/hosts/nixos/common/users/common.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ - authorizedKeys = { outputs, lib }: - let - # Record containing all the hosts - hosts = outputs.nixosConfigurations; - - # Function from hostname to relative path to public ssh key - idKey = host: ../../${host}/keys/id_ed25519.pub; - in - lib.pipe hosts [ - # attrsetof host -> attrsetof path - (builtins.mapAttrs - (name: _: idKey name)) # string -> host -> path - - # attrsetof path -> path[] - builtins.attrValues - - # path[] -> path[] - (builtins.filter builtins.pathExists) - ]; -} diff --git a/hosts/nixos/common/users/guest.nix b/hosts/nixos/common/users/guest.nix deleted file mode 100644 index e301080..0000000 --- a/hosts/nixos/common/users/guest.nix +++ /dev/null @@ -1,13 +0,0 @@ -# For more comments check out [pilot](./pilot.nix) -{ pkgs, outputs, lib, ... }: -{ - users.mutableUsers = false; - users.users.guest = { - isNormalUser = true; - shell = pkgs.fish; - extraGroups = [ "wheel" "audio" "video" "network" "tty" ]; - password = "heyo"; - openssh.authorizedKeys.keyFiles = - (import ./common.nix).authorizedKeys { inherit outputs lib; }; - }; -} diff --git a/hosts/nixos/iso/default.nix b/hosts/nixos/iso/default.nix index 5549c46..4ffc2a3 100644 --- a/hosts/nixos/iso/default.nix +++ b/hosts/nixos/iso/default.nix @@ -16,8 +16,8 @@ inputs.sops-nix.nixosModules.sops - ../common/global/wireless ../common/global/cli/fish.nix + ../common/optional/services/wpa_supplicant.nix ../common/optional/services/kanata.nix ]; # }}} diff --git a/hosts/nixos/lapetus/default.nix b/hosts/nixos/lapetus/default.nix index ebf33c7..258a2b6 100644 --- a/hosts/nixos/lapetus/default.nix +++ b/hosts/nixos/lapetus/default.nix @@ -6,7 +6,7 @@ # {{{ Imports imports = [ ../common/global - ../common/users/pilot.nix + ../common/optional/users/pilot.nix ../common/optional/oci.nix ../common/optional/services/tailscale.nix ../common/optional/services/acme.nix @@ -15,6 +15,7 @@ ../common/optional/services/postgres.nix ../common/optional/services/syncthing.nix ../common/optional/services/restic + ../common/optional/services/wpa_supplicant.nix # ./services/commafeed.nix # ./services/ddclient.nix diff --git a/hosts/nixos/tethys/default.nix b/hosts/nixos/tethys/default.nix index 8ab1681..3e30e90 100644 --- a/hosts/nixos/tethys/default.nix +++ b/hosts/nixos/tethys/default.nix @@ -6,8 +6,8 @@ # {{{ Imports imports = [ ../common/global - ../common/users/pilot.nix + ../common/optional/users/pilot.nix ../common/optional/bluetooth.nix ../common/optional/greetd.nix ../common/optional/oci.nix @@ -17,6 +17,7 @@ ../common/optional/desktop/steam.nix ../common/optional/wayland/hyprland.nix + ../common/optional/services/wpa_supplicant.nix ../common/optional/services/tailscale.nix ../common/optional/services/kanata.nix ../common/optional/services/restic diff --git a/modules/common/korora-neovim.nix b/modules/common/korora-neovim.nix index 11acdf8..eac4dd3 100644 --- a/modules/common/korora-neovim.nix +++ b/modules/common/korora-neovim.nix @@ -3,178 +3,266 @@ let e = import ./korora-lua.nix attrs; k = korora; h = e.helpers; - struct = name: props: verify: (k.struct name props).override { - total = false; - unknown = false; - verify = h.mkVerify verify; - }; + struct = + name: props: verify: + (k.struct name props).override { + total = false; + unknown = false; + verify = h.mkVerify verify; + }; lazyType = name: mkType: k.typedef' name (v: (mkType true).verify v); types = { # {{{ Helper types - oneOrMany = type: k.union [ type (k.listOf type) ]; + oneOrMany = + type: + k.union [ + type + (k.listOf type) + ]; luaValue = k.any; - strictLuaLiteral = (k.struct "lua literal" { - value = k.string; - __luaEncoderTag = k.enum "lua literal tag" [ "lua" ]; - }).override { unknown = true; }; + strictLuaLiteral = + (k.struct "lua literal" { + value = k.string; + __luaEncoderTag = k.enum "lua literal tag" [ "lua" ]; + }).override + { unknown = true; }; derivation = k.typedef "derivation" lib.isDerivation; path = k.typedef "path" lib.isPath; - functionCheckedWith = arg: type: - k.typedef' - "${h.toPretty arg} -> ${type.name}" - (f: - if lib.isFunction f - then type.verify (f arg) - else "Expected function, but got ${h.toPretty f} instead"); - luaEagerOrLazy = type: k.union [ type (types.functionCheckedWith "" type) ]; + functionCheckedWith = + arg: type: + k.typedef' "${h.toPretty arg} -> ${type.name}" ( + f: + if lib.isFunction f then + type.verify (f arg) + else + "Expected function, but got ${h.toPretty f} instead" + ); + luaEagerOrLazy = + type: + k.union [ + type + (types.functionCheckedWith "" type) + ]; luaLiteral = types.luaEagerOrLazy types.strictLuaLiteral; # }}} - # {{{ Lazy key - lazyKey = struct "lazy key" - { - mapping = k.string; - action = k.union [ types.luaLiteral k.string ]; - mode = k.string; - desc = k.string; - expr = k.bool; - ft = types.oneOrMany k.string; - } - [ (h.propExists "mapping") ]; + # {{{ Lazy key + lazyKey = struct "lazy key" { + mapping = k.string; + action = k.union [ + types.luaLiteral + k.string + ]; + mode = k.string; + desc = k.string; + expr = k.bool; + ft = types.oneOrMany k.string; + } [ (h.propExists "mapping") ]; # }}} - # {{{ Lazy module - lazyModule = lazyType "actually lazy lazy module" (_: struct "lazy module" - { - package = k.string; - dir = k.union [ k.string types.derivation types.path ]; - version = k.string; - tag = k.string; - name = k.string; - main = k.string; - lazy = k.bool; - dependencies = struct "lazy dependencies" - { - lua = k.listOf (k.union [ k.string types.lazyModule ]); + # {{{ Lazy module + lazyModule = lazyType "actually lazy lazy module" ( + _: + struct "lazy module" + { + package = k.string; + dir = k.union [ + k.string + types.derivation + types.path + ]; + version = k.string; + tag = k.string; + name = k.string; + main = k.string; + lazy = k.bool; + dependencies = struct "lazy dependencies" { + lua = k.listOf ( + k.union [ + k.string + types.lazyModule + ] + ); nix = k.listOf types.derivation; - } - [ ]; - cond = types.oneOrMany types.luaLiteral; - init = k.union [ types.luaLiteral types.tempestConfig ]; - config = k.union [ types.luaLiteral k.bool types.tempestConfig ]; - event = types.oneOrMany k.string; - cmd = types.oneOrMany k.string; - ft = types.oneOrMany k.string; - keys = types.oneOrMany (k.union [ k.string types.lazyKey ]); - passthrough = types.luaValue; - opts = types.luaValue; - } - [ - (h.propOnlyOne [ "dir" "package" ]) - (h.propImplies "tag" "package") - (h.propImplies "version" "package") - ]); + } [ ]; + cond = types.oneOrMany types.luaLiteral; + init = types.luaEagerOrLazy ( + k.union [ + types.strictLuaLiteral + types.strictTempestConfig + ] + ); + config = k.union [ + k.bool + (types.luaEagerOrLazy ( + k.union [ + types.strictLuaLiteral + types.strictTempestConfig + ] + )) + ]; + event = types.oneOrMany k.string; + cmd = types.oneOrMany k.string; + ft = types.oneOrMany k.string; + keys = types.oneOrMany ( + k.union [ + k.string + types.lazyKey + ] + ); + passthrough = types.luaValue; + opts = types.luaValue; + } + [ + (h.propOnlyOne [ + "dir" + "package" + ]) + (h.propImplies "tag" "package") + (h.propImplies "version" "package") + ] + ); # }}} - # {{{ Tempest key - tempestKey = struct "tempest key" - { - mapping = k.string; - action = k.union [ types.luaLiteral k.string ]; - mode = k.string; - desc = k.string; - expr = k.bool; - silent = k.bool; - ft = types.oneOrMany k.string; - buffer = k.union [ k.bool k.number types.luaLiteral ]; - } - [ - (h.propExists "mapping") - (h.propExists "action") - ]; + # {{{ Tempest key + tempestKey = + struct "tempest key" + { + mapping = k.string; + action = k.union [ + types.luaLiteral + k.string + ]; + mode = k.string; + desc = k.string; + expr = k.bool; + silent = k.bool; + ft = types.oneOrMany k.string; + buffer = k.union [ + k.bool + k.number + types.luaLiteral + ]; + } + [ + (h.propExists "mapping") + (h.propExists "action") + ]; # }}} - # {{{ Tempest autocmd - tempestAutocmd = struct "tempest autocommand" - { - event = types.oneOrMany k.string; - pattern = types.oneOrMany k.string; - group = k.string; - action = k.union [ types.tempestConfig types.luaLiteral ]; - } - [ - (h.propExists "event") - (h.propExists "group") - (h.propExists "action") - ]; + # {{{ Tempest autocmd + tempestAutocmd = + struct "tempest autocommand" + { + event = types.oneOrMany k.string; + pattern = types.oneOrMany k.string; + group = k.string; + action = k.union [ + types.tempestConfig + types.luaLiteral + ]; + } + [ + (h.propExists "event") + (h.propExists "group") + (h.propExists "action") + ]; # }}} # {{{ Tempest config - tempestConfig = lazyType "lazy tempest config" (_: struct "tempest config" - { - vim = types.luaValue; - callback = k.union [ types.luaLiteral types.tempestConfig ]; - setup = k.attrsOf types.luaValue; - keys = types.luaEagerOrLazy (types.oneOrMany types.tempestKey); - autocmds = types.luaEagerOrLazy (types.oneOrMany types.tempestAutocmd); - mkContext = types.luaValue; - cond = types.oneOrMany types.luaLiteral; - } - [ ]); + strictTempestConfig = struct "tempest config" { + vim = types.luaValue; + callback = k.union [ + types.luaLiteral + types.tempestConfig + ]; + setup = k.attrsOf types.luaValue; + keys = types.luaEagerOrLazy (types.oneOrMany types.tempestKey); + autocmds = types.luaEagerOrLazy (types.oneOrMany types.tempestAutocmd); + mkContext = types.luaValue; + cond = types.oneOrMany types.luaLiteral; + } [ ]; + + tempestConfig = lazyType "lazy tempest config" (_: types.strictTempestConfig); # }}} - # {{{ Neovim env - neovimEnv = k.enum "neovim env" - [ "neovide" "firenvim" "vscode" ]; + # {{{ Neovim env + neovimEnv = k.enum "neovim env" [ + "neovide" + "firenvim" + "vscode" + ]; # }}} - # {{{ Neovim config - neovimConfig = struct "neovim configuration" - { - pre = k.attrsOf types.tempestConfig; - lazy = k.attrsOf types.lazyModule; - post = k.attrsOf types.tempestConfig; - } [ ]; + # {{{ Neovim config + neovimConfig = struct "neovim configuration" { + pre = k.attrsOf types.tempestConfig; + lazy = k.attrsOf types.lazyModule; + post = k.attrsOf types.tempestConfig; + } [ ]; # }}} }; - mkLib = { tempestModule }: + mkLib = + { tempestModule }: assert h.hasType k.string tempestModule; rec { inherit (e) encode; inherit (h) lua; - # {{{ Common generation helpers - importFrom = path: tag: + # {{{ Common generation helpers + importFrom = + path: tag: assert lib.isPath path; assert h.hasType k.string tag; lua "dofile(${encode (toString path)}).${tag}"; - foldedList = value: assert h.hasType k.attrs value; - { inherit value; __luaEncoderTag = "foldedList"; }; + foldedList = + value: + assert h.hasType k.attrs value; + { + inherit value; + __luaEncoderTag = "foldedList"; + }; thunk = code: _: lua code; - tempest = given: context: lua '' - D.tempest.configure( - ${encode given}, - ${context} - ) - ''; - tempestBufnr = given: lua '' - function(_, bufnr) - return D.tempest.configure( + require = module: lua "require(${module})"; + tempest = + given: context: + lua '' + D.tempest.configure( ${encode given}, - { bufnr = bufnr} + ${context} ) - end - ''; - keymap = mode: mapping: action: desc: - { inherit mode mapping action desc; }; - nmap = mapping: action: desc: - { inherit mapping action desc; }; - unmap = mapping: - { inherit mapping; action = ""; }; - blacklist = given: + ''; + tempestBufnr = + given: + lua '' + function(_, bufnr) + return D.tempest.configure( + ${encode given}, + { bufnr = bufnr} + ) + end + ''; + keymap = mode: mapping: action: desc: { + inherit + mode + mapping + action + desc + ; + }; + nmap = mapping: action: desc: { inherit mapping action desc; }; + unmap = mapping: { + inherit mapping; + action = ""; + }; + blacklist = + given: assert h.hasType (types.oneOrMany types.neovimEnv) given; - lua /* lua */ '' + # lua + lua '' D.tempest.blacklist(${encode given}) ''; - whitelist = given: + whitelist = + given: assert h.hasType (types.oneOrMany types.neovimEnv) given; - lua /* lua */ '' + # lua + lua '' D.tempest.whitelist(${encode given}) ''; # :p => expands path @@ -182,11 +270,17 @@ let notmp = lua ''vim.fn.expand("%:p:h") ~= "/tmp"''; # }}} # {{{ Main config generation entrypoint - generateConfig = rawConfig: + generateConfig = + rawConfig: assert h.hasType types.neovimConfig rawConfig; let - config = { lazy = { }; pre = { }; post = { }; } // rawConfig; - collectNixDeps = lazyModule: + config = { + lazy = { }; + pre = { }; + post = { }; + } // rawConfig; + collectNixDeps = + lazyModule: if lazyModule ? dependencies then let nix = lazyModule.dependencies.nix or [ ]; @@ -202,12 +296,10 @@ let (lib.mapAttrsToList (_: collectNixDeps)) lib.lists.flatten ]; - processedLazyModules = - lib.mapAttrs - (name: module: { inherit name; } // module // { - dependencies = (module.dependencies or { }).lua or null; - }) - config.lazy; + processedLazyModules = lib.mapAttrs ( + name: module: + { inherit name; } // module // { dependencies = (module.dependencies or { }).lua or null; } + ) config.lazy; luaConfig = '' local M = {} @@ -218,7 +310,7 @@ let -- {{{ Pre-plugin config M.pre = ${encode (foldedList config.pre)} -- }}} - -- {{{ Lazy modules + -- {{{ Lazy modules M.lazy = ${encode (foldedList processedLazyModules)} D.tempest.prepareLazySpec(M.lazy) -- }}} @@ -229,7 +321,10 @@ let return M ''; in - { inherit dependencies; lua = luaConfig; }; + { + inherit dependencies; + lua = luaConfig; + }; # }}} }; in