-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
79 lines (70 loc) · 2.58 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
{
description = "Liberaforms — An open source form server";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
mach-nix.url = "github:DavHau/mach-nix/3.5.0";
deploy-rs.url = "github:serokell/deploy-rs";
deploy-rs.inputs.nixpkgs.follows = "nixpkgs";
liberaforms = {
url = "gitlab:liberaforms/liberaforms";
flake = false;
};
};
outputs = {
self,
nixpkgs,
mach-nix,
...
} @ inputs: let
# System types to support.
supportedSystems = ["x86_64-linux"];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
genSystems = nixpkgs.lib.genAttrs supportedSystems;
# genAttrs but you can also apply a function to the name
genAttrs' = names: fn: fv: nixpkgs.lib.listToAttrs (map (n: nixpkgs.lib.nameValuePair (fn n) (fv n)) names);
pkgsFor = genSystems (system:
import nixpkgs {
inherit system;
overlays = [self.overlays.default];
});
serverCfg = {
hostname = "forms";
domain = "example.org";
email = "[email protected]";
};
in {
# Overlay containing package definitions
overlays.default = import nix/overlay.nix inputs;
# Provide some packages for selected system types.
packages = genSystems (
system: {
# Include everything from the overlay
inherit (pkgsFor.${system}) liberaforms liberaforms-env;
# Set the default package
default = self.packages.${system}.liberaforms;
}
);
# Expose the module for use as an input in another flake
nixosModules.liberaforms = import ./nix/module.nix self;
# System configurations for nixos-container local dev deployment and DigitalOcean deployments
nixosConfigurations = let
genConfig = name: args:
genAttrs' supportedSystems (s: "${name}-${s}") (system:
nixpkgs.lib.nixosSystem {
inherit system;
modules = [(import ./nix/${name}.nix args)];
});
in
(genConfig "container" self) // (genConfig "digitalocean" {inherit self serverCfg;});
deploy.nodes = genAttrs' supportedSystems (s: "liberaforms-${s}") (system: {
hostname = "${serverCfg.hostname}.${serverCfg.domain}";
profiles.system = {
user = "root";
sshUser = "root";
path = inputs.deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations."digitalocean-${system}";
};
});
# This is highly advised, and will prevent many possible mistakes
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib;
};
}