Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use pkgs.writeShellApplication #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .github/workflows/update-example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update example flake
name: Update, build and test example flake

on:
push:
Expand All @@ -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 '[email protected]'
Expand Down
15 changes: 15 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
51 changes: 15 additions & 36 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,37 @@
...
}: 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,
pkgs,
...
}: 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;
};
};
Expand Down