From f29555309533912ac4032f84e03233bfa634fde0 Mon Sep 17 00:00:00 2001 From: seth Date: Wed, 1 May 2024 18:00:23 -0400 Subject: [PATCH 1/2] use standard module system over specialArgs --- darwin/flake.nix | 38 ++++++++++++++++++++++++++++---------- darwin/home.nix | 5 ++--- darwin/homebrew.nix | 1 + darwin/system.nix | 3 +++ darwin/users.nix | 9 --------- home-manager/flake.nix | 14 +++++++++----- home-manager/home.nix | 10 ++-------- system/configuration.nix | 5 +---- system/flake.nix | 11 +++++++---- 9 files changed, 53 insertions(+), 43 deletions(-) delete mode 100644 darwin/users.nix diff --git a/darwin/flake.nix b/darwin/flake.nix index 5e9fdca..8183734 100644 --- a/darwin/flake.nix +++ b/darwin/flake.nix @@ -44,34 +44,52 @@ # the specialArgs are used to pass the inputs to the system configuration and home-manager configuration specialArgs = { - inherit inputs username hostname; + inherit inputs; }; in { # it is important that you use darwin.lib.darwinSystem as this is the builder that allow # for the configuration of the darwin system darwinConfigurations.${hostname} = darwin.lib.darwinSystem { + inherit system; # The specialArgs are used to pass the inputs to the system configuration inherit specialArgs; modules = [ + ./core.nix ./homebrew.nix - ./users.nix + ./system.nix # The home-manager module is used to configure home-manager # to read more about this please see ../home-manager home-manager.darwinModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + ( + { config, ... }: + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; - # extraSpecialArgs is used to pass the inputs to the home-manager configuration - home-manager.extraSpecialArgs = specialArgs; + # extraSpecialArgs is used to pass the inputs to the home-manager configuration + home-manager.extraSpecialArgs = specialArgs; - # Here we have assume that the use is called "axel" but you can change that to your needs - home-manager.users.${username} = import ./home.nix; - } + # Here we can create our user + uses.users.${username} = { + home = "/Users/${username}"; + }; + + # And a home-manager configuration for them + home-manager.users.${username} = { + imports = [ ./home.nix ]; + + home.username = username; + }; + + # Here we set our (networking) host name and computer name. They should usually be the same + networking.hostName = hostname; + networking.computerName = config.networking.hostName; + } + ) ]; }; }; diff --git a/darwin/home.nix b/darwin/home.nix index ea34399..cff401f 100644 --- a/darwin/home.nix +++ b/darwin/home.nix @@ -1,11 +1,10 @@ -{ username, ... }: +{ config, ... }: { # Home Manager needs a bit of information about you and the # paths it should manage. home = { # remember we set this in our flake.nix file - username = username; - homeDirectory = "/Users/${username}"; + homeDirectory = "/Users/${config.home.username}"; # This value determines the Home Manager release that your # configuration is compatible with. This helps avoid breakage diff --git a/darwin/homebrew.nix b/darwin/homebrew.nix index e083aff..d812a70 100644 --- a/darwin/homebrew.nix +++ b/darwin/homebrew.nix @@ -1,3 +1,4 @@ +{ config, ... }: { config = { environment = { diff --git a/darwin/system.nix b/darwin/system.nix index e0ca7e5..ab8e793 100644 --- a/darwin/system.nix +++ b/darwin/system.nix @@ -2,6 +2,9 @@ # see for more options { system = { + # remember to set the hostname in the kernel command line + defaults.smb.NetBIOSName = config.networking.hostName; + # Add ability to used TouchID for sudo authentication security.pam.enableSudoTouchIdAuth = true; diff --git a/darwin/users.nix b/darwin/users.nix deleted file mode 100644 index f799f33..0000000 --- a/darwin/users.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ username, hostname, ... }: -{ - # remember to set the hostname in the kernel command line - networking.hostName = hostname; - networking.computerName = hostname; - system.defaults.smb.NetBIOSName = hostname; - - users.users."${username}".home = "/Users/${username}"; -} diff --git a/home-manager/flake.nix b/home-manager/flake.nix index e5504f3..f43f834 100644 --- a/home-manager/flake.nix +++ b/home-manager/flake.nix @@ -16,7 +16,7 @@ }; outputs = - { nixpkgs, home-manager, ... }: + inputs@{ nixpkgs, home-manager, ... }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; @@ -28,13 +28,17 @@ # Specify your home configuration modules here, for example, # the path to your home.nix. - modules = [ ./home.nix ]; + modules = [ + ./home.nix + + { home.username = username; } + ]; - extraSpecialArgs = { - inherit username pkgs; # We inherit pkgs - }; # Optionally use extraSpecialArgs # to pass through arguments to home.nix + extraSpecialArgs = { + inherit inputs; + }; }; }; } diff --git a/home-manager/home.nix b/home-manager/home.nix index 4ce9001..336a5af 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -1,15 +1,9 @@ -{ - config, - pkgs, - username, - ... -}: +{ config, pkgs, ... }: { # Home Manager needs a bit of information about you and the paths it should # manage. home = { - inherit username; - homeDirectory = "/home/${username}"; + homeDirectory = "/home/${config.home.username}"; # This value determines the Home Manager release that your configuration is # compatible with. This helps avoid breakage when a new Home Manager release diff --git a/system/configuration.nix b/system/configuration.nix index 80efdc0..66de527 100644 --- a/system/configuration.nix +++ b/system/configuration.nix @@ -2,8 +2,6 @@ config, lib, pkgs, - username, - hostName, ... }: @@ -17,7 +15,6 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - networking.hostName = hostName; # Define your hostname. # Pick only one of the below networking options. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. @@ -59,7 +56,7 @@ # services.xserver.libinput.enable = true; # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.${username} = { + users.users.axol = { isNormalUser = true; extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. packages = with pkgs; [ firefox ]; diff --git a/system/flake.nix b/system/flake.nix index 60d0e63..652b121 100644 --- a/system/flake.nix +++ b/system/flake.nix @@ -4,17 +4,20 @@ inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable"; outputs = - { nixpkgs, ... }: + inputs@{ nixpkgs, ... }: let system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; hostName = builtins.abort "You need to fill in your hostName"; # Set this variable equal to your hostName - username = builtins.abort "You need to fill in your username"; # Set this variable equal to your username in { nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem { inherit system; - modules = [ ./configuration.nix ]; + modules = [ + ./configuration.nix + + { networking.hostName = hostName; } + ]; + specialArgs = { inherit inputs; }; From 7634bd468922c7533f39ebd954586a26cf8f775b Mon Sep 17 00:00:00 2001 From: seth Date: Wed, 1 May 2024 23:06:30 -0400 Subject: [PATCH 2/2] docs: update template instructions --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a352a86..bfa48dd 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,16 @@ There are 3 main templates in this repository: 1. Run `nix flake new -t github:auxolotl/templates#darwin NixFiles` in the terminal. This will setup the basic configuration for the system, this generate a configuration for you from the files located in the `darwin` directory. 2. The next step is to go into the `NixFiles` directory this can be achieved by running `cd NixFiles`. 3. Now we you need to read over the configuration files and make any changes that you see fit, some of these must include changing your username and hostname. -4. You now must rebuild this configuration we can do this with `nix run darwin-rebuild -- switch --flake .#hostname` hostname should be subsituted for your systems hostname. +4. You now must rebuild this configuration we can do this with `nix run darwin -- switch --flake .#hostname` hostname should be substituted for your systems hostname. 5. After your first run you are now able to use the `darwin-rebuild switch --flake .` command to rebuild your system. -#### With Linux +#### With NixOS 1. Run `nix flake new -t github:auxolotyl/templates#system NixFiles` 2. Move into your new system with `cd NixFiles` -3. Fill in your `hostName` and `username` in `flake.nix` +3. Fill in your `hostName` in `flake.nix` 4. Run `nixos-generate-config --show-hardware-config > hardware-configuration.nix` to generate configuration based on your filesystems and drivers -5. Run `sudo nixos-rebuild build --flake .#hostName`, replacing hostName with your new hostName +5. Run `nixos-rebuild build --flake .#hostName`, replacing hostName with your new hostName Congratulations, you are now using Aux!