summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 6b11dd6cea66cb412a69b67d06ccceb37bacb393 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
    unstable.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nur.url = "github:nix-community/NUR";
    impermanence.url = "github:nix-community/impermanence";
    hm-isolation.url = "github:3442/hm-isolation";

    nixvirt = {
      url = "github:AshleyYakeley/NixVirt";
      inputs = {
        nixpkgs.follows = "nixpkgs";

        #FIXME: Por qué existe esto?
        nixpkgs-ovmf.follows = "nixpkgs";
      };
    };

    flake-utils.url = "github:numtide/flake-utils";

    lanzaboote = {
      url = "github:nix-community/lanzaboote/v0.4.1";

      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
        pre-commit-hooks-nix.follows = "";
      };
    };
  };

  outputs =
    flakes@{ self
    , nixpkgs
    , unstable
    , home-manager
    , nur
    , impermanence
    , hm-isolation
    , nixvirt
    , flake-utils
    , lanzaboote
    }:
    let
      system = "x86_64-linux";

      pkgs = importPkgs nixpkgs;

      importPkgs = flake: import flake {
        inherit system;

        config = import ./pkgs/config nixpkgs.lib;
        overlays = [ nur.overlay self.overlays.default ];
      };

      inherit (pkgs.local.lib) importAll;

      local = import ./pkgs;
    in
    with pkgs.lib; {
      formatter.${system} = pkgs.nixpkgs-fmt;
      packages.${system} = pkgs.local;

      overlays.default = final: prev:
        let
          locals = local final prev;
        in
        {
          local = locals;
          unstable = importPkgs unstable;
        } // locals.override;

      nixosConfigurations =
        let
          nixosSystem = { modules }: makeOverridable nixpkgs.lib.nixosSystem {
            inherit modules pkgs system;

            specialArgs = {
              inherit flakes;
            };
          };

          hostConfig = host: nixosSystem {
            modules = [
              ./sys
              host
            ];
          };
        in
        mapAttrs (_: hostConfig) (importAll { root = ./sys/platform; });

      homeConfigurations =
        let
          registry = { ... }: {
            config.nix.registry = mapAttrs
              (_: value: {
                flake = value;
              })
              flakes;
          };

          home = platform: home-manager.lib.homeManagerConfiguration {
            inherit pkgs;

            modules = [
              ./home
              platform
              registry
              hm-isolation.homeManagerModule
            ];
          };

          platformHome = platform:
            let
              value = home platform;
            in
            {
              inherit value;
              name = "${value.config.home.username}@${value.config.local.hostname}";
            };
        in
        mapAttrs' (_: platformHome) (importAll { root = ./home/platform; });
    };
}