Skip to content

Commit c930fb0

Browse files
committed
use flake-parts
1 parent 2c46287 commit c930fb0

4 files changed

Lines changed: 131 additions & 114 deletions

File tree

flake.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 10 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,91 +3,17 @@
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6-
flake-utils.url = "github:numtide/flake-utils";
6+
flake-parts.url = "github:hercules-ci/flake-parts";
77
};
88

9-
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let
10-
pkgs = inputs.nixpkgs.legacyPackages.${system};
11-
12-
luarcSchemaVersion = "v3.18.2";
13-
luaLSVscodeLuaBaseUrl = "https://raw.githubusercontent.com/LuaLS/vscode-lua/refs/tags/${luarcSchemaVersion}";
14-
luarcSchema = pkgs.fetchurl {
15-
url = "${luaLSVscodeLuaBaseUrl}/setting/schema.json";
16-
sha256 = "sha256-9iIVguhV85jc7sESYwEnkxEH849HFEtv/SaXwLQBH4Q=";
17-
};
18-
luarcSchemaLicense = pkgs.fetchurl {
19-
url = "${luaLSVscodeLuaBaseUrl}/LICENSE";
20-
sha256 = "sha256-cHSCTv/fzh1DUBOflSpHBnFhB+ImldbVEyeCzeG40SY=";
21-
};
22-
23-
runtimePrograms = [
24-
pkgs.fd pkgs.ripgrep
25-
pkgs.gcc pkgs.gitMinimal
26-
pkgs.nil pkgs.tree-sitter
27-
pkgs.curl pkgs.vscode-js-debug
28-
pkgs.gnutar pkgs.lua-language-server
29-
pkgs.gnumake pkgs.yaml-language-server
30-
pkgs.lemminx pkgs.vscode-langservers-extracted
31-
];
32-
33-
patchedNeovim = pkgs.neovim-unwrapped.overrideAttrs (old: {
34-
postPatch = (old.postPatch or "") + ''
35-
substituteInPlace src/nvim/version.c \
36-
--replace-fail '"│ ╲ ││",' '"h i ",' \
37-
--replace-fail '"││╲╲││",' '"hhh v v i mmm",' \
38-
--replace-fail '"││ ╲ │",' '"h h v i mmm",' \
39-
--replace-fail 'N_(NVIM_VERSION_LONG),' '"hvim " NVIM_VERSION_MEDIUM,'
40-
substituteInPlace src/nvim/version.c \
41-
--replace-fail " int attr = 0;" " int attr = *p == 'h' ? string_attr : (*p == ' ' ? 0 : special_attr);"
42-
'';
43-
});
44-
45-
wrappedNeovim = pkgs.wrapNeovim patchedNeovim {
46-
extraName = "-hvim";
47-
wrapperArgs = [
48-
"--set" "NVIM_APPNAME" "hvim"
49-
"--suffix" "PATH" ":" (pkgs.lib.makeBinPath runtimePrograms)
50-
];
9+
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
10+
systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-linux" ];
11+
perSystem = { pkgs, ... }: let
12+
hvim = pkgs.callPackage ./package.nix { };
13+
in {
14+
packages.hvim = hvim;
15+
packages.default = hvim;
16+
apps.hvim-luarc.program = "${hvim}/bin/hvim-luarc";
5117
};
52-
53-
hvim = pkgs.runCommand "hvim-${pkgs.lib.getVersion pkgs.neovim-unwrapped}" {
54-
meta = wrappedNeovim.meta // {
55-
mainProgram = "hvim";
56-
description = "A personal Neovim wrapper built with Nix.";
57-
homepage = "https://github.com/hooreique/hvim";
58-
license = pkgs.lib.unique ([ pkgs.lib.licenses.mit ] ++ (pkgs.lib.toList wrappedNeovim.meta.license));
59-
};
60-
nativeBuildInputs = [ pkgs.makeWrapper ];
61-
} ''
62-
mkdir -p "$out/bin"
63-
mkdir -p "$out/share"
64-
mkdir -p "$out/share/licenses/hvim"
65-
cp "${./LICENSE}" "$out/share/licenses/hvim/LICENSE"
66-
cp "${luarcSchemaLicense}" "$out/share/licenses/hvim/LuaLS-vscode-lua-LICENSE"
67-
cp "${luarcSchema}" "$out/share/luarc-schema.json"
68-
cat > "$out/share/luarc.hvim-config.json" <<EOF
69-
{
70-
"\''$schema": "file://$out/share/luarc-schema.json",
71-
"runtime": {
72-
"version": "LuaJIT"
73-
},
74-
"workspace": {
75-
"library": [
76-
"${patchedNeovim}/share/nvim/runtime/lua",
77-
"${patchedNeovim}/share/nvim/runtime/lua/vim/lsp"
78-
]
79-
}
80-
}
81-
EOF
82-
makeWrapper "${wrappedNeovim}/bin/nvim" "$out/bin/hvim" --prefix PATH : "$out/bin"
83-
cat > "$out/bin/hvim-luarc" <<EOF
84-
#!${pkgs.runtimeShell}
85-
exec ${pkgs.coreutils}/bin/cat "$out/share/luarc.hvim-config.json"
86-
EOF
87-
chmod +x "$out/bin/hvim-luarc"
88-
'';
89-
in {
90-
packages.hvim = hvim;
91-
packages.default = hvim;
92-
});
18+
};
9319
}

