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

  nixConfig = {
    extra-substituters = ["https://cache.mydadleft.me/nix-exprs"];
    extra-trusted-public-keys = ["nix-exprs:mLifiLXlGVkkuFpIbqcrCWkIxKn2GyCkrxOuE7fwLxQ="];
  };

  inputs.nixpkgs.url = "nixpkgs/nixos-unstable";

  outputs = {
    nixpkgs,
    self,
    ...
  }: let
    inherit (nixpkgs) lib;

    systems = [
      "x86_64-linux"
      "aarch64-linux"
      "x86_64-darwin"
      "aarch64-darwin"
    ];

    forAllSystems = fn: lib.genAttrs systems (sys: fn nixpkgs.legacyPackages.${sys});
  in {
    packages = forAllSystems (
      pkgs: let
        overlay = lib.fix (final: self.overlays.default final pkgs);

        /*
        this filters out packages that may be broken or not supported
        on the current system. packages that have no `broken` or `platforms`
        meta attribute are assumed to be valid
        */
        isValid = _: v:
          lib.elem pkgs.system (v.meta.platforms or [pkgs.system]) && !(v.meta.broken or false);

        pkgs' = lib.filterAttrs isValid overlay;
      in
        pkgs' // {default = pkgs'.treefetch;}
    );

    formatter = forAllSystems (pkgs: pkgs.alejandra);

    overlays.default = final: prev: (import ./pkgs final prev);

    templates = let
      # string -> string -> {}
      toTemplate = name: description: {
        path = builtins.path {
          path = ./templates/${name};
          name = "${name}-template";
        };

        inherit description;
      };
    in
      lib.mapAttrs toTemplate {
        basic = "minimal boilerplate for my flakes";
        full = "big template for complex flakes (using flake-parts)";
        nixos = "minimal boilerplate for flake-based nixos configuration";
      };

    githubWorkflow.matrix = let
      ciSystems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
      ];

      platforms = {
        "x86_64-linux" = {
          arch = "x64";
          os = "ubuntu-latest";
        };

        "aarch64-linux" = {
          arch = "aarch64";
          os = "ubuntu-latest";
        };

        "x86_64-darwin" = {
          arch = "x64";
          os = "macos-latest";
        };
      };
    in {
      include = lib.pipe ciSystems [
        (systems: lib.getAttrs systems self.packages)

        (lib.mapAttrsToList (system:
          lib.mapAttrsToList (attr: _: {
            inherit (platforms.${system}) os arch;
            attr = "packages.${system}.${attr}";
          })))

        lib.flatten
      ];
    };
  };
}