refactor: separate NixOS and Home-Manager configuration

This commit is contained in:
Yorick Barbanneau 2024-10-09 00:37:47 +02:00
parent 9edca93fd5
commit d446f84030
5 changed files with 75 additions and 127 deletions

100
flake.nix
View file

@ -17,7 +17,7 @@
}; };
}; };
outputs = { self, nixpkgs, home-manager, nur, nixgl, sops-nix, ... }@inputs: outputs = { self, nixpkgs, home-manager, nur, nixgl, sops-nix, ... }@inputs:
let let
stateVersion = "23.11"; stateVersion = "23.11";
allSystems = [ allSystems = [
@ -28,7 +28,35 @@ let
forAllSystems = fn: forAllSystems = fn:
nixpkgs.lib.genAttrs allSystems nixpkgs.lib.genAttrs allSystems
(system: fn { pkgs = import nixpkgs { inherit system; }; }); (system: fn { pkgs = import nixpkgs { inherit system; }; });
in {
createNixosSystem = { system, hostname, username ? "ephase" }: nixpkgs.lib.nixosSystem {
system = system;
specialArgs = {
inherit stateVersion inputs;
hostname = hostname;
username = username;
};
modules = [
./nixos/default.nix
];
};
createHomeConfiguration = { system ? "x86_64-linux", hostname, username ? "ephase" }:
home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
system = system;
overlays = [ nixgl.overlay ];
};
extraSpecialArgs = {
inherit stateVersion inputs;
hostname = hostname;
username = username;
};
modules = [
./home-manager/default.nix
];
};
in {
devShells = forAllSystems ({ pkgs }: { devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell { default = pkgs.mkShell {
name = "nixfiles"; name = "nixfiles";
@ -46,72 +74,20 @@ in {
}; };
}); });
nixosConfigurations = { nixosConfigurations = {
morty = nixpkgs.lib.nixosSystem { morty = createNixosSystem { system = "x86_64-linux"; hostname = "morty"; };
system = "x86_64-linux"; mrmeeseeks = createNixosSystem { system = "x86_64-linux"; hostname = "mrmeeseeks";};
specialArgs = { luci = createNixosSystem { system = "x86_64-linux"; hostname = "luci"; };
inherit stateVersion inputs;
hostname = "morty";
username = "ephase";
};
modules = [
./nixos/default.nix
home-manager.nixosModule
];
};
mrmeeseeks = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {
inherit stateVersion inputs;
hostname = "mrmeeseeks";
username = "ephase";
};
modules = [
./nixos/default.nix
home-manager.nixosModule
];
};
luci = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {
inherit stateVersion inputs;
hostname = "luci";
username = "ephase";
};
modules = [
./nixos/default.nix
home-manager.nixosModule
];
};
}; };
homeConfigurations = { homeConfigurations = {
rick = home-manager.lib.homeManagerConfiguration { "ephase@rick" = createHomeConfiguration { system = "aarch64-linux"; hostname = "rick";};
pkgs = import nixpkgs { "ephase@luci" = createHomeConfiguration { system = "x86_64-linux"; hostname = "luci";};
system = "aarch64-linux"; "ephase@morty" = createHomeConfiguration { system = "x86_64-linux"; hostname = "morty";};
overlays = [ nixgl.overlay ]; "ephase@mrmeeseeks" = createHomeConfiguration { system = "x86_64-linux"; hostname = "mrmeeseeks";};
}; "yorick-barbanneau@work" = createHomeConfiguration {
extraSpecialArgs = {
inherit stateVersion inputs;
hostname = "rick";
username = "ephase";
};
modules = [
./home-manager/default.nix
];
};
work = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
system = "x86_64-linux"; system = "x86_64-linux";
overlays = [ nixgl.overlay ];
};
extraSpecialArgs = {
inherit stateVersion inputs;
hostname = "work"; hostname = "work";
username = "yorick-barbanneau"; username = "yorick-barbanneau";
}; };
modules = [
./home-manager/default.nix
];
};
}; };
}; };
} }

View file