package.nix

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
fd, lemminx, makeWrapper,
3+
gcc, ripgrep, tree-sitter,
4+
lib, fetchurl, runtimeShell,
5+
nil, coreutils, vscode-js-debug,
6+
curl, gitMinimal, neovim-unwrapped,
7+
gnutar, runCommand, lua-language-server,
8+
gnumake, wrapNeovim, yaml-language-server,
9+
vscode-langservers-extracted,
10+
}:
11+
12+
let
13+
luarcSchemaVersion = "v3.18.2";
14+
luaLSVscodeLuaBaseUrl = "https://raw.githubusercontent.com/LuaLS/vscode-lua/refs/tags/${luarcSchemaVersion}";
15+
luarcSchema = fetchurl {
16+
url = "${luaLSVscodeLuaBaseUrl}/setting/schema.json";
17+
sha256 = "sha256-9iIVguhV85jc7sESYwEnkxEH849HFEtv/SaXwLQBH4Q=";
18+
};
19+
luarcSchemaLicense = fetchurl {
20+
url = "${luaLSVscodeLuaBaseUrl}/LICENSE";
21+
sha256 = "sha256-cHSCTv/fzh1DUBOflSpHBnFhB+ImldbVEyeCzeG40SY=";
22+
};
23+
24+
runtimePrograms = [
25+
fd gnutar gitMinimal
26+
gcc gnumake tree-sitter
27+
nil lemminx vscode-js-debug
28+
curl ripgrep lua-language-server
29+
yaml-language-server
30+
vscode-langservers-extracted
31+
];
32+
33+
patchedNeovim = neovim-unwrapped.overrideAttrs (old: {
34+
postPatch = (old.postPatch or "") + ''
35+
substituteInPlace src/nvim/version.c \
36+
--replace-fail '"│ ╲ ││",' '"h i ",' \
37+
--replace-fail '"││╲╲││",' '"hhh v v i mmm",' \
38+
--replace-fail '"││ ╲ │",' '"h h v i mmm",' \
39+
--replace-fail 'N_(NVIM_VERSION_LONG),' '"hvim " NVIM_VERSION_MEDIUM,'
40+
substituteInPlace src/nvim/version.c \
41+
--replace-fail " int attr = 0;" " int attr = *p == 'h' ? string_attr : (*p == ' ' ? 0 : special_attr);"
42+
'';
43+
});
44+
45+
wrappedNeovim = wrapNeovim patchedNeovim {
46+
extraName = "-hvim";
47+
wrapperArgs = [
48+
"--set" "NVIM_APPNAME" "hvim"
49+
"--suffix" "PATH" ":" (lib.makeBinPath runtimePrograms)
50+
];
51+
};
52+
in
53+
54+
runCommand "hvim-${lib.getVersion neovim-unwrapped}"
55+
{
56+
meta = {
57+
mainProgram = "hvim";
58+
description = "A personal Neovim wrapper built with Nix.";
59+
homepage = "https://github.com/hooreique/hvim";
60+
license = lib.licenses.mit;
61+
};
62+
nativeBuildInputs = [ makeWrapper ];
63+
}
64+
''
65+
mkdir -p "$out/bin"
66+
mkdir -p "$out/share"
67+
mkdir -p "$out/share/licenses/hvim"
68+
cp "${./LICENSE}" "$out/share/licenses/hvim/LICENSE"
69+
cp "${luarcSchemaLicense}" "$out/share/licenses/hvim/LuaLS-vscode-lua-LICENSE"
70+
cp "${luarcSchema}" "$out/share/luarc-schema.json"
71+
cat > "$out/share/luarc.hvim-config.json" <<EOF
72+
{
73+
"\''$schema": "file://$out/share/luarc-schema.json",
74+
"runtime": {
75+
"version": "LuaJIT"
76+
},
77+
"workspace": {
78+
"library": [
79+
"${patchedNeovim}/share/nvim/runtime/lua",
80+
"${patchedNeovim}/share/nvim/runtime/lua/vim/lsp"
81+
]
82+
}
83+
}
84+
EOF
85+
makeWrapper "${wrappedNeovim}/bin/nvim" "$out/bin/hvim" --prefix PATH : "$out/bin"
86+
cat > "$out/bin/hvim-luarc" <<EOF
87+
#!${runtimeShell}
88+
exec ${coreutils}/bin/cat "$out/share/luarc.hvim-config.json"
89+
EOF
90+
chmod +x "$out/bin/hvim-luarc"
91+
''

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ lemminx
6666
vscode-js-debug
6767
```
6868

69-
Add tools to `runtimePrograms` in `flake.nix` when they should be visible from inside `hvim`.
69+
Add tools to `runtimePrograms` in `package.nix` when they should be visible from inside `hvim`.
7070

7171
## hvim-luarc
7272

73-
The package also provides:
73+
The flake exposes `hvim-luarc` as an app:
7474

7575
```sh
76-
hvim-luarc
76+
nix run .#hvim-luarc
7777
```
7878

7979
It prints the generated LuaLS config for this wrapper.
8080

81-
After building:
81+
The built `hvim` package also contains the helper executable:
8282

8383
```sh
8484
./result/bin/hvim-luarc

0 commit comments

Comments
 (0)