NixOSConfig/flake.nix

185 lines
5.6 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 = {
2024-06-12 01:07:46 +00:00
nixpkgs.url = "nixpkgs/f7207adcc68d9cafa29e3cd252a18743ae512c6a";
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 = {
2024-06-12 01:07:46 +00:00
url = "github:nix-community/home-manager?ref=892f76bd0aa09a0f7f73eb41834b8a904b6d0fad";
2024-05-09 00:06:59 +00:00
inputs.nixpkgs.follows = "nixpkgs";
};
2024-06-12 01:07:46 +00:00
sops-nix.url = "github:Mic92/sops-nix?ref=c279dec105dd53df13a5e57525da97905cc0f0d6";
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";
2024-06-11 23:35:30 +00:00
modules = [ ];
2024-05-08 22:59:02 +00:00
config = { pkgs, ... }: {
dualBoot = false;
2024-05-20 15:24:45 +00:00
timeZone = "Europe/Zurich";
keyMap = "de_CH-latin1";
keyboardLayout = "ch";
localeSettings =
let defaultLocale = "en_US.UTF-8";
in {
LANG = "de_CH.UTF-8";
LANGUAGE = defaultLocale;
LC_MESSAGE = defaultLocale;
};
2024-05-20 19:44:15 +00:00
users = {
manuel = {
fullName = "Manuel Thalmann";
mail = "m@nuth.ch";
sudoer = true;
};
};
2024-05-08 22:59:02 +00:00
};
};
2024-05-10 23:19:06 +00:00
machineDefinitions = {
2024-05-08 22:59:02 +00:00
nixos.config = { ... }: {
};
2024-05-20 23:57:56 +00:00
manu-surface.config = { ... }: {
};
2024-05-08 22:59:02 +00:00
};
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; };
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 {
packages = {
rcloneDocs =
let
module = lib.evalModules {
modules = [
({ pkgs, ... }@args: {
inherit (import ./lib/modules/rclone.nix args) options;
})
];
};
optionsDoc = pkgs.nixosOptionsDoc {
options = module.options;
};
in
pkgs.runCommand "options-doc.md" {} ''
cat ${optionsDoc.optionsCommonMark} >> $out
'';
};
2024-05-10 23:28:15 +00:00
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 = [
mkpasswd
2024-05-10 23:28:15 +00:00
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-06-11 23:35:30 +00:00
hostname: { system, config, modules }@machine: 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, ... }: {
2024-05-11 18:28:41 +00:00
config = {
_module.args = {
machine = machine // {
name = hostname;
config = (pkgs.callPackage config { });
};
2024-05-11 17:40:01 +00:00
};
2024-05-11 18:28:41 +00:00
home-manager.sharedModules = [
sops-nix.homeManagerModules.sops
];
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-06-11 23:35:30 +00:00
] ++ modules;
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;
};
machineConfig = pkgs.callPackage machine.config { };
2024-05-08 22:59:02 +00:00
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
2024-05-11 19:35:13 +00:00
getUserModule = pkgs.callPackage (import ./lib/utils/user-module.nix);
in
getUserModule {
machine = machine // {
name = hostname;
config = machineConfig;
};
user = {
name = username;
} // user;
} ++ [
sops-nix.homeManagerModules.sops
];
2024-05-08 22:59:02 +00:00
};
})
machineConfig.users)
2024-05-08 22:59:02 +00:00
machines;
});
2023-12-01 11:29:39 +00:00
}