summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 92438f9b8d79050c2fd45604f75a9746f1798913 (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
{
  description = "getchoo's nix expressions";

  nixConfig = {
    extra-substituters = [ "https://getchoo.cachix.org" ];
    extra-trusted-public-keys = [ "getchoo.cachix.org-1:ftdbAUJVNaFonM0obRGgR5+nUmdLMM+AOvDOSx0z5tE=" ];
  };

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

  outputs =
    { self, nixpkgs }:

    let
      inherit (nixpkgs) lib;

      # Support all systems exported by Nixpkgs
      systems = lib.intersectLists lib.systems.flakeExposed (with lib.platforms; darwin ++ linux);
      # But separate our primarily supported systems
      tier1Systems = lib.intersectLists systems (with lib.platforms; aarch64 ++ x86_64);

      forAllSystems = lib.genAttrs systems;
      forTier1Systems = lib.genAttrs tier1Systems;
      nixpkgsFor = nixpkgs.legacyPackages;
    in

    {
      checks = forTier1Systems (
        system:
        let
          pkgs = nixpkgsFor.${system};

          mkCheck =
            name: deps: script:
            pkgs.runCommand name { nativeBuildInputs = deps; } ''
              ${script}
              touch $out
            '';
        in
        {
          deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}";
          nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}/**.nix";
          statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${self}";
        }
      );

      packages = forAllSystems (
        system:

        let
          pkgs = nixpkgsFor.${system};

          getchpkgs = import ./default.nix { inherit pkgs; };

          getchpkgs' = lib.filterAttrs (lib.const (
            deriv:
            let
              isCross = deriv.stdenv.buildPlatform != deriv.stdenv.hostPlatform;
              availableOnHost = lib.meta.availableOn pkgs.stdenv.hostPlatform deriv;
              # `nix flake check` doesn't like broken packages
              isBroken = deriv.meta.broken or false;
            in
            isCross || availableOnHost && (!isBroken)
          )) getchpkgs;
        in

        getchpkgs' // { default = getchpkgs'.treefetch or pkgs.emptyFile; }
      );

      flakeModules = {
        checks = self + "/modules/flake/checks.nix";
        configurations = self + "/modules/flake/configurations.nix";
      };

      homeModules = {
        arkenfox = self + "/modules/home/arkenfox";
        firefox-addons = self + "/modules/home/firefox-addons.nix";
      };

      nixosModules = {
        firefox-addons = self + "/modules/nixos/firefox-addons.nix";
      };

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

      templates =
        let
          toTemplate = name: description: {
            path = self + "/templates/${name}";
            inherit description;
          };
        in
        lib.mapAttrs toTemplate {
          standard = "Minimal boilerplate for my Flakes";
          nixos = "Minimal boilerplate for a Flake-based NixOS configuration";
        };

      hydraJobs = forTier1Systems (system: {
        all-packages = nixpkgsFor.${system}.linkFarm "all-packages" (
          lib.mapAttrs (lib.const (deriv: deriv.outPath or deriv)) self.packages.${system}
        );
      });
    };
}