summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 0d04166f89d07d1339f5e8f8581a7969ca05eeec (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
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
  inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nixos-hardware.url = "github:NixOS/nixos-hardware/master";
  inputs.pms7003.url = "github:orbekk/pms7003/master";
  inputs.pms7003.inputs.nixpkgs.follows = "nixpkgs";
  inputs.emacs-overlay.url = "github:nix-community/emacs-overlay";
  inputs.agenix.url = "github:ryantm/agenix";

  outputs =
    { self, nixpkgs, nixpkgs-unstable, nixos-hardware, pms7003, emacs-overlay, agenix }:
    let
      pkgs-module = { config, ... }:
        let
          cfg = config.nixpkgs;

          ppp = pms7003;
          extra-packages = final: prev: {
            pms7003 = ppp.packages.${final.system}.pms7003;
            agenix = agenix.defaultPackage.${final.system};
          };

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

      registry-module = { ... }: {
        nix.registry.nixpkgs.flake = nixpkgs;
        nix.registry.nixpkgs-unstable.flake = nixpkgs-unstable;
      };

      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 registry-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
                registry-module
                module
                nixpkgs.nixosModules.notDetected
                agenix.nixosModules.age
                ({ 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);
    };
}