summaryrefslogtreecommitdiff
path: root/flake.nix
blob: c85edbc08a7a5db783b8bded451975c08cb1e9e3 (plain) (blame)
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
{
  description = "sinan's reproducible nixos systems";

  inputs = {
    nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";

    sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    home-manager = {
      url = "github:sinanmohd/home-manager/sway-generators";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    alina = {
      url = "github:sinanmohd/alina";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      sops-nix,
      home-manager,
      nixos-hardware,
      alina,
    }:
    let
      lib = nixpkgs.lib;

      makeGlobalImports =
        host:
        [
          ./global/common
        ]
        ++ lib.optional (builtins.pathExists ./global/${host}) ./global/${host};

      makeHomeImports =
        host:
        makeGlobalImports host
        ++ [
          ./home/common/home.nix
        ]
        ++ lib.optional (builtins.pathExists ./home/${host}) ./home/${host}/home.nix;

      makeNixos =
        host: system:
        lib.nixosSystem {
          inherit system;
          specialArgs = { inherit nixos-hardware; };

          modules = [
            alina.nixosModules.alina
            sops-nix.nixosModules.sops

            ./os/${host}/configuration.nix
            {
              networking.hostName = host;
              nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
            }

            home-manager.nixosModules.home-manager
            (
              { config, ... }:
              let
                username = config.global.userdata.name;
              in
              {
                home-manager = {
                  useGlobalPkgs = true;
                  useUserPackages = false;
                  users.${username} =
                    { ... }:
                    {
                      imports = makeHomeImports host;
                    };
                };
              }
            )
          ] ++ (makeGlobalImports host);
        };

      makeHome =
        host: system:
        home-manager.lib.homeManagerConfiguration {
          pkgs = nixpkgs.legacyPackages.${system};
          modules = makeHomeImports host;
        };
    in
    {
      nixosConfigurations = lib.genAttrs [ "cez" "kay" "lia" "fscusat" "dspace" ] (
        host: makeNixos host "x86_64-linux"
      );

      homeConfigurations = lib.genAttrs [ "common" "wayland" "pc" "cez" ] (
        host: makeHome host "x86_64-linux"
      );
    };
}