making a mess of it, but getting to auto loading multi user setups!

This commit is contained in:
Chris Kruining 2025-03-13 00:50:41 +01:00
parent 20a2450683
commit b139021f8e
13 changed files with 139 additions and 216 deletions

View file

@ -1,9 +1,8 @@
{ inputs, config, lib, pkgs, ... }: { inputs, config, lib, pkgs, ... }:
let let
inherit (builtins) toString; inherit (builtins) toString;
inherit (lib.attrsets) attrValues filterAttrs mapAttrs mapAttrsToList; inherit (lib.modules) mkAliasOptionModule mkIf;
inherit (lib.modules) mkAliasOptionModule mkDefault mkIf; inherit (lib.my) mapModulesRec' mapModules mkSysUser mkHmUser;
inherit (lib.my) mapModulesRec';
in in
{ {
imports = [ imports = [
@ -14,8 +13,6 @@ in
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
(mkAliasOptionModule ["hm"] ["home-manager" "users" config.user.name]) (mkAliasOptionModule ["hm"] ["home-manager" "users" config.user.name])
(mkAliasOptionModule ["home"] ["hm" "home"]) (mkAliasOptionModule ["home"] ["hm" "home"])
(mkAliasOptionModule ["create" "configFile"] ["hm" "xdg" "configFile"])
(mkAliasOptionModule ["create" "dataFile"] ["hm" "xdg" "dataFile"])
] ]
++ (mapModulesRec' (toString ./modules) import); ++ (mapModulesRec' (toString ./modules) import);
@ -37,9 +34,4 @@ in
age.keyFile = "/home/"; age.keyFile = "/home/";
}; };
system = {
stateVersion = "23.11";
configurationRevision = with inputs; mkIf (self ? rev) self.rev;
};
} }

View file

@ -91,7 +91,5 @@
// mapModulesRec ./modules import; // mapModulesRec ./modules import;
nixosConfigurations = mapHosts ./hosts {}; nixosConfigurations = mapHosts ./hosts {};
devShells."${system}".default = import ./shell.nix { inherit lib pkgs; };
}; };
} }

View file

