summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 59695aa3245e75e9f20807b07e2ee8e4920c6bf3 (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
{
  description = "Personal monorepo";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    disko.url = "github:nix-community/disko/latest";
    disko.inputs.nixpkgs.follows = "nixpkgs";

    nixos-hardware.url = "github:nixos/nixos-hardware/master";
  };

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

      systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;

      forAllSystems = lib.genAttrs systems;
      nixpkgsFor = forAllSystems (
        system:
        import inputs.nixpkgs {
          inherit system;
          overlays = [ overlays.default ];
        }
      );

      inherit (import ./lib/depot-tools.nix { inherit inputs systems lib; })
        importDir
        ;

      overlays.default =
        final: _:
        let
          depot = lib.filesystem.packagesFromDirectoryRecursive {
            callPackage = lib.callPackageWith (final // { inherit depot; });
            directory = ./packages;
          };
        in
        {
          inherit depot;
        };

      nixosModules = importDir ./modules (builtins.mapAttrs (_: { path, ... }: path));

      nixosConfigurations = importDir ./machines (
        entries:
        let
          flake = self;

          defaultModule =
            { config, ... }:
            {
              nixpkgs.overlays = lib.singleton overlays.default;
              system.stateVersion = config.system.nixos.release;
            };

          buildNixOS =
            hostName: entry:
            lib.nixosSystem {
              modules = [
                defaultModule
                entry.path
                nixosModules.xnet
              ];
              specialArgs = { inherit inputs flake hostName; };
            };
        in
        builtins.mapAttrs buildNixOS entries
      );
    in
    {
      inherit nixosModules nixosConfigurations overlays;

      formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt);
      packages = forAllSystems (
        system:
        let
          inherit (nixpkgsFor.${system}) depot;
        in
        {
          inherit (depot.misc) cv;
          inherit (depot.web) site;
          inherit (depot)
            colorpicker
            randpass
            ;
        }
      );
    };
}