summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 66caa9270afb33e73d2f81a4dc02ad7db3207281 (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
{
  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";
  };

  outputs = inputs@{self, flake-parts, nixpkgs, ... }: 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 = ''
          for x in $out/bin/*; do
            wrapProgram "$x" --prefix PATH : ${pkgs.lib.makeBinPath paths}
          done
        '';
      };

      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 = ./.;
        in hfinal.callCabal2nix "www-main" src {};
      });
    };

    perSystem = { self', config, pkgs, system, ... }: {
      _module.args.pkgs = import nixpkgs {
        inherit system;
        overlays = [ self.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
          ];
        };
      };

      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
  #       ];
  #     };
  #   });
}