@ -1,13 +1,4 @@
{ lib, hostname, ...}: _:
{ {
programs.home-manager.enable = true;
home.sessionPath = [
"$HOME/.local/bin"
];
imports = [
../hosts/${hostname}/home-config.nix
../modules/home-manager/default.nix
] ++ lib.optional (
builtins.pathExists ../hosts/${hostname}/includes/home-manager.nix
) ../hosts/${hostname}/includes/home-manager.nix;
} }

View file

@ -1,12 +1,23 @@
{ stateVersion, username, inputs, ... }: { inputs, lib, stateVersion, username, hostname, ... }:
{ {
home.stateVersion = stateVersion;
home.username = "${username}";
home.homeDirectory = "/home/${username}";
fonts.fontconfig.enable = true;
imports = [ imports = [
inputs.sops-nix.homeManagerModules.sops inputs.sops-nix.homeManagerModules.sops
./base.nix ../hosts/${hostname}/home-config.nix
../nixos/includes/system/overlay.nix ../nixos/includes/system/overlay.nix
../modules/home-manager/default.nix
] ++ lib.optional (
builtins.pathExists ../hosts/${hostname}/includes/home-manager.nix
) ../hosts/${hostname}/includes/home-manager.nix;
nixpkgs.config.allowUnfree = true;
programs.home-manager.enable = true;
fonts.fontconfig.enable = true;
home = {
inherit stateVersion username;
homeDirectory = "/home/${username}";
sessionPath = [
"$HOME/.local/bin"
]; ];
};
} }

View file

@ -1,4 +1,4 @@
{ inputs, pkgs, stateVersion, hostname, username, hostConfig, ... }: { pkgs, stateVersion, hostname, ... }:
{ {
imports = [ # Include the results of the hardware scan. imports = [ # Include the results of the hardware scan.
../hosts/${hostname}/hardware-configuration.nix ../hosts/${hostname}/hardware-configuration.nix
@ -15,11 +15,9 @@
./includes/system/overlay.nix ./includes/system/overlay.nix
]; ];
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
boot.kernelPackages = pkgs.linuxPackages_latest;
boot.kernelPackages = pkgs.linuxPackages_latest;
networking.hostName = hostname; networking.hostName = hostname;
console = { console = {
@ -30,32 +28,10 @@
useXkbConfig = true; # use xkbOptions in tty. useXkbConfig = true; # use xkbOptions in tty.
}; };
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
git git
zsh zsh
]; ];
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit hostConfig;
inherit hostname;
};
# NixOS system-wide home-manager configuration
sharedModules = [
inputs.sops-nix.homeManagerModules.sops
];
users.${username} = {
home.stateVersion = stateVersion;
imports = [
../home-manager/base.nix
];
};
};
system.stateVersion = stateVersion; system.stateVersion = stateVersion;
} }

View file

@ -17,19 +17,19 @@ tasks:
sources: sources:
- "**/*.nix" - "**/*.nix"
build:*: nixos:build:*:
vars: vars:
TARGET: "{{index .MATCH 0}}" TARGET: "{{index .MATCH 0}}"
cmds: cmds:
- nixos-rebuild --flake .#{{.TARGET}} build - nixos-rebuild --flake .#{{.TARGET}} build
switch:*: nixos:switch:*:
vars: vars:
TARGET: "{{index .MATCH 0}}" TARGET: "{{index .MATCH 0}}"
cmds: cmds:
- doas nixos-rebuild --flake .#{{.TARGET}} switch - doas nixos-rebuild --flake .#{{.TARGET}} switch
test:*: nixos:test:*:
vars: vars:
TARGET: "{{index .MATCH 0}}" TARGET: "{{index .MATCH 0}}"
cmds: cmds:
@ -41,12 +41,6 @@ tasks:
cmds: cmds:
- home-manager build --flake .#{{.TARGET}} - home-manager build --flake .#{{.TARGET}}
home:test:*:
vars:
TARGET: "{{index .MATCH 0}}"
cmds:
- home-manager test --flake .#{{.TARGET}}
home:switch:*: home:switch:*:
vars: vars:
TARGET: "{{index .MATCH 0}}" TARGET: "{{index .MATCH 0}}"