NixOSConfig/flake.nix

144 lines
4.4 KiB
Nix
Raw Normal View History

2023-12-01 11:29:39 +00:00
{
2024-05-01 12:00:39 +00:00
description = "NixOS Machine Configurations by manuth";
2023-12-01 11:29:39 +00:00
2024-05-01 12:00:39 +00:00
inputs = {
nixpkgs.url = "nixpkgs/38c01297e7ec11f7b9e3f2cae7d6fcec6cc767ec";
2024-05-01 16:14:25 +00:00
flake-utils.url = "github:numtide/flake-utils?ref=b1d9ab70662946ef0850d488da1c9019f3a9752a";
2024-05-09 00:06:59 +00:00
home-manager = {
url = "github:nix-community/home-manager?ref=6e277d9566de9976f47228dd8c580b97488734d4";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-05-01 23:08:45 +00:00
sops-nix.url = "github:Mic92/sops-nix?ref=f1b0adc27265274e3b0c9b872a8f476a098679bd";
2024-05-01 12:00:39 +00:00
};
2023-12-01 11:29:39 +00:00
2024-05-09 00:06:59 +00:00
outputs = { self, nixpkgs, flake-utils, home-manager, sops-nix }: (
2024-05-08 22:50:42 +00:00
let
inherit (nixpkgs) lib;
2024-05-08 22:59:02 +00:00
defaultMachine = {
system = "x86_64-linux";
config = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
};
2024-05-10 23:19:06 +00:00
machineDefinitions = {
2024-05-08 22:59:02 +00:00
nixos.config = { ... }: {
};
};
machines = builtins.mapAttrs (
name: machineDefinition:
defaultMachine // machineDefinition // {
config = { ... }@args:
((defaultMachine.config args) // (machineDefinition.config args));
})
machineDefinitions;
tryFiles = import ./lib/utils/try-files.nix { inherit lib; };
2024-05-08 22:50:42 +00:00
in
flake-utils.lib.eachDefaultSystem (
system:
2024-05-10 23:28:15 +00:00
let
pkgs = import nixpkgs {
inherit system;
config = {};
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
overlays = [
sops-nix.overlays.default
2024-05-08 22:50:42 +00:00
];
2024-05-10 23:28:15 +00:00
};
in {
devShells.default = pkgs.mkShellNoCC (
with pkgs;
{
sopsPGPKeyDirs = [
"${toString ./.}/keys/hosts"
"${toString ./.}/keys/users"
];
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
packages = [
nixos-rebuild
sops
sops-import-keys-hook
ssh-to-age
ssh-to-pgp
];
2024-05-01 23:08:45 +00:00
2024-05-10 23:28:15 +00:00
nativeBuildInputs = [
sops-import-keys-hook
];
});
}
2024-05-08 22:50:42 +00:00
) // {
nixosConfigurations =
builtins.mapAttrs (
2024-05-10 23:19:06 +00:00
hostname: { system, config }: nixpkgs.lib.nixosSystem {
2024-05-08 22:50:42 +00:00
inherit system;
2024-05-01 16:58:39 +00:00
2024-05-08 22:50:42 +00:00
modules = [
(
{ pkgs, ... }@args: {
config._module.args = {
2024-05-10 23:19:06 +00:00
inherit hostname;
2024-05-08 22:35:21 +00:00
machineConfig = (config args) // {
inherit hostname;
};
2024-05-08 22:50:42 +00:00
};
})
2024-05-09 00:06:59 +00:00
home-manager.nixosModules.home-manager
2024-05-08 22:50:42 +00:00
sops-nix.nixosModules.sops
./lib/configuration.nix
2024-05-10 23:19:06 +00:00
(tryFiles [ ./lib/machines/${hostname}.nix ] ./lib/hardware/base.nix)
2024-05-08 22:50:42 +00:00
];
2024-05-08 22:59:02 +00:00
})
2024-05-10 23:19:06 +00:00
machines;
2024-05-08 22:59:02 +00:00
homeConfigurations =
let
lib = nixpkgs.lib;
in
lib.attrsets.concatMapAttrs (
2024-05-10 23:19:06 +00:00
hostname: machine:
2024-05-08 22:59:02 +00:00
let
pkgs = import nixpkgs {
inherit (machine) system;
};
in
lib.attrsets.concatMapAttrs (
username: user: {
2024-05-09 00:06:59 +00:00
"${username}@${hostname}" = home-manager.lib.homeManagerConfiguration {
2024-05-08 22:59:02 +00:00
modules =
let
getUserConfig = import ./lib/utils/user-config.nix { inherit lib; };
userConfigPath = getUserConfig { inherit hostname username; };
2024-05-08 22:59:02 +00:00
in [
(
{ pkgs, ... }: {
config._module.args = {
userConfig = {
inherit
hostname
username
;
} // user;
};
})
sops-nix.homeManagerModules.sops
] ++ (lib.optional (userConfigPath != null) userConfigPath);
};
})
(machine.config { inherit pkgs; }).users)
2024-05-08 22:59:02 +00:00
machines;
});
2023-12-01 11:29:39 +00:00
}