This repository has been archived by the owner on May 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
130 lines (112 loc) · 3.67 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
{
description = "isntweb super mega website";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
naersk.url = "github:nix-community/naersk";
};
outputs = { self, nixpkgs, rust-overlay, utils, naersk, ... }:
# utils.lib.eachDefaultSystem (system:
let
system = "x86_64-linux";
inherit (lib) attrValues;
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlay ];
};
lib = pkgs.lib;
rust_channel = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
naersk-lib = naersk.lib."${system}".override {
cargo = rust_channel;
rustc = rust_channel;
};
# The rust server package
isntweb-home-server = naersk-lib.buildPackage {
pname = "isntweb-home-server";
root = ./.;
};
# The static front-end as a derivation
static-sources = pkgs.stdenv.mkDerivation {
name = "isntweb-sources";
src = ./.;
phases = "installPhase";
installPhase = ''
mkdir -p $out/static
cp -r ${./static}/* $out/static
'';
};
# a script executable passing the root dir to the package
isntweb-bundle = pkgs.writeShellScriptBin
# port is the second arg
"isntweb-serve" "${isntweb-home-server}/bin/isntweb-home-server ${static-sources}/static 6200";
# the nixos module taht runs the whole deal!
isntwebHomeModule = { config, options, lib, pkgs, ... }:
with lib;
let cfg = config.isntweb-home;
user = "isntweb-home";
group = "isntweb-home";
in {
options.isntweb-home = with lib; {
enable = mkEnableOption false;
};
config = mkIf cfg.enable {
# create a user in which to run the web app
users.users.isntweb-home = {
inherit group;
isSystemUser = true;
};
users.groups.isntweb-home = {};
# configure a systemd service to launh it
systemd.services.isntweb-home = {
enable = true;
aliases = [ "isntweb-home" ];
after = [ "network.target" ];
path = with pkgs; [ openssl ];
serviceConfig = {
User = user;
Group = group;
ExecStart = "${isntweb-bundle}/bin/isntweb-serve";
PrivateTmp = "true";
PrivateDevices = "true";
ProtectHome = "true";
ProtectSystem = "strict";
StateDirectory = "isntweb-home";
};
wantedBy = [ "multi-user.target" ];
};
};
}
;
in rec {
# packages.isntweb-home = isntweb-bundle;
# apps.isntweb-home = packages.isntweb-home;
defaultPackage.${system} = isntweb-bundle;
nixosModules.isntweb-home = isntwebHomeModule;
nixosModule = nixosModules.isntweb-home;
devShell.${system} = with pkgs; mkShell {
buildInputs = [
# all of rust unstable
rust_channel
cargo
rust-analyzer
# fast linking
lld
# not sure
pkg-config
# for tbe web
wasm-pack
# web development
nodejs
nodePackages.yarn
# client side
nixpkgs-fmt
leiningen
clojure
clojure-lsp
];
# don't warn for dead code, unused imports or unused variables
RUSTFLAGS = "-A dead_code -A unused_imports -A unused_variables";
};
};
}