-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
94 lines (88 loc) · 2.59 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
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
version = cargoToml.package.version;
name = cargoToml.package.name;
in
rec {
devShell = pkgs.mkShell {
packages = with pkgs; [
cargo
rustc
rust-analyzer
jq.lib
openssl.dev
sqlite
oniguruma
pkgconfig
];
JQ_LIB_DIR = "${pkgs.jq.lib}";
DATABASE_URL = "sqlite:db/oneroster.db";
shellHook = ''
if [ ! -f db/oneroster.db ]; then
sqlite3 db/oneroster.db < db/schema.sql
sqlite3 db/oneroster.db < db/init.sql
fi
'';
};
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = name;
version = version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
pkgs.pkgconfig
pkgs.openssl.dev
pkgs.sqlite
];
buildInputs = [
pkgs.jq.lib
pkgs.oniguruma
];
preConfigure = ''
sqlite3 db/oneroster.db < db/schema.sql
sqlite3 db/oneroster.db < db/init.sql
'';
doCheck = false;
JQ_LIB_DIR = "${pkgs.jq.lib}";
DATABASE_URL = "sqlite:db/oneroster.db";
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
};
packages.docker = pkgs.dockerTools.buildImage {
name = name;
tag = version;
copyToRoot = pkgs.buildEnv {
name = name;
paths = [
packages.default
pkgs.dockerTools.caCertificates
pkgs.dockerTools.fakeNss
];
};
config.EntryPoint = [ "/bin/oneroster" ];
};
apps.dockerPush = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "dockerPush" ''
set -eu
nix build .#docker -o ${name}
REPO="git.bgw.dev/bgw/${name}:${version}"
${pkgs.skopeo}/bin/skopeo copy \
--insecure-policy \
--dest-creds "bgw:$CI_PACKAGE_WRITE" \
docker-archive:${name} \
docker://$REPO
'';
};
}
);
}