Skip to content

Commit

Permalink
refactor: peel back mkSystem abstractions
Browse files Browse the repository at this point in the history
- Remove `lib/system.nix`
- Remove `lib/user.nix`
- Move system creation functions to `hosts/flake-module.nix`
- Greatly reduce abstractions, could still be reduced further

Also:
- Reduced module `specialArgs` to just `self` & `inputs`
- Manually import `hardware-configuration.nix` in `configuration.nix`
  • Loading branch information
MattSturgeon committed Apr 2, 2024
1 parent 029ec20 commit 4deb81b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 209 deletions.
96 changes: 72 additions & 24 deletions hosts/flake-module.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,83 @@
{ self, ... }:
{ self, inputs, lib, ... }:
let
inherit (self.lib) mkNixOSConfig mkHMConfig;
specialArgs = { inherit self inputs; };

# Define my user, used by most configurations
# see initUser in lib/user.nix
userMatt = {
name = "matt";
description = "Matt Sturgeon";
initialPassword = "init";
isAdmin = true;
};
guessUsername = name:
let
parts = lib.splitString "@" name;
len = builtins.length parts;
in
if len == 2 then builtins.head parts else name;

guessHostname = name:
let
parts = lib.splitString "@" name;
len = builtins.length parts;
in
lib.optionalString (len == 2) (builtins.elemAt parts 1);

mkSystem = name:
{ system
, username ? "matt"
, fullname ? "Matt Sturgeon"
, modules ? [ ]
, ...
}: inputs.nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules = modules ++ [
./${name}/configuration.nix
self.nixosModules.common
self.nixosModules.nixos
inputs.home-manager.nixosModules.home-manager
{
users.users.${username} = {
description = fullname;
extraGroups = [ "wheel" "networkmanager" ];
initialPassword = "init";
isNormalUser = true;
};
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = specialArgs;
sharedModules = [ self.homeModules.home ];
users.${username} = ./${name}/home.nix;
};
}
];
};

mkHome = name:
{ system
, username ? guessUsername name
, hostname ? guessHostname name
, modules ? [ ]
, ...
}: inputs.home-manager.lib.homeManagerConfiguration {
extraSpecialArgs = specialArgs;
pkgs = inputs.nixpkgs.legacyPackages.${system};
modules = modules ++ [
# FIXME doesn't support username-specific configs
./${hostname}/home.nix
self.homeModules.common
self.homeModules.home
{
home.username = username;
home.homeDirectory = "/home/${username}";
}
];
};
in
{
flake = {
# NixOS configurations
nixosConfigurations = {
matebook = mkNixOSConfig {
hostname = "matebook";
hmUsers = [ userMatt ];
nixosModules = with self.nixosModules; [ common nixos ];
homeManagerModules = [ self.homeModules.home ];
};
nixosConfigurations = builtins.mapAttrs mkSystem {
matebook = { system = "x86_64-linux"; };
};

# Standalone home-manager configuration entrypoint
homeConfigurations = {
"matt@desktop" = mkHMConfig {
hostname = "desktop";
user = userMatt;
modules = with self.homeModules; [ common home ];
};
# Standalone home-manager configurations
homeConfigurations = builtins.mapAttrs mkHome {
"matt@desktop" = { system = "x86_64-linux"; };
};
};
}
5 changes: 3 additions & 2 deletions hosts/matebook/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{ hardware
{ inputs
, ...
}: {
custom = {
boot.splash = true;
desktop.gnome = true;
};

imports = with hardware.nixosModules; [
imports = with inputs.hardware.nixosModules; [
# Hardware
# intelBusId = "PCI:0:2:0"; nvidiaBusId = "PCI:1:0:0";
common-cpu-intel
common-cpu-intel-kaby-lake
common-gpu-nvidia-disable # Disable MX150 for better battery
common-pc-laptop-ssd
common-hidpi
./hardware-configuration.nix
];

# https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion
Expand Down
77 changes: 0 additions & 77 deletions lib/system.nix

This file was deleted.

97 changes: 0 additions & 97 deletions lib/user.nix

This file was deleted.

4 changes: 2 additions & 2 deletions modules/home-manager/firefox.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ config
, lib
, util
, pkgs
, self
, inputs
, ...
}:
let
inherit (lib) types mkIf mkOption;
inherit (util.modules) mkFirst;
inherit (self.lib.modules) mkFirst;
cfg = config.custom.browsers.firefox;
otherHost = config.custom.otherHost.enable;

Expand Down
4 changes: 2 additions & 2 deletions modules/home-manager/neovim.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{ config
, lib
, pkgs
, nixvim
, inputs
, ...
}:
let
inherit (lib) types mkOption mkIf;
cfg = config.custom.editors;
in
{
imports = [ nixvim.homeManagerModules.nixvim ];
imports = [ inputs.nixvim.homeManagerModules.nixvim ];

options.custom.editors.nvim = mkOption {
type = types.bool;
Expand Down
4 changes: 2 additions & 2 deletions modules/home-manager/other-hosts.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config
, lib
, pkgs
, nixgl
, inputs
, ...
}:
let
Expand Down Expand Up @@ -86,6 +86,6 @@ in
else [ ];

# Overlay configured packages with wrapped versions
nixpkgs.overlays = with cfg; [ nixgl.overlay ] ++ (mkOverlays glWrapper glPackages) ++ (mkOverlays vkWrapper vkPackages);
nixpkgs.overlays = with cfg; [ inputs.nixgl.overlay ] ++ (mkOverlays glWrapper glPackages) ++ (mkOverlays vkWrapper vkPackages);
};
}
6 changes: 3 additions & 3 deletions modules/home-manager/tmux.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config
, lib
, pkgs
, tmux-which-key
, inputs
, ...
}:
let
Expand All @@ -25,8 +25,8 @@ let
extraPlugins = map mkPlugin [
{
pluginName = "tmux-which-key";
version = tmux-which-key.shortRev;
src = tmux-which-key;
version = inputs.tmux-which-key.shortRev;
src = inputs.tmux-which-key;
rtpFilePath = "plugin.sh.tmux";
extraConfig = ''
# Use XDG config file for which-key plugin
Expand Down

0 comments on commit 4deb81b

Please sign in to comment.