@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
{ {
imports = [ ./hardware.nix ];
user.name = "chris"; user.name = "chris";
fileSystems."/home/chris/games" = { fileSystems."/home/chris/games" = {

View file

@ -0,0 +1,5 @@
{}:
{
full_name = "WOOOP WOOOP";
is_trusted = true;
}

View file

@ -1,65 +0,0 @@
// { config, lib, pkgs, ... }:
// {
// full_name = "WOOT";
// modules = {
// themes = {
// enable = true;
// theme = "everforest";
// polarity = "dark";
// };
// develop = {
// rust.enable = true;
// js.enable = true;
// dotnet.enable = true;
// };
// # EXPERIMENTS
// # services.games.minecraft.enable = true;
// services.auth.enable = true;
// desktop = {
// plasma.enable = true;
// type = "wayland";
// applications = {
// communication.enable = true;
// email.enable = true;
// office.enable = true;
// steam.enable = true;
// recording.enable = true;
// };
// terminal = {
// default = "ghostty";
// alacritty.enable = true;
// ghostty.enable = true;
// };
// editors = {
// default = "zed";
// vscodium.enable = true;
// zed.enable = true;
// nvim.enable = true;
// nano.enable = true;
// kate.enable = true;
// };
// browsers = {
// default = "chromium";
// firefox.enable = true;
// chrome.enable = true;
// };
// games = {
// minecraft.enable = true;
// };
// };
// shell = {
// default = "zsh";
// corePkgs.enable = true;
// };
// };
// }

View file

@ -1,24 +1,53 @@
{ inputs, lib, pkgs, self, ... }: {
let inputs,
lib,
pkgs,
self,
...
}: let
inherit (inputs.nixpkgs.lib) nixosSystem; inherit (inputs.nixpkgs.lib) nixosSystem;
inherit (builtins) baseNameOf elem; inherit (builtins) baseNameOf elem;
inherit (lib.attrsets) filterAttrs; inherit (lib.attrsets) filterAttrs;
inherit (lib.modules) mkDefault; inherit (lib.modules) mkDefault;
inherit (lib.strings) removeSuffix; inherit (lib.strings) removeSuffix;
inherit (self.modules) mapModules; inherit (self.modules) mapModules;
inherit (self) mkSysUser mkHmUser;
in rec in rec
{ {
mkHost = path: attrs @ {system ? "x86_64-linux", ...}: mkHost = path: attrs @ {system ? "x86_64-linux", ...}:
nixosSystem { nixosSystem {
inherit system; inherit system;
specialArgs = { inherit lib inputs system; }; specialArgs = {inherit lib inputs system;};
modules = [ modules =
let
stateVersion = "23.11";
in [
inputs.nixos-boot.nixosModules.default inputs.nixos-boot.nixosModules.default
{ {
nixpkgs.pkgs = pkgs; nixpkgs.pkgs = pkgs;
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path)); networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
system = {
inherit stateVersion;
configurationRevision = with inputs; mkIf (self ? rev) self.rev;
};
imports = [ "${path}/hardware.nix" ];
users = {
mutableUsers = false;
users = mapModules "${path}/users" mkSysUser;
};
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [
inputs.plasma-manager.homeManagerModules.plasma-manager
];
users = mapModules "${path}/users" (p: mkHmUser p stateVersion);
};
} }
(filterAttrs (n: v: !elem n ["system"]) attrs) (filterAttrs (n: v: !elem n ["system"]) attrs)
../. # ../default.nix ../. # ../default.nix
@ -26,6 +55,6 @@ in rec
]; ];
}; };
mapHosts = dir: attrs @ { system ? system, ... }: mapHosts = dir: attrs @ {system ? system, ...}:
mapModules dir (hostPath: mkHost hostPath attrs); mapModules dir (hostPath: mkHost hostPath attrs);
} }

31
lib/user.nix Normal file
View file

@ -0,0 +1,31 @@
{ lib, ... }: let
inherit (builtins) baseNameOf;
inherit (lib.attrsets) filterAttrs;
inherit (lib.strings) removeSuffix;
in rec
{
mkSysUser = path: let
user = import path {};
name = removeSuffix ".nix" (baseNameOf path);
in
{
inherit name;
inherit (user) is_trusted;
description = user.full_name;
extraGroups = (if user.is_trusted then [ "wheel" ] else []);
isNormalUser = true;
home = "/home/${name}";
group = "users";
};
mkHmUser = path: stateVersion: let
user = import path {};
name = removeSuffix ".nix" (baseNameOf path);
in
{
home = {
inherit stateVersion;
sessionPath = [ "$SNEEUWVLOK_BIN" "$XDG_BIN_HOME" "$PATH" ]; # Pretty sure I don't need this.
};
};
}

View file

@ -1,19 +1,67 @@
{ config, options, lib, pkgs, ... }: {
let config,
inherit (lib.meta) getExe; options,
lib,
pkgs,
...
}: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.attrsets) attrValues; inherit (lib.attrsets) attrValues;
cfg = config.modules.desktop.editors.zed; cfg = config.modules.desktop.editors.zed;
in in {
{
options.modules.desktop.editors.zed = let options.modules.desktop.editors.zed = let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "zed"; }; in {enable = mkEnableOption "zed";};
config = mkIf cfg.enable { config = mkIf cfg.enable {
user.packages = attrValues { user.packages = attrValues {
inherit (pkgs) zed-editor; inherit (pkgs) zed-editor;
}; };
hm.programs.zed-editor = {
enable = true;
extraPackages = with pkgs; [ nixd nil alejandra ];
extensions = ["nix" "toml" "html"];
userSettings = {
assistant.enabled = false;
vim_mode = false;
load_direnv = "shell_hook";
base_keymap = "JetBrains";
tabs = {
file_icons = true;
git_status = true;
};
project_panel.auto_reveal_entries = false;
hour_format = "hour24";
auto_update = false;
lsp = {
nixd = {};
nil = {
initialization_options = {
formatting = {
command = ["alejandra" "--quiet" "--"];
};
};
binary = {
path_lookup = true;
};
};
};
languages = {
"Nix" = {
language_servers = ["nixd" "nil"];
format_on_save = "on";
};
};
};
};
}; };
} }

View file

@ -45,55 +45,7 @@ in {
args = ["-l" "-c" "tmux new || tmux"]; args = ["-l" "-c" "tmux new || tmux"];
}; };
} }
# (mkIf (active != null) {
# import = ["~/.config/alacritty/config/${active}.toml"];
# })
]; ];
}; };
# create.configFile = mkIf (active != null) {
# alacritty-conf = {
# target = "alacritty/config/${active}.toml";
# source = let
# inherit (config.modules.themes.font) mono sans;
# tomlFormat = pkgs.formats.toml {};
# in tomlFormat.generate "alacritty-theme" {
# font = {
# builtin_box_drawing = true;
# size = mono.size;
#
# normal = {
# family = "${mono.family}";
# style = "${sans.weight}";
# };
#
# italic = {
# family = "${mono.family}";
# style = "${sans.weight} Italic";
# };
#
# bold = {
# family = "${mono.family}";
# style = "${mono.weight}";
# };
#
# bold_italic = {
# family = "${mono.family}";
# style = "${mono.weight} Italic";
# };
#
# offset = {
# x = 0;
# y = 0;
# };
# glyph_offset = {
# x = 0;
# y = 0;
# };
# };
# };
# };
# };
}; };
} }

