-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
82 lines (67 loc) · 2.5 KB
/
flake.nix
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
{
description = "Memes";
inputs.deploy-rs.url = "github:serokell/deploy-rs";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.serokell-nix.url = "github:serokell/serokell.nix";
outputs = { self, nixpkgs, deploy-rs, serokell-nix }@inputs:
let
# Add default system
system = "x86_64-linux";
# Make a config
mkConfig = { name, lxc ? true }:
nixpkgs.lib.nixosSystem {
inherit system;
modules = (if lxc then
[ "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" ]
else
# this is probably the ugliest fix ever, but it
# makes both nix/deploy.rs and the formatter work so it's fine
[ ]) ++ [ "${./.}/hosts/${name}/configuration.nix" ];
specialArgs = { inputs = inputs; };
};
# create a deployment
mkDeploy = profile: {
hostname = "${profile}.voidlocal";
fastConnection = true;
profiles.system = {
user = "root";
path = deploy-rs.lib.${system}.activate.nixos
self.nixosConfigurations.${profile};
};
};
# art starts here :D
hosts' = import ./hosts;
# we only want nix hosts for this part, not all of the defined ones...
nixHosts = (builtins.filter ({ nix ? true, ... }: nix) hosts');
# We can't do partial application with //, so this solves it i guess...
merge = a: b: a // b;
# Convert a host from hosts.nix to something nixosConfigurations understands
hostToConfig = z@{ hostname, nixname ? hostname, lxc ? true, ... }:
merge {
${nixname} = mkConfig {
name = nixname;
lxc = lxc;
};
};
# Same as above, but for the nodes part of deploy.
hostToDeploy = z@{ hostname, nixname ? hostname, lxc ? true, ... }:
merge { ${nixname} = mkDeploy nixname; };
# And actually make the two sets.
configs = nixpkgs.lib.foldr hostToConfig { } nixHosts;
nodes = nixpkgs.lib.foldr hostToDeploy { } nixHosts;
in {
nixosConfigurations = configs;
deploy.nodes = nodes;
devShell.${system} = let
pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system} [ ];
in pkgs.mkShell {
buildInputs = [
deploy-rs.packages.${system}.deploy-rs
pkgs.vault
pkgs.nixUnstable
];
};
checks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
};
}