1
0
mirror of https://github.com/ellmau/nixos.git synced 2025-12-19 09:29:36 +01:00

Fix home-manager import issue

This commit is contained in:
Stefan Ellmauthaler 2022-05-24 18:02:56 +02:00
parent 8a6fb6c6cc
commit 0793eaa1c3
Failed to extract signature
2 changed files with 116 additions and 106 deletions

105
flake.nix
View File

@ -2,7 +2,7 @@
description = "Flake to define configurations of 'elss' - ellmauthaler stefan's systems"; description = "Flake to define configurations of 'elss' - ellmauthaler stefan's systems";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
@ -25,7 +25,7 @@
url = "github:gytis-ivaskevicius/flake-utils-plus"; url = "github:gytis-ivaskevicius/flake-utils-plus";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
emacs-overlay = { emacs-overlay = {
url = "github:nix-community/emacs-overlay"; url = "github:nix-community/emacs-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -47,69 +47,74 @@
}; };
}; };
outputs = {self, nixpkgs, flake-utils-plus, ...}@inputs: outputs = { self, nixpkgs, flake-utils-plus, ... }@inputs:
let let
extended-lib = nixpkgs.lib.extend extended-lib = nixpkgs.lib.extend
(final: prev: { (final: prev: {
elss = (import ./lib {lib = final; }) prev; elss = (import ./lib { lib = final; }) prev;
}); });
inherit (extended-lib.elss) discoverModules moduleNames; inherit (extended-lib.elss) discoverModules moduleNames;
in in
flake-utils-plus.lib.mkFlake rec{ flake-utils-plus.lib.mkFlake rec{
inherit self inputs; inherit self inputs;
supportedSystems = [ "x86_64-linux" ]; supportedSystems = [ "x86_64-linux" ];
lib = extended-lib; lib = extended-lib;
channelsConfig = { channelsConfig = {
allowUnfreePredicate = pkg: builtins.elem (extended-lib.getName pkg) [ allowUnfreePredicate = pkg: builtins.elem (extended-lib.getName pkg) [
"steam" "steam"
"steam-original" "steam-original"
"steam-runtime" "steam-runtime"
"skypeforlinux" "skypeforlinux"
"teams" "teams"
"zoom" "zoom"
];
};
channels.nixpkgs.overlaysBuilder = channels: [
(final: prev: {
unstable = channels.nixpkgs-unstable;
})
inputs.nix.overlay
inputs.emacs-overlay.overlay
]; ];
};
hostDefaults = { channels.nixpkgs.overlaysBuilder = channels: [
system = "x86_64-linux"; (final: prev: {
channelName = "nixpkgs"; unstable = channels.nixpkgs-unstable;
modules = [ })
inputs.home-manager.nixosModules.home-manager inputs.nix.overlay
inputs.dwarffs.nixosModules.dwarffs inputs.emacs-overlay.overlay
] ++ (map (name: ./modules + "/${name}") (moduleNames ./modules)); ];
specialArgs = {
nixos-hardware = inputs.nixos-hardware.nixosModules; hostDefaults = {
inherit inputs; system = "x86_64-linux";
}; channelName = "nixpkgs";
extraArgs = { inherit homeConfigurations; }; modules = [
inputs.home-manager.nixosModules.home-manager
inputs.dwarffs.nixosModules.dwarffs
] ++ (map (name: ./modules + "/${name}") (moduleNames ./modules));
specialArgs = {
nixos-hardware = inputs.nixos-hardware.nixosModules;
inherit inputs;
}; };
extraArgs = {
homeConfigurations = discoverModules ./users
(name:
import (./users + "/${name}")
);
};
};
hosts = discoverModules ./machines (name: { hosts = discoverModules ./machines (name: {
modules = [ (./machines + "/${name}") ]; modules = [ (./machines + "/${name}") ];
specialArgs = { lib = extended-lib; }; specialArgs = { lib = extended-lib; };
}); });
homeConfigurations = discoverModules ./users homeConfigurations = discoverModules ./users
(name: (name:
let let
username = extended-lib.removeSuffix ".nix" name; username = extended-lib.removeSuffix ".nix" name;
in in
inputs.home-manager.lib.homeManagerConfiguration { inputs.home-manager.lib.homeManagerConfiguration {
configuration = import (./users + "/${name}"); configuration = import (./users + "/${name}");
inherit username; inherit username;
system = "x86_64-linux"; system = "x86_64-linux";
homeDirectory = "/home/${username}"; homeDirectory = "/home/${username}";
stateVersion = "21.05"; stateVersion = "21.05";
}); });
}; };
} }

