summaryrefslogtreecommitdiff
path: root/flake.nix
blob: ee0e6a36eedd72877b56ab1867859a96928cf899 (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
{
  outputs =
    {
      self,
      nur,
      nixpkgs,
      flake-parts,
      ...
    }@inputs:
    let
      devenvModules.personal = ./modules/devenv;
      flakeModules = {
        personal = ./modules/flake-parts/personal.nix;
        devenv = import ./modules/flake-parts/devenv.nix devenvModules;
      };
    in
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [ flakeModules.personal ];
      flake = {
        inherit devenvModules flakeModules;
        nixosModules.personal = ./modules/nixos;
        homeModules.personal = ./modules/home-manager;
        overlays.personal =
          _: super:
          let
            my-packages = import ./pkgs (super.extend nur.overlays.default);
          in
          {
            inherit
              (super.lib.recursiveUpdate super {
                personal = my-packages;
                lib.personal = my-packages.lib;
              })
              personal
              lib
              ;
          };

        lib = import ./lib;

        templates =
          let
            devenv = {
              path = ./templates/devenv;
            };
          in
          {
            inherit devenv;
            default = devenv;
          };
      };

      perSystem =
        {
          config,
          system,
          pkgs,
          lib,
          ...
        }:
        let
          flatten =
            let
              aux =
                path: attrs:
                if lib.isAttrs attrs && !lib.isDerivation attrs then
                  lib.foldlAttrs (
                    prev: name: value:
                    prev // aux (path ++ [ name ]) value
                  ) { } attrs
                else
                  (
                    if lib.isDerivation attrs then
                      {
                        "${lib.concatStringsSep "_" path}" = attrs;
                      }
                    else
                      { }
                  );
            in
            aux [ ];
        in
        {
          _module.args.pkgs = import nixpkgs {
            inherit system;
            overlays = [ self.overlays.personal ];
            config = { };
          };

          packages = flatten pkgs.personal;
        };
    };
}