aboutsummaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: 4efe54be583e2dc0c1b4d5dc5d612a7aa776c050 (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
{
  description = "Cross-platform Nix system configuration (NixOS + standalone home-manager)";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

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

  outputs = { self, nixpkgs, home-manager, ... }@inputs:
    let
      lib = import ./lib { inherit inputs; };

      forAllSystems = nixpkgs.lib.genAttrs [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];

      # Any directory under hosts/ other than hosts/template that contains a
      # `system` file becomes a real nixosConfigurations.<name> output —
      # adding a host means dropping in a directory, not editing this file.
      # hosts/template is excluded by name so it is never built, even though
      # it also carries a system file (kept only so it stays a complete,
      # consistent copy-source for the bootstrap script).
      hostNames = builtins.attrNames
        (nixpkgs.lib.filterAttrs
          (name: type: type == "directory" && name != "template")
          (builtins.readDir ./hosts));

      mkHostConfig = hostname:
        lib.mkNixos {
          inherit hostname;
          system = builtins.readFile (./hosts + "/${hostname}/system");
        };
    in
    {
      nixosConfigurations = nixpkgs.lib.genAttrs hostNames mkHostConfig;

      homeConfigurations = {
        "tom@linux" = lib.mkHome {
          username = "tom";
          system = "x86_64-linux";
        };

        "tom@darwin" = lib.mkHome {
          username = "tom";
          system = "aarch64-darwin";
        };
      };

      formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);

      devShells = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
        in
        {
          default = pkgs.mkShell {
            packages = [ pkgs.statix pkgs.deadnix pkgs.nixfmt-rfc-style ];
          };
        });

      apps = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
        in
        {
          bootstrap-host = {
            type = "app";
            program = "${pkgs.writeShellApplication {
              name = "bootstrap-host";
              runtimeInputs = [ pkgs.coreutils pkgs.gnused ];
              text = builtins.readFile ./scripts/bootstrap-host.sh;
            }}/bin/bootstrap-host";
          };
        });
    };
}