-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
112 lines (106 loc) · 3.4 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
{
description = "zknotes, a web based zettelkasten";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, naersk }:
let
makeElmPkg = { pkgs, additionalInputs ? [ ], pythonPackages ? (ps: [ ]) }:
pkgs.stdenv.mkDerivation {
name = "zknotes-elm";
src = ./.;
buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import ./elm/elm-srcs.nix;
elmVersion = "0.19.1";
registryDat = ./elm/registry.dat;
} + ''
cd elm
elm-optimize-level-2 src/Main.elm --output=dist/main.js
'';
installPhase = ''
mkdir $out
cp -r dist/* $out
'';
buildInputs = with pkgs;
[
elmPackages.elm
elmPackages.elm-optimize-level-2
] ++ additionalInputs;
};
in
flake-utils.lib.eachDefaultSystem (
system: let
pname = "zknotes";
pkgs = nixpkgs.legacyPackages."${system}";
naersk-lib = naersk.lib."${system}";
elm-stuff = makeElmPkg { inherit pkgs; };
rust-stuff = naersk-lib.buildPackage {
pname = pname;
root = ./.;
buildInputs = with pkgs; [
cargo
rustc
sqlite
pkg-config
openssl.dev
];
};
in
rec {
inherit pname;
# `nix build`
packages.${pname} = pkgs.stdenv.mkDerivation {
nativeBuildInputs = [ pkgs.makeWrapper ];
name = pname;
src = ./.;
# building the 'out' folder
installPhase = ''
mkdir -p $out/share/zknotes/static
mkdir $out/bin
cp -r $src/server/static $out/share/zknotes
cp ${elm-stuff}/main.js $out/share/zknotes/static
cp -r ${rust-stuff}/bin $out
mv $out/bin/zknotes-server $out/bin/.zknotes-server
makeWrapper $out/bin/.zknotes-server $out/bin/zknotes-server --set ZKNOTES_STATIC_PATH $out/share/zknotes/static;
'';
};
defaultPackage = packages.${pname};
# `nix run`
apps.${pname} = flake-utils.lib.mkApp {
drv = packages.${pname};
};
defaultApp = apps.${pname};
# `nix develop`
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cargo
cargo-watch
rustc
rustfmt
rust-analyzer
sqlite
pkg-config
openssl.dev
elm2nix
elmPackages.elm
elmPackages.elm-analyse
elmPackages.elm-doc-preview
elmPackages.elm-format
elmPackages.elm-live
elmPackages.elm-test
elmPackages.elm-upgrade
elmPackages.elm-xref
elmPackages.elm-language-server
elmPackages.elm-verify-examples
elmPackages.elmi-to-json
elmPackages.elm-optimize-level-2
];
};
}
) // {
nixosModules = { zknotes = import ./module.nix; };
};
}