From e1ce5e9b63ca7f139ae462da92bec6747b83591d Mon Sep 17 00:00:00 2001 From: atagen Date: Mon, 23 Mar 2026 13:15:50 +1100 Subject: [PATCH] fix module --- flake.nix | 123 ++++++++++++++++++++----------------------------- nix/module.nix | 37 +++++---------- 2 files changed, 62 insertions(+), 98 deletions(-) diff --git a/flake.nix b/flake.nix index 90a94f9..64ec763 100644 --- a/flake.nix +++ b/flake.nix @@ -7,89 +7,66 @@ forAllSystems = f: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] ( - system: f (import nixpkgs { inherit system; }) system + system: f (import nixpkgs { inherit system; }) ); in { - devShells = forAllSystems ( - pkgs: sys: { - default = pkgs.mkShell { - packages = with pkgs.ocamlPackages; [ - dune_3 - ocaml - angstrom - angstrom-unix - camlzip - ppx_inline_test - ocaml-lsp - ocamlformat - ocamlformat-rpc-lib - utop - ]; - }; - } - ); + devShells = forAllSystems (pkgs: { + default = pkgs.mkShell { + packages = with pkgs.ocamlPackages; [ + dune_3 + ocaml + angstrom + angstrom-unix + camlzip + ppx_inline_test + ocaml-lsp + ocamlformat + ocamlformat-rpc-lib + utop + ]; + }; + }); - packages = forAllSystems ( - pkgs: sys: { - default = pkgs.ocamlPackages.buildDunePackage { - pname = "inshellah"; - version = "0.1"; - src = ./.; - nativeBuildInputs = [ pkgs.git ]; - buildInputs = with pkgs.ocamlPackages; [ - dune_3 - ocaml - angstrom - angstrom-unix - camlzip - ]; + packages = forAllSystems (pkgs: { + default = pkgs.ocamlPackages.buildDunePackage { + pname = "inshellah"; + version = "0.1"; + src = ./.; + nativeBuildInputs = [ pkgs.git ]; + buildInputs = with pkgs.ocamlPackages; [ + dune_3 + ocaml + angstrom + angstrom-unix + camlzip + ]; - meta.mainProgram = "inshellah"; - - }; - } - ); - - checks = forAllSystems ( - pkgs: sys: - let - # Evaluate a minimal NixOS config that enables the module. - # If the module has infinite recursion, this evaluation will fail. - mockSystem = nixpkgs.lib.nixosSystem { - system = sys; - modules = [ - self.nixosModules.default - { - # Minimal config to make NixOS evaluation happy - boot.loader.grub.device = "nodev"; - fileSystems."/" = { device = "/dev/sda1"; fsType = "ext4"; }; - programs.inshellah.enable = true; - environment.systemPackages = [ pkgs.hello ]; - } - ]; - }; - in - { - module-no-infinite-recursion = pkgs.runCommandLocal "inshellah-module-test" { - # Force evaluation of extraSetup and systemPackages at eval time. - # If the module has infinite recursion, this derivation can't even - # be instantiated. - extraSetupLen = builtins.stringLength mockSystem.config.environment.extraSetup; - syspkgCount = builtins.length mockSystem.config.environment.systemPackages; - } '' - echo "environment.extraSetup length: $extraSetupLen" - echo "environment.systemPackages count: $syspkgCount" - touch $out - ''; - } - ); + meta.mainProgram = "inshellah"; + }; + }); nixosModules.default = - { pkgs, ... }: + { + pkgs, + lib, + config, + ... + }: { imports = [ ./nix/module.nix ]; programs.inshellah.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + programs.inshellah.snippet = '' + let cache_home = if ('XDG_CACHE_HOME' in $env) { "--dir " + $env.XDG_CACHE_HOME } else if ('HOME' in $env) { "--dir " + $env.HOME + '/.cache/inshellah' } else { "" } + let inshellah_complete = {|spans| + ${lib.getExe config.programs.inshellah.package} complete $spans $cache_home --system-dir /run/current-system/sw/${config.programs.inshellah.completionsPath} + } + $env.config.completions.external = { + enable: true + max_results: 100 + completer: $inshellah_complete + } + ''; }; }; } diff --git a/nix/module.nix b/nix/module.nix index 8072a92..c62951b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -30,57 +30,44 @@ in package = lib.mkOption { type = lib.types.package; - description = "The inshellah package to use for indexing completions."; + description = "package to use for indexing completions"; }; completionsPath = lib.mkOption { type = lib.types.str; default = "/share/inshellah"; description = '' - Subdirectory within the merged environment where completion files - are placed. Used as the system-dir for the completer. + subdirectory within the system profile where completion files + are placed. used as --system-dir for the completer. ''; }; ignoreCommands = lib.mkOption { type = lib.types.listOf lib.types.str; - default = []; - example = [ "meat" "problematic-tool" ]; + default = [ ]; + example = [ "problematic-tool" ]; description = '' - List of command names to skip during completion indexing. + list of command names to skip during completion indexing ''; }; + + snippet = lib.mkOption { + type = lib.types.str; + readOnly = true; + }; }; config = lib.mkIf cfg.enable { - environment.pathsToLink = [ cfg.completionsPath ]; - environment.extraSetup = let inshellah = "${cfg.package}/bin/inshellah"; destDir = "$out${cfg.completionsPath}"; - segments = lib.filter (s: s != "") (lib.splitString "/" cfg.completionsPath); - derefPath = lib.concatMapStringsSep "\n " (seg: '' - _cur="$_cur/${seg}" - if [ -L "$_cur" ]; then - _target=$(readlink "$_cur") - rm "$_cur" - mkdir -p "$_cur" - if [ -d "$_target" ]; then - cp -rT "$_target" "$_cur" - chmod -R u+w "$_cur" - fi - fi'') segments; ignoreFile = pkgs.writeText "inshellah-ignore" (lib.concatStringsSep "\n" cfg.ignoreCommands); - ignoreFlag = lib.optionalString (cfg.ignoreCommands != []) " --ignore ${ignoreFile}"; + ignoreFlag = lib.optionalString (cfg.ignoreCommands != [ ]) " --ignore ${ignoreFile}"; in '' - _cur="$out" - ${derefPath} mkdir -p ${destDir} - # Index completions in one pass: - # native generators > manpages > --help fallback if [ -d "$out/bin" ] && [ -d "$out/share/man" ]; then ${inshellah} index "$out" --dir ${destDir}${ignoreFlag} \ 2>/dev/null || true