From 0e5aa6568e9876eade5bef40786efb4c687f25ba Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 07:28:25 -0700 Subject: [PATCH 1/5] flake/home: release -> master --- flake.lock | 7 +++---- flake.nix | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index f36841e..3bf8a9e 100644 --- a/flake.lock +++ b/flake.lock @@ -118,16 +118,15 @@ ] }, "locked": { - "lastModified": 1612902587, - "narHash": "sha256-VZ7Z1OMFf5ReObu3CCVBsC2DWloTYDjqW1onUKejVrE=", + "lastModified": 1616318638, + "narHash": "sha256-E6ABXtzw6bHmrIirB1sJL6S2MEa3sfcvRLzRa92frCo=", "owner": "nix-community", "repo": "home-manager", - "rev": "209566c752c4428c7692c134731971193f06b37c", + "rev": "ddcd476603dfd3388b1dc8234fa9d550156a51f5", "type": "github" }, "original": { "owner": "nix-community", - "ref": "release-20.09", "repo": "home-manager", "type": "github" } diff --git a/flake.nix b/flake.nix index aa89c77..b10f6b6 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ devshell.url = "github:numtide/devshell"; flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; - home.url = "github:nix-community/home-manager/release-20.09"; + home.url = "github:nix-community/home-manager"; home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "override"; From 416a52fcd3feb637dca28b860141b26430389ce7 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 07:34:38 -0700 Subject: [PATCH 2/5] users: add and export user modules and import them in hosts --- extern/default.nix | 10 +++++----- flake.nix | 4 ++++ hosts/default.nix | 8 ++++++-- users/modules/module-list.nix | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 users/modules/module-list.nix diff --git a/extern/default.nix b/extern/default.nix index 8a4e36f..5484eb4 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -1,7 +1,4 @@ { inputs }: with inputs; -let - hmModules = { }; -in { modules = [ home.nixosModules.home-manager @@ -19,9 +16,12 @@ in # passed to all nixos modules specialArgs = { - inherit hmModules; - overrideModulesPath = "${override}/nixos/modules"; hardware = nixos-hardware.nixosModules; }; + + # added to home-manager + userModules = [ + ]; + } diff --git a/flake.nix b/flake.nix index b10f6b6..0e945c5 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,10 @@ let moduleList = import ./modules/module-list.nix; in lib.pathsToImportedAttrs moduleList; + homeModules = + let moduleList = import ./users/modules/module-list.nix; + in lib.pathsToImportedAttrs moduleList; + overlay = import ./pkgs; overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays); diff --git a/hosts/default.nix b/hosts/default.nix index ba6ad91..1e8dec3 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -35,8 +35,12 @@ let }; global = { config, ... }: { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + + sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); + }; hardware.enableRedistributableFirmware = lib.mkDefault true; diff --git a/users/modules/module-list.nix b/users/modules/module-list.nix new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/users/modules/module-list.nix @@ -0,0 +1 @@ +[] From cc52cd9fa25c59bce42b724070697b149a65fee1 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 07:36:23 -0700 Subject: [PATCH 3/5] users: wire up all user profiles to userSuites and pass to home-manager --- extern/default.nix | 3 +++ hosts/default.nix | 3 ++- suites/default.nix | 16 ++++++++++++++-- users/nixos/default.nix | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/extern/default.nix b/extern/default.nix index 5484eb4..66f4e78 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -24,4 +24,7 @@ userModules = [ ]; + # passed to all home-manager modules + userSpecialArgs = { + }; } diff --git a/hosts/default.nix b/hosts/default.nix index 1e8dec3..930f5f2 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -39,6 +39,7 @@ let useGlobalPkgs = true; useUserPackages = true; + extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; }; sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules); }; @@ -71,7 +72,7 @@ let flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; }; - specialArgs = extern.specialArgs // { inherit suites; }; + specialArgs = extern.specialArgs // { suites = suites.system; }; mkHostConfig = hostName: let diff --git a/suites/default.nix b/suites/default.nix index 7eb11e5..e1b7d66 100644 --- a/suites/default.nix +++ b/suites/default.nix @@ -3,6 +3,7 @@ let inherit (lib) dev; profiles = dev.os.mkProfileAttrs (toString ../profiles); + userProfiles = dev.os.mkProfileAttrs (toString ../users/profiles); users = dev.os.mkProfileAttrs (toString ../users); allProfiles = @@ -17,7 +18,18 @@ let suites = with profiles; rec { base = [ users.nixos users.root ]; }; + + # available as 'suites' within the home-manager configuration + userSuites = with userProfiles; rec { + base = [ direnv git ]; + }; + in -lib.mapAttrs (_: v: dev.os.profileMap v) suites // { - inherit allProfiles allUsers; +{ + system = lib.mapAttrs (_: v: dev.os.profileMap v) suites // { + inherit allProfiles allUsers; + }; + user = lib.mapAttrs (_: v: dev.os.profileMap v) userSuites // { + allProfiles = userProfiles; + }; } diff --git a/users/nixos/default.nix b/users/nixos/default.nix index 38bf20f..700467b 100644 --- a/users/nixos/default.nix +++ b/users/nixos/default.nix @@ -1,7 +1,7 @@ { ... }: { - home-manager.users.nixos = { - imports = [ ../profiles/git ../profiles/direnv ]; + home-manager.users.nixos = { suites, ... }: { + imports = suites.base; }; users.users.nixos = { From dc9d9877b87c4bce3d82503b1b9974c9ff5417a6 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 07:37:11 -0700 Subject: [PATCH 4/5] export homeConfigurations for all user@host pairs and add better home-manager only defaults --- flake.nix | 5 ++--- lib/devos/default.nix | 2 +- lib/devos/devosSystem.nix | 19 +++++++++++++++++++ lib/devos/mkHomeActivation.nix | 12 ------------ lib/devos/mkHomeConfigurations.nix | 12 ++++++++++++ shell/flk.sh | 2 +- users/README.md | 2 +- 7 files changed, 36 insertions(+), 18 deletions(-) delete mode 100644 lib/devos/mkHomeActivation.nix create mode 100644 lib/devos/mkHomeConfigurations.nix diff --git a/flake.nix b/flake.nix index 0e945c5..082f501 100644 --- a/flake.nix +++ b/flake.nix @@ -47,6 +47,8 @@ }); }); + homeConfigurations = os.mkHomeConfigurations; + nixosModules = let moduleList = import ./modules/module-list.nix; in lib.pathsToImportedAttrs moduleList; @@ -86,9 +88,6 @@ devShell = import ./shell { inherit self system; }; - - legacyPackages.hmActivationPackages = - os.mkHomeActivation; } ); in diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 32ce490..bf109ba 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -19,7 +19,7 @@ devosSystem = dev.callLibs ./devosSystem.nix; - mkHomeActivation = dev.callLibs ./mkHomeActivation.nix; + mkHomeConfigurations = dev.callLibs ./mkHomeConfigurations.nix; mkPackages = dev.callLibs ./mkPackages.nix; } diff --git a/lib/devos/devosSystem.nix b/lib/devos/devosSystem.nix index f8d08f9..8245818 100644 --- a/lib/devos/devosSystem.nix +++ b/lib/devos/devosSystem.nix @@ -73,10 +73,29 @@ lib.nixosSystem (args // { }) ]; })).config; + hmConfig = (lib.nixosSystem + (args // { + modules = moduleList ++ [ + ({ config, ... }: { + home-manager.useUserPackages = lib.mkForce false; + home-manager.sharedModules = [ + { + home.packages = config.environment.systemPackages; + home.sessionVariables = { + inherit (config.environment.sessionVariables) NIX_PATH; + }; + xdg.configFile."nix/registry.json".text = + config.environment.etc."nix/registry.json".text; + } + ]; + }) + ]; + })).config; in moduleList ++ [{ system.build = { iso = isoConfig.system.build.isoImage; + homes = hmConfig.home-manager.users; }; }]; }) diff --git a/lib/devos/mkHomeActivation.nix b/lib/devos/mkHomeActivation.nix deleted file mode 100644 index 6b7176a..0000000 --- a/lib/devos/mkHomeActivation.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ lib, self, ... }: - -let hmConfigs = - lib.mapAttrs - (_: config: config.config.home-manager.users) - self.nixosConfigurations; -in -lib.mapAttrs - (_: x: lib.mapAttrs - (_: cfg: cfg.home.activationPackage) - x) - hmConfigs diff --git a/lib/devos/mkHomeConfigurations.nix b/lib/devos/mkHomeConfigurations.nix new file mode 100644 index 0000000..ab84393 --- /dev/null +++ b/lib/devos/mkHomeConfigurations.nix @@ -0,0 +1,12 @@ +{ lib, self, ... }: + +with lib; +let + mkHomes = host: config: + mapAttrs' (user: v: nameValuePair "${user}@${host}" v) + config.config.system.build.homes; + + hmConfigs = mapAttrs mkHomes self.nixosConfigurations; + +in +foldl recursiveUpdate {} (attrValues hmConfigs) diff --git a/shell/flk.sh b/shell/flk.sh index d22b327..344e9d3 100755 --- a/shell/flk.sh +++ b/shell/flk.sh @@ -81,7 +81,7 @@ case "$1" in ;; "home") - ref="$DEVSHELL_ROOT/#hmActivationPackages.$2.$3" + ref="$DEVSHELL_ROOT/#homeConfigurations.$3@$2.home.activationPackage" if [[ "$4" == "switch" ]]; then nix build "$ref" && result/activate && diff --git a/users/README.md b/users/README.md index c36aa3a..7000c8e 100644 --- a/users/README.md +++ b/users/README.md @@ -42,7 +42,7 @@ flk home NixOS nixos switch ### Manually from outside the project: ```sh # build -nix build "github:divnix/devos#hmActivationPackages.NixOS.nixos" +nix build "github:divnix/devos#homeConfigurations.nixos@NixOS.home.activationPackage" # activate ./result/activate && unlink result From 6d51ed02669c93fbc02950475deeb6dc11f6a010 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Tue, 23 Mar 2021 07:44:57 -0700 Subject: [PATCH 5/5] users: add Home Manager section to doc --- users/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/users/README.md b/users/README.md index 7000c8e..5fdb029 100644 --- a/users/README.md +++ b/users/README.md @@ -22,10 +22,17 @@ your users. For a fully fleshed out example, check out the developers personal ``` +## Home Manager +Home Manager support follows the same principles as regular nixos configurations. +All modules defined in [user modules](./modules/module-list.nix) will be imported to +Home Manager. All profiles are availabe in [suites](../suites/default.nix) as userProfiles. +The `userSuites` output will be available in your Home Manager Configuration as +the special argument, `suites`. + ## External Usage You can easily use the defined home-manager configurations outside of NixOS -using the `hmActivations` meta-package defined in the flakes `legacyPackages` -output. The [flk](../doc/flk) helper script makes this even easier. +using the `homeConfigurations` flake output. The [flk](../doc/flk) helper +script makes this even easier. This is great for keeping your environment consistent across Unix systems, including OSX.