summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 48e7350ff65eb05141cc81e3c329e214a875efe0 (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
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
{
  description = "Getchoo's website";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-filter.url = "github:numtide/nix-filter";
  };

  outputs =
    {
      self,
      nixpkgs,
      nix-filter,
    }:
    let
      inherit (nixpkgs) lib;
      systems = lib.systems.flakeExposed;

      forAllSystems = lib.genAttrs systems;
      nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
    in
    {
      apps = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};
        in
        {
          serve = {
            type = "app";
            program = toString (
              pkgs.runCommand "serve-website" { nativeBuildInputs = [ pkgs.zola ]; } ''
                tmpdir=$(mktemp -d)
                cd ${self.packages.${system}.website.src}
                zola serve --force --output-dir "$tmpdir"
              ''
            );
          };
        }
      );

      devShells = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};
        in
        {
          default = pkgs.mkShellNoCC {
            packages = [
              pkgs.zola

              pkgs.actionlint
              pkgs.deadnix
              pkgs.nil
              pkgs.statix
              self.formatter.${system}
            ];
          };
        }
      );

      formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);

      packages = forAllSystems (
        system:
        let
          pkgs = nixpkgsFor.${system};
        in
        {
          website = pkgs.callPackage (
            {
              lib,
              stdenvNoCC,
              writeShellApplication,
              zola,
            }:

            stdenvNoCC.mkDerivation {
              pname = "getchoo-website";
              version = self.shortRev or self.dirtyShortRev or "unknown";

              src = nix-filter.lib.filter {
                root = self;
                include = [
                  "config.toml"
                  "content"
                  "highlight_themes"
                  "sass"
                  "static"
                  "templates"
                ];
              };

              nativeBuildInputs = [ zola ];

              postBuild = "zola build --output-dir $out";

              dontConfigure = true;
              dontInstall = true;
              dontFixup = true;

              meta = {
                homepage = "https://github.com/getchoo/website";
                license = lib.licenses.mit;
                maintainers = with lib.maintainers; [ getchoo ];
              };
            }
          ) { };

          default = self.packages.${system}.website;
        }
      );
    };
}