summaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: 370c43ba6c6556fe5510808427bd73f6707734ae (plain)
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
{
  description = "My knowledge";

  nixConfig = {
    extra-substituters = "https://srid.cachix.org";
    extra-trusted-public-keys = "srid.cachix.org-1:3clnql5gjbJNEvhA/WQp7nrZlBptwpXnUk6JAv8aB2M=";
  };

  inputs = {
    emanote.url = "github:srid/emanote";
    nixpkgs.follows = "emanote/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, emanote, flake-utils, nixpkgs, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
      in
      rec {
        apps.deploy = flake-utils.lib.mkApp {
          name = "deploy";
          drv = pkgs.writeScriptBin "deploy" ''
            #!${pkgs.runtimeShell}
            rsync -arP ${packages.default}/public as:/srv/knowledge.beyermatthi.as/
          '';
        };

        apps.serve = flake-utils.lib.mkApp {
          name = "serve";
          drv = pkgs.writeScriptBin "serve" ''
            #!${pkgs.runtimeShell}
            PORT=8008 ${emanote.packages."${system}".default}/bin/emanote
          '';
        };

        packages.default = pkgs.stdenv.mkDerivation {
          name = "knowledge";

          src =
            let
              nixFilter = path: _type: !pkgs.lib.hasSuffix ".nix" path;
              extraFiles = path: _type: !(builtins.any (n: pkgs.lib.hasSuffix n path) [ ".github" ".sh" ]);
              filterPath = path: type: builtins.all (f: f path type) [
                nixFilter
                extraFiles
                pkgs.lib.cleanSourceFilter
              ];
            in
            pkgs.lib.cleanSourceWith {
              src = ./.;
              filter = filterPath;
            };

          buildPhase = ''
            mkdir -p $out/public/
            ${emanote.packages."${system}".default}/bin/emanote --allow-broken-links gen $out/public/
          '';

          installPhase = ''true'';
        };

        devShells.default = pkgs.mkShell {
          buildInputs = [
            pkgs.nixpkgs-fmt
            emanote.packages."${system}".default
          ];
        };
      });
}