Merge pull request #93 from Pacman99/home-manager-only
users: Initial home-manager only configurations(non-nixos systems)
This commit is contained in:
commit
5e2f4d09ef
4 changed files with 70 additions and 6 deletions
37
README.md
37
README.md
|
@ -131,6 +131,43 @@ They are placed in the git staging area automatically because they would be
|
||||||
invisible to the flake otherwise, but it is best to move what you need from
|
invisible to the flake otherwise, but it is best to move what you need from
|
||||||
them directly into your hosts file and commit that instead.
|
them directly into your hosts file and commit that instead.
|
||||||
|
|
||||||
|
## Home Manager Integration
|
||||||
|
The home-manager nixos module is available for each host. It is meant
|
||||||
|
to be used in the user profiles, you can find an example in the nixos user profile
|
||||||
|
|
||||||
|
The home-manager configuration for each user in each system is available in the
|
||||||
|
outputs as homeConfigurations and the activation packages in hmActivationPackages.
|
||||||
|
|
||||||
|
This allows you to just build the home-manager environment without the rest of the
|
||||||
|
system configuration. The feature is useful on systems without nixos or root access.
|
||||||
|
|
||||||
|
Lets say you want to activate the home configuration for the user `nixos` in the
|
||||||
|
host `NixOS`.
|
||||||
|
|
||||||
|
With the flk script:
|
||||||
|
```sh
|
||||||
|
# You can build it using
|
||||||
|
flk home NixOS nixos
|
||||||
|
# and activate with
|
||||||
|
./result/activate
|
||||||
|
|
||||||
|
# Or do both like this
|
||||||
|
flk home NixOS nixos switch
|
||||||
|
```
|
||||||
|
|
||||||
|
This can also be done manually:
|
||||||
|
```sh
|
||||||
|
|
||||||
|
# With hmActivationPackages, what the flk script uses
|
||||||
|
nix build ./#hmActivationPackages.NixOS.nixos
|
||||||
|
|
||||||
|
# Or with homeConfigurations,
|
||||||
|
nix build ./#homeConfigurations.NixOS.nixos.home.activationPackage
|
||||||
|
# this is hard to debug though, due to nix build's fallback to packages
|
||||||
|
|
||||||
|
# The configuration can then be activated like before
|
||||||
|
```
|
||||||
|
|
||||||
## Build an ISO
|
## Build an ISO
|
||||||
|
|
||||||
You can make an ISO and customize it by modifying the [niximg](./hosts/niximg.nix)
|
You can make an ISO and customize it by modifying the [niximg](./hosts/niximg.nix)
|
||||||
|
|
17
flake.nix
17
flake.nix
|
@ -29,7 +29,8 @@
|
||||||
inherit (builtins) attrValues;
|
inherit (builtins) attrValues;
|
||||||
inherit (flake-utils.lib) eachDefaultSystem flattenTreeSystem;
|
inherit (flake-utils.lib) eachDefaultSystem flattenTreeSystem;
|
||||||
inherit (nixos.lib) recursiveUpdate;
|
inherit (nixos.lib) recursiveUpdate;
|
||||||
inherit (self.lib) overlays nixosModules genPackages pkgImport;
|
inherit (self.lib) overlays nixosModules genPackages pkgImport
|
||||||
|
genHomeActivationPackages;
|
||||||
|
|
||||||
externOverlays = [ nur.overlay devshell.overlay ];
|
externOverlays = [ nur.overlay devshell.overlay ];
|
||||||
externModules = [
|
externModules = [
|
||||||
|
@ -52,6 +53,11 @@
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
homeConfigurations =
|
||||||
|
builtins.mapAttrs
|
||||||
|
(_: config: config.config.home-manager.users)
|
||||||
|
self.nixosConfigurations;
|
||||||
|
|
||||||
overlay = import ./pkgs;
|
overlay = import ./pkgs;
|
||||||
|
|
||||||
lib = import ./lib {
|
lib = import ./lib {
|
||||||
|
@ -90,10 +96,17 @@
|
||||||
in
|
in
|
||||||
pkgImport nixos overlays system;
|
pkgImport nixos overlays system;
|
||||||
|
|
||||||
packages = flattenTreeSystem system
|
packages =
|
||||||
|
let
|
||||||
|
packages' = flattenTreeSystem system
|
||||||
(genPackages {
|
(genPackages {
|
||||||
inherit self pkgs;
|
inherit self pkgs;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
homeActivationPackages = genHomeActivationPackages
|
||||||
|
self.homeConfigurations;
|
||||||
|
in
|
||||||
|
recursiveUpdate packages' homeActivationPackages;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit packages;
|
inherit packages;
|
||||||
|
|
|
@ -73,6 +73,15 @@ in
|
||||||
(recursiveUpdate cachixAttrs modulesAttrs)
|
(recursiveUpdate cachixAttrs modulesAttrs)
|
||||||
profilesAttrs;
|
profilesAttrs;
|
||||||
|
|
||||||
|
genHomeActivationPackages = hmConfigs: {
|
||||||
|
hmActivationPackages =
|
||||||
|
builtins.mapAttrs
|
||||||
|
(_: x: builtins.mapAttrs
|
||||||
|
(_: cfg: cfg.home.activationPackage)
|
||||||
|
x)
|
||||||
|
hmConfigs;
|
||||||
|
};
|
||||||
|
|
||||||
genPackages = { self, pkgs }:
|
genPackages = { self, pkgs }:
|
||||||
let
|
let
|
||||||
inherit (self) overlay overlays;
|
inherit (self) overlay overlays;
|
||||||
|
|
|
@ -12,7 +12,7 @@ let
|
||||||
|
|
||||||
flk = pkgs.writeShellScriptBin "flk" ''
|
flk = pkgs.writeShellScriptBin "flk" ''
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] ]"
|
echo "Usage: $(basename "$0") [ iso | up | install {host} | {host} [switch|boot|test] | home {host} {user} [switch] ]"
|
||||||
elif [[ "$1" == "up" ]]; then
|
elif [[ "$1" == "up" ]]; then
|
||||||
mkdir -p $DEVSHELL_ROOT/up
|
mkdir -p $DEVSHELL_ROOT/up
|
||||||
hostname=$(hostname)
|
hostname=$(hostname)
|
||||||
|
@ -27,6 +27,11 @@ let
|
||||||
nix build $DEVSHELL_ROOT#nixosConfigurations.niximg.${build}.isoImage "${"\${@:2}"}"
|
nix build $DEVSHELL_ROOT#nixosConfigurations.niximg.${build}.isoImage "${"\${@:2}"}"
|
||||||
elif [[ "$1" == "install" ]]; then
|
elif [[ "$1" == "install" ]]; then
|
||||||
sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${"\${@:3}"}"
|
sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${"\${@:3}"}"
|
||||||
|
elif [[ "$1" == "home" ]]; then
|
||||||
|
nix build ./#hmActivationPackages.$2.$3
|
||||||
|
if [[ "$4" == "switch" ]]; then
|
||||||
|
./result/activate && unlink result
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${"\${@:2}"}"
|
sudo nixos-rebuild --flake "$DEVSHELL_ROOT#$1" "${"\${@:2}"}"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue