diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 18d5ea8..76761ae 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,18 +1,14 @@ -name: Build example and run tests +name: Build and test example flake on: pull_request: - push: - branches: - - main jobs: - tests: + check-pr: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v25 with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - - run: nix build ./example - - run: nix run ./example#test + - run: nix run .#check-local diff --git a/.github/workflows/update-example.yaml b/.github/workflows/update-example.yaml index 93d7e54..7df29fd 100644 --- a/.github/workflows/update-example.yaml +++ b/.github/workflows/update-example.yaml @@ -1,4 +1,4 @@ -name: Update example flake +name: Update, build and test example flake on: push: @@ -17,6 +17,7 @@ jobs: with: github_access_token: ${{ secrets.GITHUB_TOKEN }} - run: nix flake lock --update-input neovim-nix ./example + - run: nix run .#check - run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'willruggiano@users.noreply.github.com' diff --git a/flake.nix b/flake.nix index 0b471ed..0e433b9 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,21 @@ system, ... }: { + apps = { + check.program = pkgs.writeShellApplication { + name = "check"; + text = '' + nix run ./example#test + ''; + }; + check-local.program = pkgs.writeShellApplication { + name = "check-local"; + text = '' + nix run --override-input neovim-nix path:./. ./example#test + ''; + }; + }; + devShells.default = pkgs.mkShell { name = "neovim.nix"; shellHook = '' diff --git a/modules/default.nix b/modules/default.nix index 0f8bf6d..648f588 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -4,7 +4,7 @@ ... }: let inherit (flake-parts-lib) mkPerSystemOption; - inherit (lib) concatStringsSep makeBinPath mapAttrsToList mkOption optional types unique; + inherit (lib) concatStringsSep makeBinPath mapAttrsToList mkOption optional optionals types unique; mkNeovimEnv = { config, @@ -12,50 +12,29 @@ ... }: let cfg = config.neovim; - - # TODO: Use wrapProgram? - wrapper = pkgs.writeTextFile rec { + toEnvVar = name: value: ''export ${name}="''${${name}:-${toString value}}"''; + in + pkgs.writeShellApplication { name = "nvim"; - executable = true; - destination = "/bin/${name}"; - text = concatStringsSep "\n" ([ - '' - #!${pkgs.runtimeShell} - set -o errexit - set -o nounset - set -o pipefail - '' - ] + text = concatStringsSep "\n" ( + # NOTE: We don't use writeShellApplication's `runtimeEnv` argument since + # it does not allow the specified environment variables to be overridden + # (e.g. by direnv). + optionals (cfg.env != {}) (mapAttrsToList toEnvVar cfg.env) + # NOTE: Similar sentiment here. We don't use writeShellApplication's + # `runtimeInputs` because it would *prepend* `cfg.paths`. What we want, + # rather, is to *append* them such that they too can be overridden. ++ optional (cfg.paths != []) '' export PATH="$PATH:${makeBinPath (unique cfg.paths)}" '' - ++ [ - '' - ${concatStringsSep "\n" (mapAttrsToList (name: value: ''export ${name}="''${${name}:-${toString value}}"'') cfg.env)} - '' - ] ++ [ '' export NVIM_RPLUGIN_MANIFEST="${config.neovim.build.rplugin}/rplugin.vim" ${cfg.package}/bin/nvim -u ${cfg.build.initlua} "$@" '' - ]); - - checkPhase = '' - runHook preCheck - ${pkgs.stdenv.shellDryRun} "$target" - ${pkgs.shellcheck}/bin/shellcheck "$target" - runHook postCheck - ''; - - meta.mainProgram = name; - }; - in - pkgs.buildEnv { - name = "neovim-env"; - paths = [wrapper]; - meta.mainProgram = "nvim"; - passthru = { + ] + ); + derivationArgs.passthru = { inherit (config.neovim.build) initlua plugins; }; };