NixOSConfig/flake.nix

147 lines
4.5 KiB
Nix

{
description = "NixOS Machine Configurations by manuth";
inputs = {
nixpkgs.url = "nixpkgs/38c01297e7ec11f7b9e3f2cae7d6fcec6cc767ec";
flake-utils.url = "github:numtide/flake-utils?ref=b1d9ab70662946ef0850d488da1c9019f3a9752a";
home-manager = {
url = "github:nix-community/home-manager?ref=6e277d9566de9976f47228dd8c580b97488734d4";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix.url = "github:Mic92/sops-nix?ref=f1b0adc27265274e3b0c9b872a8f476a098679bd";
};
outputs = { self, nixpkgs, flake-utils, home-manager, sops-nix }: (
let
inherit (nixpkgs) lib;
defaultMachine = {
system = "x86_64-linux";
config = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
};
machineDefinitions = {
nixos.config = { ... }: {
};
};
machines = builtins.mapAttrs (
name: machineDefinition:
defaultMachine // machineDefinition // {
config = { callPackage, ... }:
((callPackage defaultMachine.config { }) // (callPackage machineDefinition.config { }));
})
machineDefinitions;
tryFiles = import ./lib/utils/try-files.nix { inherit lib; };
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config = {};
overlays = [
sops-nix.overlays.default
];
};
in {
devShells.default = pkgs.mkShellNoCC (
with pkgs;
{
sopsPGPKeyDirs = [
"${toString ./.}/keys/hosts"
"${toString ./.}/keys/users"
];
packages = [
nixos-rebuild
sops
sops-import-keys-hook
ssh-to-age
ssh-to-pgp
];
nativeBuildInputs = [
sops-import-keys-hook
];
});
}
) // {
nixosConfigurations =
builtins.mapAttrs (
hostname: { system, config }: nixpkgs.lib.nixosSystem {
inherit system;
modules = [
(
{ pkgs, ... }: {
config._module.args = {
inherit hostname;
machineConfig = (pkgs.callPackage config { }) // {
inherit hostname;
};
};
})
home-manager.nixosModules.home-manager
sops-nix.nixosModules.sops
./lib/configuration.nix
(tryFiles [ ./lib/machines/${hostname}.nix ] ./lib/hardware/base.nix)
];
})
machines;
homeConfigurations =
let
lib = nixpkgs.lib;
in
lib.attrsets.concatMapAttrs (
hostname: machine:
let
pkgs = import nixpkgs {
inherit (machine) system;
};
machineConfig = pkgs.callPackage machine.config { };
in
lib.attrsets.concatMapAttrs (
username: user: {
"${username}@${hostname}" = home-manager.lib.homeManagerConfiguration {
modules =
let
getUserConfig = import ./lib/utils/user-config.nix { inherit lib; };
userConfigPath = getUserConfig { inherit hostname username; };
in [
(
{ pkgs, ... }: {
config._module.args = {
inherit
machineConfig
hostname
username
;
userConfig = user;
};
})
sops-nix.homeManagerModules.sops
] ++ (lib.optional (userConfigPath != null) userConfigPath);
};
})
machineConfig.users)
machines;
});
}