nixos-config/flake.nix

173 lines
4.7 KiB
Nix
Raw Normal View History

{
description = "Fudo Host Configuration";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.05";
2021-09-29 17:55:13 -07:00
2022-03-16 09:49:35 -07:00
fudo-home = {
url = "git+https://git.fudo.org/fudo-nix/home.git";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-11-17 17:32:27 -08:00
2021-11-29 16:03:38 -08:00
# This MUST be a clean git repo, because we use the timestamp.
2021-11-28 12:39:03 -08:00
fudo-entities = {
2021-11-30 10:52:00 -08:00
url = "git+https://git.fudo.org/fudo-nix/entities.git";
2021-11-28 12:39:03 -08:00
inputs.nixpkgs.follows = "nixpkgs";
};
2021-11-28 12:39:03 -08:00
fudo-lib = {
#url = "git+https://git.fudo.org/fudo-nix/lib.git";
url = "path:/state/fudo-lib";
2021-11-28 12:39:03 -08:00
inputs.nixpkgs.follows = "nixpkgs";
};
2021-11-30 10:52:00 -08:00
fudo-pkgs.url = "git+https://git.fudo.org/fudo-nix/pkgs.git";
2021-09-29 17:55:13 -07:00
fudo-secrets.url = "path:/state/secrets";
2021-12-18 12:10:42 -08:00
chute.url = "git+https://git.fudo.org/chute/chute.git?ref=stable";
chuteUnstable.url = "git+https://git.fudo.org/chute/chute.git?ref=master";
2022-03-16 09:49:35 -07:00
nixpkgsUnstable.url = "nixpkgs/nixos-unstable";
};
outputs = { self,
nixpkgs,
fudo-home,
fudo-lib,
fudo-entities,
fudo-pkgs,
fudo-secrets,
2021-12-18 12:10:42 -08:00
chute,
chuteUnstable,
2022-03-16 09:49:35 -07:00
nixpkgsUnstable,
2021-11-29 16:03:38 -08:00
... } @ inputs:
2021-11-19 10:26:10 -08:00
with nixpkgs.lib;
let
2021-11-29 16:03:38 -08:00
fudo-nixos-hosts = filterAttrs
2021-11-19 10:26:10 -08:00
(hostname: hostOpts: hostOpts.nixos-system)
(fudo-entities.entities.hosts);
2021-09-29 17:55:13 -07:00
fudo-networks = fudo-entities.entities.networks;
2021-11-17 17:32:27 -08:00
2022-03-16 09:49:35 -07:00
unstable-for = arch: import nixpkgsUnstable {
system = arch;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"openssh-with-gssapi-8.4p1"
];
};
};
pkgs-for = arch: let
unstable = unstable-for arch;
in import nixpkgs {
system = arch;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"openssh-with-gssapi-8.4p1"
];
};
overlays = [
fudo-lib.overlay
fudo-pkgs.overlay
2021-12-18 12:10:42 -08:00
(final: prev: {
chute = chute.packages.${arch}.chute;
chuteUnstable = chuteUnstable.packages.${arch}.chute;
})
2022-03-16 09:49:35 -07:00
(final: prev: {
nyxt = unstable.nyxt;
})
];
};
2021-11-19 10:26:10 -08:00
2021-11-29 19:21:38 -08:00
latest-modified-timestamp = head
(sort (a: b: a > b)
2021-11-29 21:18:58 -08:00
(map (input: toInt input.lastModifiedDate)
(filter (input: hasAttr "lastModifiedDate" input)
2021-11-29 19:34:15 -08:00
(attrValues inputs))));
2021-11-29 19:21:38 -08:00
concat-timestamp = timestamp:
toInt (substring 0 10 (toString timestamp));
2021-11-29 16:03:38 -08:00
common-host-config = hostname: hostOpts: let
config-dir = ./config;
2021-11-29 19:21:38 -08:00
build-timestamp =
2021-11-29 19:25:56 -08:00
concat-timestamp latest-modified-timestamp;
2021-11-29 16:03:38 -08:00
in { config, ... }: {
imports = [
2021-11-19 10:26:10 -08:00
fudo-home.nixosModule
fudo-secrets.nixosModule
fudo-lib.nixosModule
2021-11-29 16:03:38 -08:00
fudo-entities.nixosModule
./config
(config-dir + /hardware/${hostname}.nix)
(config-dir + /host-config/${hostname}.nix)
(config-dir + /profile-config/${hostOpts.profile}.nix)
(config-dir + /domain-config/${hostOpts.domain}.nix)
(config-dir + /site-config/${hostOpts.site}.nix)
];
2021-11-19 10:26:10 -08:00
2022-03-16 09:49:35 -07:00
config = let
pkgs = pkgs-for hostOpts.arch;
in {
2021-11-29 16:03:38 -08:00
instance = let
build-seed = builtins.readFile
config.fudo.secrets.files.build-seed;
2021-11-19 10:26:10 -08:00
in {
2021-11-29 16:03:38 -08:00
inherit hostname build-timestamp build-seed;
};
2022-03-16 09:49:35 -07:00
environment.etc.nixos-live.source = ./.;
nix = {
registry = {
nixpkgs.flake = nixpkgs;
fudo-nixos.flake = self;
fudo-entities.flake = fudo-entities;
fudo-lib.flake = fudo-lib;
fudo-pkgs.flake = fudo-pkgs;
};
nixPath = let
lib = nixpkgs.lib;
in lib.mkDefault (lib.mkBefore [
"nixpkgs=${nixpkgs}"
]);
2021-11-29 16:03:38 -08:00
};
2022-03-16 09:49:35 -07:00
nixpkgs.pkgs = pkgs;
2021-11-29 16:03:38 -08:00
};
};
nixos-host-config = hostname: hostOpts: let
system = hostOpts.arch;
in nixosSystem {
inherit system;
modules = [
(common-host-config hostname hostOpts)
];
};
nixops-host-config = hostname: hostOpts: let
zone-hosts = fudo-entities.entities.zones.${hostOpts.domain}.hosts;
in {
imports = [
(common-host-config hostname hostOpts)
({ ... }: {
config.deployment.targetHost =
zone-hosts.${hostname}.ipv4-address;
2021-11-19 10:26:10 -08:00
})
];
2021-11-29 16:03:38 -08:00
};
in {
nixosConfigurations = mapAttrs nixos-host-config fudo-nixos-hosts;
nixopsHostConfigurations = mapAttrs nixops-host-config fudo-nixos-hosts;
2021-11-19 10:26:10 -08:00
};
}