-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
155 lines (142 loc) · 5.11 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
description = "newsfrwdr";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
crate2nix = {
url = "github:kolloch/crate2nix";
# if you use git dependencies with branches in Cargo.toml, use this fork
# https://github.com/kolloch/crate2nix/issues/205
#url = "github:yusdacra/crate2nix/feat/builtinfetchgit";
flake = false;
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, crate2nix, ... }:
let
# If you change the name here, you must also do it in Cargo.toml
name = "newsfrwdr";
rustChannel = "stable";
in
flake-utils.lib.eachDefaultSystem
(system:
let
# Imports
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlay
(self: super: {
# Because rust-overlay bundles multiple rust packages into one
# derivation, specify that mega-bundle here, so that crate2nix
# will use them automatically.
rustc = self.rust-bin.${rustChannel}.latest.default;
cargo = self.rust-bin.${rustChannel}.latest.default;
})
];
};
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
generatedCargoNix;
# Create the cargo2nix project
project = pkgs.callPackage
(generatedCargoNix {
inherit name;
src = ./.;
})
{
# Individual crate overrides go here
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
# The himalaya crate itself is overriden here. Typically we
# configure non-Rust dependencies (see below) here.
${name} = oldAttrs: {
inherit buildInputs nativeBuildInputs;
};
};
};
# Configuration for the non-Rust dependencies
buildInputs = with pkgs; [ openssl.dev ];
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig ];
in
rec {
packages.${name} = project.rootCrate.build;
# `nix build`
defaultPackage = packages.${name};
# `nix run`
apps.${name} = flake-utils.lib.mkApp {
inherit name;
drv = packages.${name};
};
defaultApp = apps.${name};
# `nix develop`
devShell = pkgs.mkShell
{
inputsFrom = builtins.attrValues self.packages.${system};
buildInputs = buildInputs ++ (with pkgs;
# Tools you need for development go here.
[
cargo-watch
pkgs.rust-bin.${rustChannel}.latest.rust-analysis
pkgs.rust-bin.${rustChannel}.latest.rls
]);
RUST_SRC_PATH = "${pkgs.rust-bin.${rustChannel}.latest.rust-src}/lib/rustlib/src/rust/library";
};
}
) // {
nixosModule = { pkgs, config, ... }:
let
inherit (nixpkgs) lib;
cfg = config.services.newsfrwdr;
in
{
options.services.newsfrwdr = {
enable = lib.mkEnableOption "newsfrwdr service";
config = lib.mkOption {
type = with lib.types; str;
default = "";
example = ''
[inputs.rust-blog]
url = "https://blog.rust-lang.org/feed.xml"
[[outputs.default]]
type = "discord_webhook"
url = "https://discord.com/api/webhooks/abcd..."
'';
description = ''
Config.
Warning: this is stored in cleartext in the Nix store!
Use <option>configFile</option> instead.
'';
};
configFile = lib.mkOption {
type = with lib.types; nullOr path;
default = null;
example = "/run/keys/newsfrwdr-config";
description = ''
Config file.
'';
};
};
config =
let
configFile = if (cfg.configFile != null) then cfg.configFile else
pkgs.writeText "newsfrwdr-config.toml" cfg.config;
in
lib.mkIf cfg.enable {
nixpkgs.overlays = [ self.overlay ];
systemd.services.newsfrwdr = {
description = "newsfrwdr";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${pkgs.newsfrwdr}/bin/newsfrwdr -c ${configFile}";
};
};
};
overlay = final: prev: {
${name} = self.defaultPackage.${prev.system};
};
};
}