forked from PierreBeucher/novops
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
134 lines (108 loc) · 3.8 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
{
description = "Novops, the cross-platform secret manager for development and CI environments";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.lib.${system};
commonArgs = {
src = craneLib.cleanCargoSource (craneLib.path ./.);
strictDeps = true;
doCheck = false;
buildInputs = [
pkgs.openssl
];
nativeBuildInputs = [
pkgs.pkg-config
];
};
novopsPackage = craneLib.buildPackage (commonArgs // {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
});
# Check if current system is Darwin (Mac)
# to add packages and buildInputs below
isDarwin = system == "x86_64-darwin" || system == "aarch64-darwin";
devShellPackages = with pkgs; [
# Dev tools
pkg-config
openssl.dev
mdbook
mdbook-linkcheck
json-schema-for-humans
gnumake
zip
gh
nodejs-slim # for npx release-please
cachix
# Module testing
podman
podman-compose
google-cloud-sdk
bitwarden-cli
sops
age
];
devShellBuildInputs = with pkgs; [] ++ lib.optionals isDarwin [
darwin.apple_sdk.frameworks.SystemConfiguration
pkgs.libiconv
];
in {
packages = {
default = novopsPackage;
novops = novopsPackage;
};
devShells = {
default = craneLib.devShell {
packages = devShellPackages;
buildInputs = devShellBuildInputs;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
# Dev shell for cross-compilation with cross
# Can't use directly in default shell: cross somehow conflicts with Crane
cross = pkgs.mkShell {
packages = devShellPackages ++ [
pkgs.cargo-cross
pkgs.rustup
];
buildInputs = devShellBuildInputs;
};
# Dev shell with Nightly Rust
# Inspired from https://github.com/ipetkov/crane/blob/afdcd41180e3dfe4dac46b5ee396e3b12ccc967a/examples/build-std/flake.nix
nightly = let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
targets = [ "x86_64-unknown-linux-gnu" ];
});
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuidling anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
in craneLib.devShell {
packages = devShellPackages;
buildInputs = devShellBuildInputs;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
};
}
);
}