Last active
May 20, 2022 12:21
-
-
Save qbit/ab6f8e7e7e3591fbb27a1c9a20ed334a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "bold.daemon"; | |
inputs = { | |
unstable = { url = "github:NixOS/nixpkgs/nixos-unstable"; }; | |
stable = { url = "github:NixOS/nixpkgs/nixos-21.11"; }; | |
sops-nix.url = "github:Mic92/sops-nix"; | |
sshKnownHosts = { | |
url = "github:qbit/ssh_known_hosts"; | |
flake = false; | |
}; | |
}; | |
outputs = { self, unstable, stable, sops-nix, sshKnownHosts }: | |
let | |
# TODO: any way to use pkgs without specifying a system? | |
pkgs = (import unstable) { system = "x86_64-linux"; }; | |
inherit (builtins) readDir elemAt listToAttrs; | |
inherit (pkgs.lib) attrNames filterAttrs splitString flatten; | |
hosts = attrNames (filterAttrs (_: entryType: entryType == "directory") | |
(readDir ./hosts)); | |
build-sys = hostSet: | |
let | |
# TODO: is there a better way to do this? | |
parts = splitString "." hostSet; | |
myName = elemAt parts 0; | |
mySys = elemAt parts 1; | |
myPkg = elemAt parts 2; | |
hostSys = { | |
system = mySys; | |
modules = [ | |
(import (./default.nix)) | |
(import (./hosts + "/${hostSet}/configuration.nix")) | |
(import (./hosts + "/${hostSet}/hardware-configuration.nix")) | |
sops-nix.nixosModules.sops | |
(import "${sshKnownHosts}") | |
]; | |
}; | |
in { | |
name = myName; | |
value = if myPkg == "unstable" then | |
unstable.lib.nixosSystem hostSys | |
else | |
stable.lib.nixosSystem hostSys; | |
}; | |
in { | |
nixosConfigurations = | |
listToAttrs (flatten (map (host: [ (build-sys host) ]) hosts)); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment