Allow configuring user homes

This commit is contained in:
Manuel Thalmann 2024-05-09 00:59:02 +02:00
parent 2cce1f0b2e
commit 0d399b63b9
2 changed files with 77 additions and 20 deletions

View file

@ -10,10 +10,30 @@
outputs = { self, nixpkgs, flake-utils, sops-nix }: ( outputs = { self, nixpkgs, flake-utils, sops-nix }: (
let let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
defaultMachine = {
system = "x86_64-linux";
config = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
};
machines = {
nixos.config = { ... }: {
};
};
systems = builtins.mapAttrs (name: value: defaultMachine // value) machines;
tryFiles = files: default: tryFiles = files: default:
lib.lists.foldr lib.lists.foldr
(a: b: (a: b:
if builtins.pathExists a if (a != null) && (builtins.pathExists a)
then a then a
else b) else b)
default default
@ -54,22 +74,8 @@
} }
) // { ) // {
nixosConfigurations = nixosConfigurations =
let
default = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
systems = {
nixos.config = { ... }: {
};
};
in
builtins.mapAttrs ( builtins.mapAttrs (
name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem { name: { system, config }: nixpkgs.lib.nixosSystem {
inherit system; inherit system;
modules = [ modules = [
@ -78,7 +84,7 @@
config._module.args = { config._module.args = {
hostname = name; hostname = name;
machineConfig = (default args) // machineConfig = (defaultMachine.config args) //
(config args) // { (config args) // {
inherit name; inherit name;
}; };
@ -90,5 +96,54 @@
]; ];
}) })
systems; systems;
homeConfigurations =
let
lib = nixpkgs.lib;
in
lib.attrsets.concatMapAttrs (
hostname: machineDeclaration:
let
machine = machineDeclaration // defaultMachine // {
config = { ... }@args: (
(defaultMachine.config args) //
(machineDeclaration.config args));
};
pkgs = import nixpkgs {
inherit (machine) system;
};
in
lib.attrsets.concatMapAttrs (
username: user: {
"${username}@${hostname}" = {
modules =
let
userConfigPath = (
tryFiles [
./lib/users/${username}/${hostname}.nix
./lib/users/${username}/common.nix
./lib/users/${username}.nix
]
null);
in [
(
{ pkgs, ... }: {
config._module.args = {
userConfig = {
inherit
hostname
username
;
} // user;
};
})
sops-nix.homeManagerModules.sops
./lib/home.nix
] ++ (lib.optional (userConfigPath != null) userConfigPath);
};
})
(machine.config { inherit pkgs; }).users)
machines;
}); });
} }

2
lib/home.nix Normal file
View file

@ -0,0 +1,2 @@
{ ... }: {
}