about summary refs log tree commit diff
path: root/flake.nix
blob: 5d2d5952df516ebefa2a42ed73f0f4a48b11f4b1 (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
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
{
  description = "personal NixOS configurations";

  inputs = {
    # Nixpkgs, NixOS's official repo
    nixpkgs.url = "github:nixos/nixpkgs/release-22.05";

    futils.url = "github:numtide/flake-utils";

    # We use the unstable nixpkgs repo for some packages.
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";

    emacs-overlay.url = "github:nix-community/emacs-overlay";

    agenix = {
      url = "github:ryantm/agenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nur.url = "github:nix-community/NUR";

    home-manager = {
      url = "github:nix-community/home-manager/release-22.05";
      # We want home-manager to use the same set of nixpkgs as our system.
      inputs.nixpkgs.follows = "nixpkgs";
    };

    rust = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };

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

  # Output config, or config for NixOS system
  outputs = { self, ... }@inputs:
    let
      inherit (inputs.futils.lib) eachSystem system;
      mySystems = [
        system.x86_64-linux
      ];
      eachMySystem = eachSystem mySystems;
      lib = import ./nix { inherit inputs; };
    in
    eachMySystem
      (system:
        let
          pkgs = import inputs.nixpkgs { inherit system; };
          home-manager = inputs.home-manager.defaultPackage."${system}";
          pre-commit-golang = pkgs.callPackage
            ({ stdenv, fetchFromGitHub }:
              stdenv.mkDerivation rec {
                pname = "pre-commit-golang";
                version = "0.5.0-96221dc";
                src = fetchFromGitHub {
                  owner = "dnephin";
                  repo = pname;
                  rev = "96221dc741cb30cc0136999083dc6bd0e2113000";
                  sha256 = "sha256-lIQBoT+UIlVGnFaaGBgXag0Lm1UhGj/pIGlCCz91L4I=";
                };
                dontBuild = true;
                dontConfigure = true;
                installPhase = ''
                  runHook preInstall
                  install -d $out
                  find . -type f -name 'run-*.sh' \
                  | sed -E 's:^\./run-(.*)\.sh:\1:' \
                  | xargs -I {} install ./run-{}.sh $out/{}
                  runHook postInstall
                '';
              })
            { };
          pre-commit-golang-hook = name: {
            "${name}" = {
              inherit name;
              enable = true;
              entry = "${pre-commit-golang}/${name}";
              files = "\\.go$";
            };
          };
        in
        rec
        {
          packages = pkgs // {
            inherit home-manager;

            tools = import ./tools { inherit pkgs; };
            ops = import ./ops { inherit pkgs; };
            users.fcuny = import ./users/fcuny { inherit pkgs; };
          };

          checks = {
            pre-commit = inputs.pre-commit-hooks.lib.${system}.run {
              src = ./.;

              hooks = {
                trailing-whitespace = {
                  enable = true;
                  entry = "${pkgs.python3Packages.pre-commit-hooks}/bin/trailing-whitespace-fixer";
                  types = [ "text" ];
                };

                end-of-file-fixer = {
                  enable = true;
                  entry = "${pkgs.python3Packages.pre-commit-hooks}/bin/end-of-file-fixer";
                  types = [ "text" ];
                };

                nixpkgs-fmt = {
                  enable = true;
                };

                terraform-format = {
                  enable = true;
                };

                shellcheck = {
                  enable = true;
                  files = "\\.sh$";
                  types_or = [ "file" ];
                };
              }
              // (pre-commit-golang-hook "go-fmt")
              // (pre-commit-golang-hook "go-mod-tidy");
            };
          };

          devShells = {
            default = pkgs.mkShell {
              name = "NixOS-config";
              buildInputs = with pkgs; [
                gitAndTools.pre-commit
                nixUnstable
                nixfmt
                nixpkgs-fmt
                rnix-lsp
                home-manager
                git
                go
                gopls
              ];
              inherit (self.checks.${system}.pre-commit) shellHook;
            };
          };
        }) // {
      nixosConfigurations = {
        carmel = lib.mkSystem { hostname = "carmel"; };
        aptos = lib.mkSystem { hostname = "aptos"; };
        tahoe = lib.mkSystem { hostname = "tahoe"; };
      };
    };
}