summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 204ad912b02555f9f655c24f04932a87d42a2b22 (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
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
  inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nixos-hardware.url = "github:NixOS/nixos-hardware/master";
  inputs.home-manager.url = "github:rycee/home-manager/master";
  inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";

  # TODO: Remove nix overlay when pull request is resolved:
  # https://github.com/NixOS/nix/pull/4566
  # inputs.nix.url = "github:orbekk/nix/master";
  # inputs.nix.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, nixpkgs-unstable, nixos-hardware, home-manager }:
    let
      pkgs-module = { config, ... }:
        let
          cfg = config.nixpkgs;

          unstable-overlay = final: prev: {
            unstable = import nixpkgs-unstable {
              inherit (cfg) config localSystem crossSystem;
            };
          };
        in {
          nixpkgs.pkgs = import nixpkgs {
            inherit (cfg) config localSystem crossSystem;
            overlays = cfg.overlays ++ [ unstable-overlay ];
          };
        };

      lib = nixpkgs.lib;

      orbekk-modules = let
        moduleFiles = lib.attrNames
          (lib.filterAttrs (n: v: lib.hasSuffix ".nix" n && v == "regular")
            (builtins.readDir ./modules));

        moduleNames = map (lib.removeSuffix ".nix") moduleFiles;

        mkModule = name: {
          inherit name;
          value = import (./. + "/modules/${name}.nix");
        };
      in lib.listToAttrs (map mkModule moduleNames);

    in {
      nixosModules = orbekk-modules // { inherit pkgs-module; };

      packages."x86_64-linux" =
        let pkgs = import nixpkgs { system = "x86_64-linux"; };
        in { };

      nixosConfigurations = let
        mkConfig = { hostName, module ? (./. + "/machines/${hostName}.nix")
          , system ? "x86_64-linux" }: {
            name = hostName;
            value = lib.nixosSystem {
              inherit system;

              modules = (lib.attrValues self.nixosModules) ++ [
                pkgs-module
                module
                nixpkgs.nixosModules.notDetected
                ({ config, pkgs, ... }: {
                  # Let 'nixos-version --json' know about the Git revision
                  # of this flake.
                  system.configurationRevision = let
                    lastModified = pkgs.lib.substring 0 8
                      (self.lastModifiedDate or self.lastModified or "19700101");
                  in "${lastModified}.${self.shortRev or "dirty"}";
                })
              ];
            };
          };
        myMachines = [
          {
            hostName = "pincer";
            module = ./machines/x1-pincer.nix;
          }
          { hostName = "dragon"; }
          { hostName = "firelink"; }
          {
            hostName = "tiny1";
          }
          # { hostName = "testvm"; module = {
          #     users.users.orbekk.initialHashedPassword = "";
          #   }; }
        ];
      in builtins.listToAttrs (map mkConfig myMachines);
    };
}