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 }: (
let
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:
lib.lists.foldr
(a: b:
if builtins.pathExists a
if (a != null) && (builtins.pathExists a)
then a
else b)
default
@ -54,22 +74,8 @@
}
) // {
nixosConfigurations =
let
default = { pkgs, ... }: {
dualBoot = false;
timeZone = null;
keyMap = "us";
keyboardLayout = "us";
localeSettings = { };
users = { };
};
systems = {
nixos.config = { ... }: {
};
};
in
builtins.mapAttrs (
name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem {
name: { system, config }: nixpkgs.lib.nixosSystem {
inherit system;
modules = [
@ -78,7 +84,7 @@
config._module.args = {
hostname = name;
machineConfig = (default args) //
machineConfig = (defaultMachine.config args) //
(config args) // {
inherit name;
};
@ -88,7 +94,56 @@
./lib/configuration.nix
(tryFiles [ ./lib/machines/${name}.nix ] ./lib/hardware/base.nix)
];
})
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 @@
{ ... }: {
}