about summary refs log tree commit diff
path: root/flake.nix
blob: 38edac06598b857da2933b0c67e9c77948d8e113 (plain) (blame)
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
{
  description = "Personal XMonad configuration.";

  inputs = {
    nixpkgs = {
      type = "github";
      owner = "NixOS";
      repo = "nixpkgs";
      ref = "nixpkgs-unstable";
    };

    flake-utils = {
      type = "github";
      owner = "numtide";
      repo = "flake-utils";
      ref = "master";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    flake-compat = {
      type = "github";
      owner = "edolstra";
      repo = "flake-compat";
      ref = "master";
      flake = false;
    };

    pre-commit-hooks = {
      type = "github";
      owner = "cachix";
      repo = "pre-commit-hooks.nix";
      ref = "master";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
      };
    };
  };

  outputs = inputs:
    with inputs;
    let name = "xmonad-ng";
    in flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          inputs = null;
          nixpkgs = nixpkgs.legacyPackages.${system};
        };

        package = { returnShellEnv ? false }:
          with pkgs;
          haskellPackages.developPackage {
            inherit name returnShellEnv;
            root = ./.;
            overrides = _: _:
              with haskellPackages; {
                xmonad = xmonad_0_17_0;
                xmonad-contrib = xmonad-contrib_0_17_0;
              };
            modifier = drv:
              haskell.lib.addBuildTools drv (with haskellPackages; [
                brittany
                cabal-install
                haskell-language-server
                hlint
                hpack
                stack
              ]);
          };
      in {
        packages.${name} = package { };
        defaultPackage = self.packages.${system}.${name};

        checks.preCommit = pre-commit-hooks.lib.${system}.run {
          src = ./.;
          hooks = {
            nix-linter.enable = true;
            nixfmt.enable = true;
            hpack.enable = true;
            hlint.enable = true;
            yamllint.enable = true;
            brittany.enable = true;
            shellcheck.enable = true;
            shfmt = {
              enable = true;
              name = "shfmt";
              entry = "${pkgs.shfmt}/bin/shfmt -s -w";
              types = [ "shell" ];
            };
            prettier = {
              enable = true;
              types = [ ];
              files = "\\.((yaml)|\\d)$";
            };
          };
        };

        devShells = {
          ${name} = package { returnShellEnv = true; };
          preCommit = pkgs.mkShell {
            inherit (self.checks.${system}.preCommit) shellHook;
          };
        };
        devShell = self.devShells.${system}.${name};
      }) // {
        # FIXME This exposes an attribute set of "system.package" thus making
        # importing this package from the overlay to look like this
        # "pkgs.xmonad-ng.${system}" which is fucking stupid. I have to fix that
        # somehow.
        overlay = _: _: { ${name} = self.defaultPackage; };
      };
}

Consider giving Nix/NixOS a try! <3