From 70c2dc4e2fcf44b3b8c872dfbabf67efdaa0dba8 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Fri, 15 Dec 2023 23:13:25 -0500 Subject: [PATCH] Pass hostname and username to modules --- flake.nix | 10 ++++++---- modules/common/darwin/all-hosts.nix | 8 ++++---- modules/common/nixos/all-hosts.nix | 7 +++++-- modules/hosts/nixos/rainbow-planet/default.nix | 10 ++-------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 4484ea1..a45f4c0 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,7 @@ inputs = { inherit disko home-manager nixpkgs nixpkgs-unstable nix-darwin; }; # creates a macOS system config - darwinSystem = system: hostName: username: nix-darwin.lib.darwinSystem { + darwinSystem = system: hostname: username: nix-darwin.lib.darwinSystem { pkgs = import nixpkgs { inherit system; config = { @@ -48,6 +48,7 @@ ]; }; }; + specialArgs = { inherit inputs username hostname; }; modules = [ nix-homebrew.darwinModules.nix-homebrew { @@ -77,12 +78,12 @@ } ./modules/common/darwin/all-hosts.nix - ./modules/hosts/darwin/${hostName} # ip address, host specific stuff + ./modules/hosts/darwin/${hostname} # ip address, host specific stuff ]; # end modules }; # end darwinSystem # creates a nixos system config - nixosSystem = system: hostName: username: nixpkgs.lib.nixosSystem { + nixosSystem = system: hostname: username: nixpkgs.lib.nixosSystem { pkgs = import nixpkgs { inherit system; config = { @@ -92,6 +93,7 @@ ]; }; }; + specialArgs = { inherit inputs username hostname; }; modules = [ home-manager.nixosModules.home-manager { @@ -107,7 +109,7 @@ } ./modules/common/nixos/all-hosts.nix - ./modules/hosts/nixos/${hostName} # ip address, host specific stuff + ./modules/hosts/nixos/${hostname} # ip address, host specific stuff ]; }; # end nixosSystem diff --git a/modules/common/darwin/all-hosts.nix b/modules/common/darwin/all-hosts.nix index ba590c0..e73bb48 100644 --- a/modules/common/darwin/all-hosts.nix +++ b/modules/common/darwin/all-hosts.nix @@ -1,6 +1,4 @@ -{ pkgs, ... }: let - username = "gene.liverman"; -in { +{ pkgs, hostname, username, ... }: { environment = { shells = with pkgs; [ bash zsh ]; loginShell = pkgs.zsh; @@ -68,6 +66,8 @@ in { }; }; + networking.hostName = "${hostname}"; + nix = { settings = { bash-prompt-prefix = "(nix:$name)\040"; @@ -93,4 +93,4 @@ in { home = "/Users/${username}"; shell = pkgs.zsh; }; -} \ No newline at end of file +} diff --git a/modules/common/nixos/all-hosts.nix b/modules/common/nixos/all-hosts.nix index e55df47..8bdc9b8 100644 --- a/modules/common/nixos/all-hosts.nix +++ b/modules/common/nixos/all-hosts.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: { +{ config, pkgs, hostname, username, ... }: { imports = [ ./internationalisation.nix ]; @@ -26,7 +26,10 @@ }) ]; + networking.hostName = "${hostname}"; + nix.settings = { + allowed-users = [ "${username}" ]; experimental-features = [ "flakes" "nix-command" @@ -46,4 +49,4 @@ time.timeZone = "America/New_York"; users.defaultUserShell = pkgs.zsh; -} \ No newline at end of file +} diff --git a/modules/hosts/nixos/rainbow-planet/default.nix b/modules/hosts/nixos/rainbow-planet/default.nix index 6cc946c..962f669 100644 --- a/modules/hosts/nixos/rainbow-planet/default.nix +++ b/modules/hosts/nixos/rainbow-planet/default.nix @@ -1,7 +1,4 @@ -{ config, pkgs, ... }: let - username = "gene"; - hostname = "rainbow-planet"; -in { +{ config, pkgs, username, ... }: { imports = [ ./hardware-configuration.nix ]; @@ -39,12 +36,9 @@ in { ]; networking = { - hostName = "${hostname}"; networkmanager.enable = true; }; - nix.settings.allowed-users = [ "${username}" ]; - programs = { _1password.enable = true; _1password-gui = { @@ -104,7 +98,7 @@ in { description = "Gene Liverman"; extraGroups = [ "networkmanager" "wheel" "dialout" "input" ]; packages = with pkgs; [ - tailscale-systray + tailscale-systray ]; }; }