View File

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, homeConfigurations, ... }:
with lib; { with lib; {
options.elss.users = { options.elss.users = {
@ -63,7 +63,7 @@ with lib; {
}); });
}; };
}; };
config = config =
let let
cfg = config.elss.users; cfg = config.elss.users;
@ -82,38 +82,38 @@ with lib; {
mkUser = login: mkUser = login:
let meta = getMeta login; let meta = getMeta login;
in in
{ {
inherit (meta) description; inherit (meta) description;
isNormalUser = true; isNormalUser = true;
home = "/home/${login}"; home = "/home/${login}";
extraGroups = [ ]; extraGroups = [ ];
openssh.authorizedKeys.keys = meta.publicKeys; openssh.authorizedKeys.keys = meta.publicKeys;
}; };
mkGitUser = login: mkGitUser = login:
let meta = getMeta login; let meta = getMeta login;
in in
{ {
programs.git = { programs.git = {
userEmail = meta.mailAddress; userEmail = meta.mailAddress;
userName = meta.description; userName = meta.description;
extraConfig ={ extraConfig = {
gpg = lib.mkIf meta.git.gpgsm { gpg = lib.mkIf meta.git.gpgsm {
format = "x509"; format = "x509";
program = "${pkgs.gnupg}/bin/gpgsm"; program = "${pkgs.gnupg}/bin/gpgsm";
}; };
user = { user = {
signingKey = meta.git.key; signingKey = meta.git.key;
signByDefault = meta.git.signDefault; signByDefault = meta.git.signDefault;
};
}; };
}; };
}; };
};
mkX11User = login: mkX11User = login:
let meta = getMeta login; let meta = getMeta login;
in in
mkIf (cfg.x11.enable) mkIf (cfg.x11.enable)
{ {
xsession = { xsession = {
numlock.enable = true; numlock.enable = true;
@ -124,45 +124,50 @@ with lib; {
''; '';
}; };
home.file.".background-image".source = ../common/wallpaper/nix-wallpaper-nineish-dark-gray.png; home.file.".background-image".source = ../common/wallpaper/nix-wallpaper-nineish-dark-gray.png;
services = { services = {
blueman-applet.enable = true; blueman-applet.enable = true;
network-manager-applet.enable = true; network-manager-applet.enable = true;
dunst.enable = true; dunst.enable = true;
}; };
}; };
in
mkIf (cfg.enable)
{
assertions =
let
cfg = config.elss.users;
in
[
{
assertion = mutuallyExclusive cfg.users cfg.admins;
message = "kbs.users.users and kbs.users.admins are mutually exclusive";
}
{
assertion = all (hash: hash != "")
(catAttrs "hashedPassword" (attrVals cfg.admins cfg.meta));
message = "No admin without password";
}
{
assertion = length (cfg.admins) > 0;
message = "One admin needed at least";
}
];
users = { in
mutableUsers = false; mkIf (cfg.enable)
users = {
mkMerge [ assertions =
(mapAdmins mkAdmin) let
(mapUsers mkUser) cfg = config.elss.users;
]; in
}; [
home-manager.users = (mapAllUsers mkGitUser) // (mapAllUsers mkX11User) // (mapAllUsersAndRoot (_: { config.home.stateVersion = mkDefault "21.05"; })); {
assertion = mutuallyExclusive cfg.users cfg.admins;
message = "elss.users.users and elss.users.admins are mutually exclusive";
}
{
assertion = all (hash: hash != "")
(catAttrs "hashedPassword" (attrVals cfg.admins cfg.meta));
message = "No admin without password";
}
{
assertion = length (cfg.admins) > 0;
message = "One admin needed at least";
}
];
users = {
mutableUsers = false;
users =
mkMerge [
(mapAdmins mkAdmin)
(mapUsers mkUser)
];
}; };
home-manager.users = mapAllUsersAndRoot (login:
mkMerge [
{ config.home.stateVersion = mkDefault "21.11"; }
(if homeConfigurations ? "${login}" then homeConfigurations."${login}" else { })
]
);
};
} }