-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
139 lines (128 loc) · 3.69 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Bulding Rust
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
# Tags sources
neovim = {
url = "github:neovim/neovim?dir=contrib";
inputs.nixpkgs.follows = "nixpkgs";
};
vim = {
url = "github:vim/vim";
flake = false;
};
};
outputs =
{ self
, nixpkgs
, flake-utils
, vim
, neovim
, crane
, fenix
, advisory-db
}:
flake-utils.lib.eachDefaultSystem (system:
let
pname = "tg-vimhelpbot";
pkgs = import nixpkgs { inherit system; };
rust = fenix.packages."${system}".stable.toolchain;
crane-lib = (crane.mkLib pkgs).overrideToolchain rust;
src = crane-lib.cleanCargoSource ./.;
cargoArtifacts = crane-lib.buildDepsOnly { inherit src; };
crate = crane-lib.buildPackage { inherit src cargoArtifacts; };
vim-helptags = derivation {
name = "vim-helptags";
inherit system;
builder = pkgs.writeScript "vim-helptags-builder.sh" ''
#!/bin/sh
set -eu
cp ${vim}/runtime/doc/tags $out
'';
PATH = "${pkgs.coreutils}/bin";
};
neovim-pkg = neovim.packages.${system}.neovim;
neovim-helptags = derivation {
name = "neovim-helptags";
inherit system;
builder = pkgs.writeScript "neovim-helptags-builder.sh" ''
#!/bin/sh
cp "${neovim-pkg}"/share/nvim/runtime/doc/tags $out
'';
PATH = "${pkgs.coreutils}/bin";
};
tags-env = {
VIM_DB_PATH = vim-helptags;
NEOVIM_DB_PATH = neovim-helptags;
CUSTOM_DB_PATH = ./customtags;
};
tags-env-commands = pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList
(key: value:
''
if [ -z "''${${key}:-}" ]; then
export ${key}=${pkgs.lib.escapeShellArg value}
fi
''
)
tags-env
);
start-script = ''
${tags-env-commands}
exec ${crate}/bin/${pname}
'';
in
rec {
checks = {
${pname} = crate;
"${pname}-fmt" = crane-lib.cargoFmt { inherit src; };
"${pname}-audit" = crane-lib.cargoAudit { inherit src advisory-db; };
"${pname}-clippy" = crane-lib.cargoClippy {
inherit src cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
};
};
packages.default = crate;
packages.${pname} = crate;
apps.default = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin pname start-script;
};
nixosModules.default = with pkgs.lib; { config, ... }:
let
cfg = config.services.tg-vimhelpbot;
in
{
options.services.tg-vimhelpbot = {
enable = mkEnableOption "Vim :help bot for Telegram";
envFile = mkOption {
type = types.str;
default = "/etc/tg-vimhelpbot.env";
};
};
config = mkIf cfg.enable {
systemd.services.tg-vimhelpbot = {
script = start-script;
wantedBy = [ "multi-user.target" ];
serviceConfig.EnvironmentFile = cfg.envFile;
};
};
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues checks;
nativeBuildInputs = [ rust ];
};
}
);
}