summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 98c8949cb378e5122d3ab6f36c973777395622bd (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
  description = "Main library for my webpage";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
    flake-parts.url = "github:hercules-ci/flake-parts";
    systems.url = "github:nix-systems/default";
    nix-filter.url = "github:numtide/nix-filter";
    www-assets = {
      url = "git://git.mathematicaster.org/www/assets.git";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-parts.follows = "flake-parts";
      };
    };
  };

  outputs = inputs@{self, flake-parts, nixpkgs, nix-filter, ... }: flake-parts.lib.mkFlake { inherit self inputs; } {
    systems = import inputs.systems;

    flake.lib = {
      rubberWith = { pkgs, texPath }: pkgs.symlinkJoin rec {
        name = "rubber";
        nativeBuildInputs = [
          pkgs.makeWrapper
        ];
        paths = [
          pkgs.rubber
        ];
        postBuild = ''
          wrapProgram "$out/bin/rubber-pipe" --set PATH : ${pkgs.lib.makeBinPath texPath}
        '';
      };

      hakyllWith = { pkgs, site, paths ? [], texPath ? null }: pkgs.symlinkJoin {
        inherit (site) name;
        nativeBuildInputs = [
          pkgs.makeWrapper
        ];
        paths = [
          (pkgs.haskell.lib.compose.justStaticExecutables site)
          pkgs.rsync
        ] ++ paths ++ pkgs.lib.optional (texPath != null) (self.lib.rubberWith { inherit pkgs texPath; });
        postBuild = ''
          for x in $out/bin/*; do
            wrapProgram "$x" --prefix PATH : ${pkgs.lib.makeBinPath paths}
          done
        '';
      };
    };

    flake.overlays.default = final: prev: {
      haskellPackages = prev.haskellPackages.extend (hfinal: _hprev: {
        www-main = let
          src = nix-filter {
            root = ./.;
            include = [
              "src"
              "app"
              "templates"
              "package.yaml"
              "www-main.cabal"
            ];
          };
        in hfinal.callCabal2nix "www-main" src {};
      });
    };

    perSystem = { self', config, pkgs, system, ... }: {
      _module.args.pkgs = import nixpkgs {
        inherit system;
        overlays = [
          self.overlays.default
          inputs.www-assets.overlays.default
        ];
      };
      # haskellProjects.default = {
      #   projectRoot = ./.;
      # };

      packages = rec {
        default = www-main-exe;
        www-main-exe = self.lib.hakyllWith {
          inherit pkgs;
          # site = config.packages.www-main;
          site = pkgs.haskellPackages.www-main;
          texPath = [
            pkgs.texlive.combined.scheme-full
          ];
        };
        site = pkgs.runCommandLocal "build-site" {} ''
          mkdir $out
          cd $out
          cp -r ${./data} data
          cp -r ${./www} www
          mkdir assets

          ${www-main-exe}/bin/www-main rebuild
        '';
        deploy = pkgs.writeShellApplication {
          name = "deploy";
          text = ''
            cd ${site}
            ${www-main-exe}/bin/www-main deploy
          '';
        };
        mkassets = pkgs.writeShellApplication {
          name = "mkassets";
          text = ''
            toplevel="$(git rev-parse --show-toplevel)"
            cd "$toplevel"

            dir="$toplevel/assets"
            rm -rf "$dir"
            cp -r "${pkgs.www-assets}" "$dir"
            chmod -R +w "$dir"
          '';
        };
      };

      devShells.default = pkgs.haskellPackages.shellFor {
        packages = _: [];
        withHoogle = true;
        buildInputs = with pkgs.haskellPackages; [
          cabal-install
          hpack
          hlint
          fast-tags
          pkgs.haskell-language-server
          pkgs.zlib
          pkgs.icu
        ];
      };
   };
  };

  # outputs = { self, nixpkgs, flake-utils, nix-filter, ... }: {
  #
  #   overlays.default = import ./nix/overlay.nix { inherit nix-filter; };
  #
  # } // flake-utils.lib.eachDefaultSystem (system: let
  #     pkgs = import nixpkgs {
  #       inherit system;
  #       overlays = [ self.overlays.default ];
  #     };
  #   in {
  #     packages = {
  #       inherit (pkgs) www-main;
  #       default = pkgs.www-main;
  #     };
  #
  #     devShells.default = pkgs.haskellPackages.shellFor {
  #       packages = _: [];
  #       # packages = p: [ p.www-main ];
  #       withHoogle = true;
  #       buildInputs = with pkgs.haskellPackages; [
  #         cabal-install
  #         hpack
  #         hlint
  #         fast-tags
  #         pkgs.haskell-language-server
  #         pkgs.zlib
  #         pkgs.icu
  #       ];
  #     };
  #   });
}