use standard module system more over specialArgs #3

Merged
getchoo merged 2 commits from modules into main 2024-05-02 09:31:39 +00:00
10 changed files with 57 additions and 47 deletions

View file

@ -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. 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`. 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. 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. 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` 1. Run `nix flake new -t github:auxolotyl/templates#system NixFiles`
2. Move into your new system with `cd 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 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! Congratulations, you are now using Aux!

View file

@ -44,24 +44,28 @@
# the specialArgs are used to pass the inputs to the system configuration and home-manager configuration # the specialArgs are used to pass the inputs to the system configuration and home-manager configuration
specialArgs = { specialArgs = {
inherit inputs username hostname; inherit inputs;
}; };
in in
{ {
# it is important that you use darwin.lib.darwinSystem as this is the builder that allow # it is important that you use darwin.lib.darwinSystem as this is the builder that allow
# for the configuration of the darwin system # for the configuration of the darwin system
darwinConfigurations.${hostname} = darwin.lib.darwinSystem { darwinConfigurations.${hostname} = darwin.lib.darwinSystem {
inherit system;
# The specialArgs are used to pass the inputs to the system configuration # The specialArgs are used to pass the inputs to the system configuration
inherit specialArgs; inherit specialArgs;
modules = [ modules = [
./core.nix
./homebrew.nix ./homebrew.nix
./users.nix ./system.nix
# The home-manager module is used to configure home-manager # The home-manager module is used to configure home-manager
# to read more about this please see ../home-manager # to read more about this please see ../home-manager
home-manager.darwinModules.home-manager home-manager.darwinModules.home-manager
(
{ config, ... }:
{ {
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
@ -69,9 +73,23 @@
# extraSpecialArgs is used to pass the inputs to the home-manager configuration # extraSpecialArgs is used to pass the inputs to the home-manager configuration
home-manager.extraSpecialArgs = specialArgs; home-manager.extraSpecialArgs = specialArgs;
# Here we have assume that the use is called "axel" but you can change that to your needs # Here we can create our user
home-manager.users.${username} = import ./home.nix; 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;
} }
)
]; ];
}; };
}; };

View file

@ -1,11 +1,10 @@
{ username, ... }: { config, ... }:
{ {
# Home Manager needs a bit of information about you and the # Home Manager needs a bit of information about you and the
# paths it should manage. # paths it should manage.
home = { home = {
# remember we set this in our flake.nix file # remember we set this in our flake.nix file
username = username; homeDirectory = "/Users/${config.home.username}";
homeDirectory = "/Users/${username}";
# This value determines the Home Manager release that your # This value determines the Home Manager release that your
# configuration is compatible with. This helps avoid breakage # configuration is compatible with. This helps avoid breakage

View file

@ -1,3 +1,4 @@
{ config, ... }:
{ {
config = { config = {
environment = { environment = {

View file

@ -2,6 +2,9 @@
# see <https://daiderd.com/nix-darwin/manual/index.html#sec-options> for more options # see <https://daiderd.com/nix-darwin/manual/index.html#sec-options> for more options
{ {
system = { 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 # Add ability to used TouchID for sudo authentication
security.pam.enableSudoTouchIdAuth = true; security.pam.enableSudoTouchIdAuth = true;

View file

@ -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}";
}

View file

@ -16,7 +16,7 @@
}; };
outputs = outputs =
{ nixpkgs, home-manager, ... }: inputs@{ nixpkgs, home-manager, ... }:
let let
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
@ -28,13 +28,17 @@
# Specify your home configuration modules here, for example, # Specify your home configuration modules here, for example,
# the path to your home.nix. # 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 # Optionally use extraSpecialArgs
# to pass through arguments to home.nix # to pass through arguments to home.nix
extraSpecialArgs = {
inherit inputs;
};
}; };
}; };
} }

View file

@ -1,15 +1,9 @@
{ { config, pkgs, ... }:
config,
pkgs,
username,
...
}:
{ {
# Home Manager needs a bit of information about you and the paths it should # Home Manager needs a bit of information about you and the paths it should
# manage. # manage.
home = { home = {
inherit username; homeDirectory = "/home/${config.home.username}";
homeDirectory = "/home/${username}";
# This value determines the Home Manager release that your configuration is # This value determines the Home Manager release that your configuration is
# compatible with. This helps avoid breakage when a new Home Manager release # compatible with. This helps avoid breakage when a new Home Manager release

View file

@ -2,8 +2,6 @@
config, config,
lib, lib,
pkgs, pkgs,
username,
hostName,
... ...
}: }:
@ -17,7 +15,6 @@
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
networking.hostName = hostName; # Define your hostname.
# Pick only one of the below networking options. # Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
@ -59,7 +56,7 @@
# services.xserver.libinput.enable = true; # services.xserver.libinput.enable = true;
# Define a user account. Don't forget to set a password with passwd. # Define a user account. Don't forget to set a password with passwd.
users.users.${username} = { users.users.axol = {
isNormalUser = true; isNormalUser = true;
extraGroups = [ "wheel" ]; # Enable sudo for the user. extraGroups = [ "wheel" ]; # Enable sudo for the user.
packages = with pkgs; [ firefox ]; packages = with pkgs; [ firefox ];

View file

@ -4,17 +4,20 @@
inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable";
outputs = outputs =
{ nixpkgs, ... }: inputs@{ nixpkgs, ... }:
let let
system = "x86_64-linux"; 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 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 in
{ {
nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem { nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem {
inherit system; inherit system;
modules = [ ./configuration.nix ]; modules = [
./configuration.nix
{ networking.hostName = hostName; }
];
specialArgs = { specialArgs = {
inherit inputs; inherit inputs;
}; };