forked from yusdacra/nix-cargo-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
141 lines (126 loc) · 3.86 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
flake = false;
};
parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
mk-naked-shell = {
url = "github:yusdacra/mk-naked-shell";
flake = false;
};
dream2nix = {
url = "github:nix-community/dream2nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-parts.follows = "parts";
devshell.follows = "";
alejandra.follows = "";
all-cabal-json.follows = "";
flake-utils-pre-commit.follows = "";
ghc-utils.follows = "";
gomod2nix.follows = "";
mach-nix.follows = "";
poetry2nix.follows = "";
pre-commit-hooks.follows = "";
nix-pypi-fetcher.follows = "";
pruned-racket-catalog.follows = "";
};
};
};
outputs = {parts, ...} @ inp: let
l = inp.nixpkgs.lib // builtins;
flakeModuleNciOnly = {
imports = [./src/default.nix];
config = {
nci._inputs = {
inherit (inp) rust-overlay dream2nix;
};
};
};
flakeModule = {
imports = [
inp.dream2nix.flakeModuleBeta
flakeModuleNciOnly
];
};
in
parts.lib.mkFlake {inputs = inp;} {
imports = [flakeModule];
systems = ["x86_64-linux"];
flake = {
inherit flakeModule flakeModuleNciOnly;
templates = {
default = inp.self.templates.simple;
simple = {
description = "A simple flake.nix template for getting started";
path = ./examples/simple;
welcomeText = ''
To get started:
1. edit the project `relPath` in `flake.nix` to point to your project.
2. change `my-crate` crate name to your own crate name.
3. (optionally) add any other crate (or project) you want to configure.
You're set!
'';
};
simple-crate = {
description = "A simple template with a Cargo crate pre-initialized";
path = ./examples/simple-crate;
welcomeText = ''
To get started, edit crate name in `flake.nix` and `Cargo.toml` to your liking.
And you should be good to go!
'';
};
simple-workspace = {
description = "A simple template with a Cargo workspace pre-initialized";
path = ./examples/simple-workspace;
welcomeText = ''
To get started:
1. edit crate names in `flake.nix` and `Cargo.toml`s to your liking,
2. edit project name in `flake.nix`
You're set!
'';
};
};
};
perSystem = {
config,
pkgs,
system,
...
}: let
testOut = config.nci.outputs."test-crate";
in {
nci.projects."test-crate-project" = {
relPath = "test-crate";
};
nci.crates."test-crate".runtimeLibs = [pkgs.alsa-lib];
apps.format.program = let
configFile = pkgs.writeText "treefmt.toml" ''
[formatter.nix]
command = "${l.getExe pkgs.alejandra}"
includes = ["*.nix"]
'';
script = pkgs.writeScript "format" ''
${l.getExe pkgs.treefmt} --config-file ${configFile} --tree-root ''${PRJ_ROOT:-$PWD}
'';
in
toString script;
checks =
{
"test-crate-devshell" = testOut.devShell;
"test-crate-project-devshell" = config.nci.outputs."test-crate-project".devShell;
}
// (l.mapAttrs'
(
profile: package:
l.nameValuePair "test-crate-${profile}" package
)
testOut.packages);
};
};
}