View file

@ -6,7 +6,7 @@ let
in in
{ {
options = let options = let
inherit (lib.types) attrs path str; inherit (lib.types) attrs path;
inherit (lib.my) mkOpt; inherit (lib.my) mkOpt;
in in
{ {
@ -14,7 +14,7 @@ in
sneeuwvlok = { sneeuwvlok = {
dir = mkOpt path (findFirst pathExists (toString ../.) [ dir = mkOpt path (findFirst pathExists (toString ../.) [
"${config.user.home}/Github/.files" "${config.user.home}/Github/sneeuwvlok"
]); ]);
hostDir = mkOpt path "${config.sneeuwvlok.dir}/hosts/${config.networking.hostName}"; hostDir = mkOpt path "${config.sneeuwvlok.dir}/hosts/${config.networking.hostName}";
configDir = mkOpt path "${config.sneeuwvlok.dir}/config"; configDir = mkOpt path "${config.sneeuwvlok.dir}/config";
@ -24,10 +24,6 @@ in
}; };
config = { config = {
environment.systemPackages = [
pkgs.sops
];
user = { user = {
name = "chris"; name = "chris";
description = "Chris Kruining"; description = "Chris Kruining";
@ -38,27 +34,16 @@ in
uid = 1000; uid = 1000;
}; };
home-manager = { users.users.${config.user.name} = mkAliasDefinitions options.user;
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [
inputs.plasma-manager.homeManagerModules.plasma-manager
];
};
home = { nix.settings = let
stateVersion = config.system.stateVersion; inherit (lib) attrNames filterAttrs;
sessionPath = [ "$SNEEUWVLOK_BIN" "$XDG_BIN_HOME" "$PATH" ];
};
users.users = { users = (attrNames (filterAttrs ({ is_trusted ? false }: is_trusted) config.users)) ++ [ "root" ];
${config.user.name} = mkAliasDefinitions options.user; in
}; {
trusted-users = users;
nix.settings = let users = [ "root" config.user.name ]; in allowed-users = users;
{ };
trusted-users = users;
allowed-users = users;
};
}; };
} }

View file

@ -89,56 +89,5 @@ in
log_level = "DEBUG"; log_level = "DEBUG";
}; };
}; };
# create.configFile.btop-theme = let
# inherit (config.modules.themes) active;
# in
# mkIf (active != null) {
# target = "btop/themes/${active}.theme";
# text = ''
# theme[main_bg]="bg"
# theme[main_fg]="fg"
# theme[title]="fg"
# theme[hi_fg]="highlight"
# theme[selected_bg]="border"
# theme[selected_fg]="bg"
# theme[inactive_fg]="brightBlack"
# theme[graph_text]="brightYellow"
# theme[meter_bg]="brightblack"
# theme[proc_misc]="brightYellow"
# theme[cpu_box]="brightCyan"
# theme[mem_box]="brightGreen"
# theme[net_box]="brightMagenta"
# theme[proc_box]="brightYellow"
# theme[div_line]="brightblack"
# theme[temp_start]="brightYellow"
# theme[temp_mid]="panelbg"
# theme[temp_end]="brightRed"
# theme[cpu_start]="brightCyan"
# theme[cpu_mid]="border"
# theme[cpu_end]="brightGreen"
# theme[free_start]="brightGreen"
# theme[free_mid]="brightGreen"
# theme[free_end]="brightGreen"
# theme[cached_start]="brightYellow"
# theme[cached_mid]="brightYellow"
# theme[cached_end]="brightMagenta"
# theme[available_start]="brightYellow"
# theme[available_mid]="brightYellow"
# theme[available_end]="brightYellow"
# theme[used_start]="panelbg"
# theme[used_mid]="panelbg"
# theme[used_end]="brightRed"
# theme[download_start]="brightBlue"
# theme[download_mid]="brightBlue"
# theme[download_end]="brightMagenta"
# theme[upload_start]="brightBlue"
# theme[upload_mid]="brightBlue"
# theme[upload_end]="brightMagenta"
# theme[process_start]="brightCyan"
# theme[process_mid]="border"
# theme[process_end]="brightGreen"
# '';
# };
}; };
} }

View file

@ -159,7 +159,7 @@ in
# }; # };
}; };
create.configFile.zsh-abbreviations = { hm.xdg.configFile."zsh-abbreviations" = {
target = "zsh/abbreviations"; target = "zsh/abbreviations";
text = let text = let
abbrevs = import "${config.sneeuwvlok.configDir}/shell-abbr"; abbrevs = import "${config.sneeuwvlok.configDir}/shell-abbr";

View file

@ -3,6 +3,7 @@
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
kdePackages.kwallet-pam kdePackages.kwallet-pam
bitwarden bitwarden
sops
]; ];
security = { security = {