summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 90c86d51660ca1fb76e7ff013233f534c2abd2d4 (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
{
  inputs.devenv = {
    url = "github:cachix/devenv";
    inputs.nixpkgs.url = "nixpkgs";
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-trusted-substituters = "https://devenv.cachix.org";
  };

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

      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;

        devenv.shells.default = {
          languages.nix = {
            enable = true;
            packaging.enable = true;
          };
        };
      };
    };
}