From dd1ef4cf6c9100adf9e6771619e6c9dc7006e325 Mon Sep 17 00:00:00 2001 From: NullBite Date: Mon, 22 Jan 2024 14:16:17 +0100 Subject: [PATCH 1/7] Add start of home-manager multi user builder --- flake.nix | 11 +++++++++-- home/root.nix | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 home/root.nix diff --git a/flake.nix b/flake.nix index ab4764c..e7f7dc7 100644 --- a/flake.nix +++ b/flake.nix @@ -47,7 +47,14 @@ # This function produces a module that adds the home-manager module to the # system and configures the given module to the user's Home Manager # configuration - homeManagerInit = {system, username ? _username , module}: { config, lib, pkgs, ... }: { + homeManagerInit = {system, username ? _username , module ? _ : {}, users ? { ${username} = module;} }: + let + # TODO ooprs i forgor home-manager needs a state version and i currently + # don't pass the system name to this so there is no way to derive this + # value properly and it should probably be derived with mkSystem + users = users // { root = ./home/root.nix;}; + in + { config, lib, pkgs, ... }: { imports = [ inputs.home-manager.nixosModules.home-manager ]; @@ -55,7 +62,7 @@ home-manager = { useGlobalPkgs = true; useUserPackages = true; - users.${username} = module; + inherit users; extraSpecialArgs = { inherit inputs outputs vars; extraPkgs = mkExtraPkgs system; diff --git a/home/root.nix b/home/root.nix new file mode 100644 index 0000000..f857ce8 --- /dev/null +++ b/home/root.nix @@ -0,0 +1,2 @@ +{ config, lib, pkgs, ... }@args: +{ } From 750fb580e17342aabde9f220461740c9ef1ed520 Mon Sep 17 00:00:00 2001 From: NullBite Date: Mon, 22 Jan 2024 20:40:08 +0100 Subject: [PATCH 2/7] Add stateVersion and multi-user to homeManagerInit --- flake.nix | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index e7f7dc7..8f8bea2 100644 --- a/flake.nix +++ b/flake.nix @@ -47,14 +47,19 @@ # This function produces a module that adds the home-manager module to the # system and configures the given module to the user's Home Manager # configuration - homeManagerInit = {system, username ? _username , module ? _ : {}, users ? { ${username} = module;} }: + homeManagerInit = {system, username ? _username , module ? _ : {}, userModules ? { ${username} = [ module ] ;}, stateVersion }: + { config, lib, pkgs, ... }: let - # TODO ooprs i forgor home-manager needs a state version and i currently - # don't pass the system name to this so there is no way to derive this - # value properly and it should probably be derived with mkSystem - users = users // { root = ./home/root.nix;}; + mapUserModules = lib.attrsets.mapAttrs (user: modules: {...}: + { + imports = modules; + config = { + home = { inherit stateVersion; }; + }; + }); + users = mapUserModules userModules; in - { config, lib, pkgs, ... }: { + { imports = [ inputs.home-manager.nixosModules.home-manager ]; @@ -72,14 +77,23 @@ # This function produces a nixosSystem which imports configuration.nix and # a Home Manager home.nix for the given user from ./hosts/${hostname}/ - mkSystem = {system, hostname, username ? _username}: + mkSystem = {system, hostname, username ? _username, stateVersion}: lib.nixosSystem { inherit system; modules = [ + ({pkgs, config, lib, ...}@args: + { + # Values for every single system that would not conceivably need + # to be made modular + system.stateVersion = stateVersion; + # not having the freedom to install unfree programs is unfree + nixpkgs.config.allowUnfree = true; + nix.settings.experimental-features = ["nix-command" "flakes" ]; + }) ./hosts/${hostname}/configuration.nix (homeManagerInit { module = import ./hosts/${hostname}/home.nix; - inherit username system; + inherit username system stateVersion; }) ]; specialArgs = { @@ -116,6 +130,7 @@ (homeManagerInit { module = import ./hosts/slab/home.nix; inherit system; + stateVersion = "23.11"; }) ]; specialArgs = { @@ -134,6 +149,7 @@ (homeManagerInit { module = import ./hosts/nullbox/home.nix; inherit system; + stateVersion = "23.11"; }) ]; }; From 922cbe537827c953c85166246489dac1d24c145e Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 23 Jan 2024 15:17:18 +0100 Subject: [PATCH 3/7] add nix-index-database to inputs --- flake.lock | 21 +++++++++++++++++++++ flake.nix | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/flake.lock b/flake.lock index 5514a3b..acfbfa7 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,26 @@ "type": "github" } }, + "nix-index-database": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705806513, + "narHash": "sha256-FcOmNjhHFfPz2udZbRpZ1sfyhVMr+C2O8kOxPj+HDDk=", + "owner": "nix-community", + "repo": "nix-index-database", + "rev": "f8e04fbcebcc24cebc91989981bd45f69b963ed7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-index-database", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1705641746, @@ -72,6 +92,7 @@ "root": { "inputs": { "home-manager": "home-manager", + "nix-index-database": "nix-index-database", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "pkg-android-tools": "pkg-android-tools" diff --git a/flake.nix b/flake.nix index 8f8bea2..18d9841 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,12 @@ # 33.0.3p2 as suggested by https://xdaforums.com/t/guide-january-3-2024-root-pixel-7-pro-unlock-bootloader-pass-safetynet-both-slots-bootable-more.4505353/ # android tools versions [ 34.0.0, 34.0.5 ) causes bootloops somehow and 34.0.5 isn't in nixpkgs yet pkg-android-tools.url = "github:NixOS/nixpkgs/55070e598e0e03d1d116c49b9eff322ef07c6ac6"; + + # provides an up-to-date database for comma + nix-index-database = { + url = "github:nix-community/nix-index-database"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, nixpkgs, nixpkgs-unstable, ... }@inputs: From 49e9fad6142ba3a1f861a36af8417e19eec47ae5 Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 23 Jan 2024 15:37:08 +0100 Subject: [PATCH 4/7] Add preliminary multi-user to homeManagerInit --- flake.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 18d9841..686575d 100644 --- a/flake.nix +++ b/flake.nix @@ -53,7 +53,7 @@ # This function produces a module that adds the home-manager module to the # system and configures the given module to the user's Home Manager # configuration - homeManagerInit = {system, username ? _username , module ? _ : {}, userModules ? { ${username} = [ module ] ;}, stateVersion }: + homeManagerInit = {system, username ? _username , module ? _ : {}, rootModule ? _:{}, userModules ? { ${username} = [ module ] ; root = [ rootModule ]; }, stateVersion }: { config, lib, pkgs, ... }: let mapUserModules = lib.attrsets.mapAttrs (user: modules: {...}: @@ -134,9 +134,11 @@ ./system/android.nix # ./system/hyprland.nix (homeManagerInit { - module = import ./hosts/slab/home.nix; + # module = import ./hosts/slab/home.nix; inherit system; stateVersion = "23.11"; + # rootModule = import ./home/root.nix; + userModules = { ${username} = [(import ./hosts/slab/home.nix)]; root = [(import ./home/root.nix)]; }; }) ]; specialArgs = { From 3ebd030fecb56d0712a52c2f6a092cff4d2834dc Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 23 Jan 2024 22:35:26 +0100 Subject: [PATCH 5/7] Set default root module to ./home/root.nix --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 686575d..f570e90 100644 --- a/flake.nix +++ b/flake.nix @@ -53,7 +53,7 @@ # This function produces a module that adds the home-manager module to the # system and configures the given module to the user's Home Manager # configuration - homeManagerInit = {system, username ? _username , module ? _ : {}, rootModule ? _:{}, userModules ? { ${username} = [ module ] ; root = [ rootModule ]; }, stateVersion }: + homeManagerInit = {system, username ? _username , module ? _ : {}, rootModule ? (import ./home/root.nix), userModules ? { ${username} = [ module ] ; root = [ rootModule ]; }, stateVersion }: { config, lib, pkgs, ... }: let mapUserModules = lib.attrsets.mapAttrs (user: modules: {...}: From 991320105dc21f32578484765dba0e140296f407 Mon Sep 17 00:00:00 2001 From: NullBite Date: Wed, 24 Jan 2024 00:02:30 +0100 Subject: [PATCH 6/7] Add an actual multi-user home configuration --- home/comma.nix | 10 ++++++++++ home/root.nix | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 home/comma.nix diff --git a/home/comma.nix b/home/comma.nix new file mode 100644 index 0000000..203f26a --- /dev/null +++ b/home/comma.nix @@ -0,0 +1,10 @@ +{ lib, pkgs, config, inputs, ... } @args: +{ + imports = [ + inputs.nix-index-database.hmModules.nix-index + ]; + + home.packages = with pkgs; [ + comma + ]; +} diff --git a/home/root.nix b/home/root.nix index f857ce8..266a894 100644 --- a/home/root.nix +++ b/home/root.nix @@ -1,2 +1,6 @@ { config, lib, pkgs, ... }@args: -{ } +{ + imports = [ + ./comma.nix + ]; +} From 7b90856ce75f3bd66a7568b7474d7302a8f98fbe Mon Sep 17 00:00:00 2001 From: NullBite Date: Wed, 24 Jan 2024 00:04:57 +0100 Subject: [PATCH 7/7] Switch slab to mkSystem --- flake.nix | 25 +++---------------------- hosts/slab/configuration.nix | 7 +++++++ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index f570e90..ca0b2d2 100644 --- a/flake.nix +++ b/flake.nix @@ -122,29 +122,10 @@ homeManagerModules = (import ./modules/home-manager) moduleInputs; nixosConfigurations = { - slab = lib.nixosSystem rec { + slab = mkSystem { system = "x86_64-linux"; - modules = [ - ./hosts/slab/configuration.nix - ./hosts/slab/nvidia-optimus.nix - ./system/remote.nix - ./system/plasma.nix - ./system/fragments/opengl.nix - ./system/gaming.nix - ./system/android.nix - # ./system/hyprland.nix - (homeManagerInit { - # module = import ./hosts/slab/home.nix; - inherit system; - stateVersion = "23.11"; - # rootModule = import ./home/root.nix; - userModules = { ${username} = [(import ./hosts/slab/home.nix)]; root = [(import ./home/root.nix)]; }; - }) - ]; - specialArgs = { - inherit inputs outputs vars; - extraPkgs = mkExtraPkgs system; - }; + hostname = "slab"; + stateVersion = "23.11"; }; nullbox = lib.nixosSystem rec { system = "x86_64-linux"; diff --git a/hosts/slab/configuration.nix b/hosts/slab/configuration.nix index 6548b65..c26dd38 100644 --- a/hosts/slab/configuration.nix +++ b/hosts/slab/configuration.nix @@ -16,6 +16,13 @@ imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix + + ./nvidia-optimus.nix + ../../system/remote.nix + ../../system/plasma.nix + ../../system/fragments/opengl.nix + ../../system/gaming.nix + ../../system/android.nix ]; networking.hostName = "slab";