From d446f840304029df855f8d98d80b3aa5fb4ed1a9 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Wed, 9 Oct 2024 00:37:47 +0200 Subject: [PATCH] refactor: separate NixOS and Home-Manager configuration --- flake.nix | 124 ++++++++++++++++----------------------- home-manager/base.nix | 13 +--- home-manager/default.nix | 25 +++++--- nixos/default.nix | 28 +-------- taskfile.yaml | 12 +--- 5 files changed, 75 insertions(+), 127 deletions(-) diff --git a/flake.nix b/flake.nix index 8d89bce..4bc95ff 100644 --- a/flake.nix +++ b/flake.nix @@ -17,18 +17,46 @@ }; }; outputs = { self, nixpkgs, home-manager, nur, nixgl, sops-nix, ... }@inputs: -let - stateVersion = "23.11"; + let + stateVersion = "23.11"; + + allSystems = [ + "x86_64-linux" # 64bit AMD/Intel x86 + "aarch64-linux" # 64bit ARM Linux + ]; - allSystems = [ - "x86_64-linux" # 64bit AMD/Intel x86 - "aarch64-linux" # 64bit ARM Linux - ]; - - forAllSystems = fn: - nixpkgs.lib.genAttrs allSystems - (system: fn { pkgs = import nixpkgs { inherit system; }; }); -in { + forAllSystems = fn: + nixpkgs.lib.genAttrs allSystems + (system: fn { pkgs = import nixpkgs { inherit system; }; }); + + 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 }: { default = pkgs.mkShell { name = "nixfiles"; @@ -46,71 +74,19 @@ in { }; }); nixosConfigurations = { - morty = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { - 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 - ]; - }; + morty = createNixosSystem { system = "x86_64-linux"; hostname = "morty"; }; + mrmeeseeks = createNixosSystem { system = "x86_64-linux"; hostname = "mrmeeseeks";}; + luci = createNixosSystem { system = "x86_64-linux"; hostname = "luci"; }; }; homeConfigurations = { - rick = home-manager.lib.homeManagerConfiguration { - pkgs = import nixpkgs { - system = "aarch64-linux"; - overlays = [ nixgl.overlay ]; - }; - 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"; - overlays = [ nixgl.overlay ]; - }; - extraSpecialArgs = { - inherit stateVersion inputs; - hostname = "work"; - username = "yorick-barbanneau"; - }; - modules = [ - ./home-manager/default.nix - ]; + "ephase@rick" = createHomeConfiguration { system = "aarch64-linux"; hostname = "rick";}; + "ephase@luci" = createHomeConfiguration { system = "x86_64-linux"; hostname = "luci";}; + "ephase@morty" = createHomeConfiguration { system = "x86_64-linux"; hostname = "morty";}; + "ephase@mrmeeseeks" = createHomeConfiguration { system = "x86_64-linux"; hostname = "mrmeeseeks";}; + "yorick-barbanneau@work" = createHomeConfiguration { + system = "x86_64-linux"; + hostname = "work"; + username = "yorick-barbanneau"; }; }; }; diff --git a/home-manager/base.nix b/home-manager/base.nix index 13a4a20..2501587 100644 --- a/home-manager/base.nix +++ b/home-manager/base.nix @@ -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; + } diff --git a/home-manager/default.nix b/home-manager/default.nix index 6470228..befa969 100644 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -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 = [ inputs.sops-nix.homeManagerModules.sops - ./base.nix + ../hosts/${hostname}/home-config.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" + ]; + }; } diff --git a/nixos/default.nix b/nixos/default.nix index 983345b..d8a2103 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,4 +1,4 @@ -{ inputs, pkgs, stateVersion, hostname, username, hostConfig, ... }: +{ pkgs, stateVersion, hostname, ... }: { imports = [ # Include the results of the hardware scan. ../hosts/${hostname}/hardware-configuration.nix @@ -15,11 +15,9 @@ ./includes/system/overlay.nix ]; - nixpkgs.config.allowUnfree = true; - - boot.kernelPackages = pkgs.linuxPackages_latest; +boot.kernelPackages = pkgs.linuxPackages_latest; networking.hostName = hostname; console = { @@ -30,32 +28,10 @@ useXkbConfig = true; # use xkbOptions in tty. }; - environment.systemPackages = with pkgs; [ git 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; } diff --git a/taskfile.yaml b/taskfile.yaml index 02f28c8..282de94 100644 --- a/taskfile.yaml +++ b/taskfile.yaml @@ -17,19 +17,19 @@ tasks: sources: - "**/*.nix" - build:*: + nixos:build:*: vars: TARGET: "{{index .MATCH 0}}" cmds: - nixos-rebuild --flake .#{{.TARGET}} build - switch:*: + nixos:switch:*: vars: TARGET: "{{index .MATCH 0}}" cmds: - doas nixos-rebuild --flake .#{{.TARGET}} switch - test:*: + nixos:test:*: vars: TARGET: "{{index .MATCH 0}}" cmds: @@ -41,12 +41,6 @@ tasks: cmds: - home-manager build --flake .#{{.TARGET}} - home:test:*: - vars: - TARGET: "{{index .MATCH 0}}" - cmds: - - home-manager test --flake .#{{.TARGET}} - home:switch:*: vars: TARGET: "{{index .MATCH 0}}"