summary refs log tree commit diff stats
path: root/flake.nix
blob: 05939ac10f36d03aaf93d28c2eb2e0bbc4c7736e (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
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixpkgs-small.url = "github:NixOS/nixpkgs/nixos-unstable-small";
    nixos-hardware.url = "github:NixOS/nixos-hardware";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    emacs-overlay.url = "github:nix-community/emacs-overlay";
    emacs-overlay.inputs.nixpkgs.follows = "nixpkgs";
    secrets = {
      flake = false;
    };
    utils.url = "github:numtide/flake-utils";
    agenix.url = "github:ryantm/agenix";
    agenix.inputs.nixpkgs.follows = "nixpkgs";
    searchix.url = "git+https://git.alanpearce.eu/searchix";
    golink = {
      url = "github:tailscale/golink";
      inputs.nixpkgs.follows = "nixpkgs-small";
    };
  };

  outputs =
    inputs@
    { self
    , utils
    , nixpkgs
    , nixpkgs-small
    , nixos-hardware
    , home-manager
    , secrets
    , emacs-overlay
    , agenix
    , searchix
    , golink
    , ...
    }:
    let
      readOverlays = path:
        let content = builtins.readDir path; in
        map (n: import (path + ("/" + n)))
          (builtins.filter
            (n:
              (builtins.match ".*\\.nix" n != null &&
              # ignore Emacs lock files (.#foo.nix)
              builtins.match "\\.#.*" n == null) ||
              builtins.pathExists (path + ("/" + n + "/default.nix")))
            (builtins.attrNames content));

      mkHomeConfiguration = { modules, system }: home-manager.lib.homeManagerConfiguration {
        pkgs = import nixpkgs {
          inherit system;
          overlays = readOverlays (toString ./overlays) ++ [ emacs-overlay.overlay ];
        };

        inherit modules;
        extraSpecialArgs = {
          inherit inputs system;
        };
      };
    in
    {
      nixosConfigurations.nanopi = nixpkgs-small.lib.nixosSystem {
        system = utils.lib.system.aarch64-linux;
        specialArgs = { inherit inputs; };
        modules = [
          agenix.nixosModules.default
          nixos-hardware.nixosModules.friendlyarm-nanopi-r5s
          ./system/nanopi.nix
        ];
      };
      nixosConfigurations.linde = nixpkgs-small.lib.nixosSystem {
        system = utils.lib.system.aarch64-linux;
        specialArgs = { inherit inputs; };
        modules = [
          agenix.nixosModules.default
          searchix.nixosModules.web
          golink.nixosModules.default
          ./system/linde.nix
        ];
      };
      homeConfigurations."alan@nanopi" = mkHomeConfiguration {
        system = utils.lib.system.aarch64-linux;
        modules = [
          ./user/nanopi.nix
          (secrets + "/default.nix")
        ];
      };
      homeConfigurations."alan@linde" = mkHomeConfiguration {
        system = utils.lib.system.aarch64-linux;
        modules = [
          ./user/server.nix
          (secrets + "/default.nix")
        ];
      };
    };
}