From 3f3ac4306bfc721f85615c7afc30d9fc0a8559ea Mon Sep 17 00:00:00 2001 From: Samuel Shuert Date: Wed, 1 May 2024 16:46:28 -0400 Subject: [PATCH] Initial work on creating sensible templates Available templates include the following: - system: flake based system similar to the default when starting nix. - darwin: flake based darwin system with ajusted nixpkgs and modules to better suit it. - home-manager: flake and home manager for non darwin systems. Co-Authored-by: isabelroses Co-Authored-by: Skyler Grey Co-Authored-by: Sigmanificient Co-Authored-by: AxelSilverdew <7677954+AxelSilverdew@users.noreply.github.com> --- .gitignore | 1 + darwin/core.nix | 24 ++++++ darwin/flake.nix | 79 +++++++++++++++++ darwin/home.nix | 23 +++++ darwin/homebrew.nix | 53 ++++++++++++ darwin/system.nix | 12 +++ darwin/users.nix | 9 ++ flake.lock | 27 ++++++ flake.nix | 36 ++++++++ home-manager/flake.nix | 40 +++++++++ home-manager/home.nix | 81 ++++++++++++++++++ system/configuration.nix | 138 ++++++++++++++++++++++++++++++ system/flake.nix | 23 +++++ system/hardware-configuration.nix | 1 + 14 files changed, 547 insertions(+) create mode 100644 .gitignore create mode 100644 darwin/core.nix create mode 100644 darwin/flake.nix create mode 100644 darwin/home.nix create mode 100644 darwin/homebrew.nix create mode 100644 darwin/system.nix create mode 100644 darwin/users.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 home-manager/flake.nix create mode 100644 home-manager/home.nix create mode 100644 system/configuration.nix create mode 100644 system/flake.nix create mode 100644 system/hardware-configuration.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b42106 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv/ diff --git a/darwin/core.nix b/darwin/core.nix new file mode 100644 index 0000000..1b8f7a0 --- /dev/null +++ b/darwin/core.nix @@ -0,0 +1,24 @@ +{ + # Auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + + nix.settings = { + # We need this to be able to use the nix-command and flakes features. + # these are essential to use this system configuration as a flake. + experimental-features = [ + "nix-command" + "flakes" + ]; + + # this allows the system builder to use substitutes + builders-use-substitutes = true; + + # we want these beacuse we don't have to build every package from source + substituters = [ "https://nix-community.cachix.org" ]; + trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ]; + + # We also want to add our user, in this case "axel" to the trusted users + # this is important so that we can use the substituters with no issues + trusted-users = [ "axel" ]; + }; +} diff --git a/darwin/flake.nix b/darwin/flake.nix new file mode 100644 index 0000000..291c1a1 --- /dev/null +++ b/darwin/flake.nix @@ -0,0 +1,79 @@ +{ + description = "A simple darwin flake using Aux and home-manager"; + + inputs = { + # nixpkgs is the input that we use for this flake the end section `nixpkgs-unstable` refers to the branch + # of nixpkgs that we want to use. This can be changed to any branch or commit hash. + nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable"; + + home-manager = { + url = "github:nix-community/home-manager"; + + # The `follows` keyword in inputs is used for inheritance. + # we do this in order to prevent duplication of the nixpkgs input, and potential + # issues with diffrent versions of given packages. + # However, it should be noted that this can lead to having to rebuild packages from source. + inputs.nixpkgs.follows = "nixpkgs"; + }; + + darwin = { + url = "github:lnl7/nix-darwin"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + inputs@{ + self, + nixpkgs, + darwin, + home-manager, + ... + }: + # we can use the `let` and `in` syntax to define variables + # and use them in the rest of the expression + let + # this can be either aarch64-darwin or x86_64-darwin + # if your using a M1 or later your going to need to use aarch64-darwin + # otherwise you can use x86_64-darwin + system = builtins.abort "You need to fill in your system"; + + # here we define our username and hostname to reuse them later + username = builtins.abort "You need to fill in your username"; # Set this variable equal to your username + hostname = builtins.abort "You need to fill in your hostname"; # Set this variable equal to your hostname + + # the specialArgs are used to pass the inputs to the system configuration and home-manager configuration + specialArgs = { + inherit inputs username hostname; + }; + in + { + # here the hostname is being set to "reservoir" but you can change that to your needs + # 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 { + + # The specialArgs are used to pass the inputs to the system configuration + inherit specialArgs; + + modules = [ + ./homebrew.nix + ./users.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; + + # 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; + } + ]; + }; + }; +} diff --git a/darwin/home.nix b/darwin/home.nix new file mode 100644 index 0000000..d623817 --- /dev/null +++ b/darwin/home.nix @@ -0,0 +1,23 @@ +{ username, ... }: +{ + # Home Manager needs a bit of information about you and the + # paths it should manage. + home = { + # rember we set this in our flake.nix file + username = username; + homeDirectory = "/Users/${username}"; + + # This value determines the Home Manager release that your + # configuration is compatible with. This helps avoid breakage + # when a new Home Manager release introduces backwards + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + stateVersion = "23.11"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/darwin/homebrew.nix b/darwin/homebrew.nix new file mode 100644 index 0000000..e083aff --- /dev/null +++ b/darwin/homebrew.nix @@ -0,0 +1,53 @@ +{ + config = { + environment = { + # You can configure your usual shell environment for homebrew here. + variables = { + HOMEBREW_NO_ANALYTICS = "1"; + HOMEBREW_NO_INSECURE_REDIRECT = "1"; + HOMEBREW_NO_EMOJI = "1"; + HOMEBREW_NO_ENV_HINTS = "0"; + }; + + # This is included so that the homebrew packages are available in the PATH. + systemPath = [ config.homebrew.brewPrefix ]; + }; + + # homebrew need to be installed manually, see https://brew.sh + # The apps installed by homebrew are not managed by nix, and not reproducible! + homebrew = { + enable = true; + caskArgs.require_sha = true; + + onActivation = { + autoUpdate = true; + upgrade = true; + # 'zap': uninstalls all formulae(and related files) not listed here. + cleanup = "zap"; + }; + + # Applications to install from Mac App Store using mas. + # You need to install all these Apps manually first so that your apple account have records for them. + # otherwise Apple Store will refuse to install them. + # For details, see https://github.com/mas-cli/mas + masApps = { }; + + taps = [ "homebrew/bundle" ]; + + # This is the equivalent of running `brew install` + brews = [ + "curl" + "openjdk" + ]; + + # This is the equivalent of running `brew install --cask` + casks = [ + "arc" # browser + "zed" # text editor + "raycast" # app launcher, and clipboard manager + "obsidian" # note taking + "inkscape" # vector graphics editor + ]; + }; + }; +} diff --git a/darwin/system.nix b/darwin/system.nix new file mode 100644 index 0000000..e0ca7e5 --- /dev/null +++ b/darwin/system.nix @@ -0,0 +1,12 @@ +# This section apply settings to the system configuration only available on macOS +# see for more options +{ + system = { + # Add ability to used TouchID for sudo authentication + security.pam.enableSudoTouchIdAuth = true; + + # Create /etc/zshrc that loads the nix-darwin environment. + # this is required if you want to use darwin's default shell - zsh + programs.zsh.enable = true; + }; +} diff --git a/darwin/users.nix b/darwin/users.nix new file mode 100644 index 0000000..f799f33 --- /dev/null +++ b/darwin/users.nix @@ -0,0 +1,9 @@ +{ 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/flake.lock b/flake.lock new file mode 100644 index 0000000..24cd7d8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "resevoir": { + "locked": { + "lastModified": 1714562304, + "narHash": "sha256-Mr3U37Rh6tH0FbaDFu0aZDwk9mPAe7ASaqDOGgLqqLU=", + "owner": "auxolotl", + "repo": "nixpkgs", + "rev": "bcd44e224fd68ce7d269b4f44d24c2220fd821e7", + "type": "github" + }, + "original": { + "owner": "auxolotl", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "resevoir": "resevoir" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7ad2a5c --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "Templates for getting started with Aux"; + + inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable"; + + outputs = + { self, nixpkgs }: + let + forAllSystems = + function: + nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ] (system: function system); + in + { + templates = { + default = self.templates.direnv; + system = { + path = ./system; + description = ""; + }; + home-manager = { + path = ./home-manager; + description = ""; + }; + darwin = { + path = ./darwin; + description = ""; + }; + }; + formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); + }; +} diff --git a/home-manager/flake.nix b/home-manager/flake.nix new file mode 100644 index 0000000..e1a87fe --- /dev/null +++ b/home-manager/flake.nix @@ -0,0 +1,40 @@ +{ + description = "A simple home-manager flake using Aux"; + + inputs = { + nixpkgs.url = "github:auxolotl/nixkpkgs/nixpkgs-unstable"; + + home-manager = { + url = "github:nix-community/home-manager"; + + # The `follows` keyword in inputs is used for inheritance. + # we do this in order to prevent duplication of the nixpkgs input, and potential + # issues with diffrent versions of given packages. + # However, it should be noted that this can lead to having to rebuild packages from source. + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { nixpkgs, home-manager, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + username = builtins.abort "You need to fill in your username"; # Set this variable equal to your username + in + { + homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + + # Specify your home configuration modules here, for example, + # the path to your home.nix. + modules = [ ./home.nix ]; + + extraSpecialArgs = { + inherit username pkgs; # We inherit pkgs + }; + # Optionally use extraSpecialArgs + # to pass through arguments to home.nix + }; + }; +} diff --git a/home-manager/home.nix b/home-manager/home.nix new file mode 100644 index 0000000..4ce9001 --- /dev/null +++ b/home-manager/home.nix @@ -0,0 +1,81 @@ +{ + config, + pkgs, + username, + ... +}: +{ + # Home Manager needs a bit of information about you and the paths it should + # manage. + home = { + inherit username; + homeDirectory = "/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 + # introduces backwards incompatible changes. + # + # You should not change this value, even if you update Home Manager. If you do + # want to update the value, then make sure to first check the Home Manager + # release notes. + stateVersion = "23.11"; # Please read the comment before changing. + + # The home.packages option allows you to install Nix packages into your + # environment. + packages = [ + # # Adds the 'hello' command to your environment. It prints a friendly + # # "Hello, world!" when run. + # pkgs.hello + + # # It is sometimes useful to fine-tune packages, for example, by applying + # # overrides. You can do that directly here, just don't forget the + # # parentheses. Maybe you want to install Nerd Fonts with a limited number of + # # fonts? + # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) + + # # You can also create simple shell scripts directly inside your + # # configuration. For example, this adds a command 'my-hello' to your + # # environment: + # (pkgs.writeShellScriptBin "my-hello" '' + # echo "Hello, ${config.home.username}!" + # '') + ]; + + # Home Manager is pretty good at managing dotfiles. The primary way to manage + # plain files is through 'home.file'. + file = { + # # Building this configuration will create a copy of 'dotfiles/screenrc' in + # # the Nix store. Activating the configuration will then make '~/.screenrc' a + # # symlink to the Nix store copy. + # ".screenrc".source = dotfiles/screenrc; + + # # You can also set the file content immediately. + # ".gradle/gradle.properties".text = '' + # org.gradle.console=verbose + # org.gradle.daemon.idletimeout=3600000 + # ''; + }; + + # Home Manager can also manage your environment variables through + # 'home.sessionVariables'. If you don't want to manage your shell through Home + # Manager then you have to manually source 'hm-session-vars.sh' located at + # either + # + # ~/.nix-profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # /etc/profiles/per-user/abhiram/etc/profile.d/hm-session-vars.sh + # + sessionVariables = { + # EDITOR = "emacs"; + }; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/system/configuration.nix b/system/configuration.nix new file mode 100644 index 0000000..80efdc0 --- /dev/null +++ b/system/configuration.nix @@ -0,0 +1,138 @@ +{ + config, + lib, + pkgs, + username, + hostName, + ... +}: + +{ + imports = [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + + # Use the systemd-boot EFI boot loader. + 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. + + # Set your time zone. + # time.timeZone = "Europe/Amsterdam"; + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Select internationalisation properties. + # i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # useXkbConfig = true; # use xkb.options in tty. + # }; + + # Enable the X11 windowing system. + # services.xserver.enable = true; + + # Configure keymap in X11 + # services.xserver.xkb.layout = "us"; + # services.xserver.xkb.options = "eurosign:e,caps:escape"; + + # Enable CUPS to print documents. + # services.printing.enable = true; + + # Enable sound. + # hardware.pulseaudio.enable = true; + # OR + # services.pipewire = { + # enable = true; + # pulse.enable = true; + # }; + + # Enable touchpad support (enabled default in most desktopManager). + # services.xserver.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.${username} = { + isNormalUser = true; + extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. + packages = with pkgs; [ firefox ]; + }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + # environment.systemPackages = with pkgs; [ + # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. + # wget + # ]; + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + # services.openssh.enable = true; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # networking.firewall.enable = false; + + # Copy the NixOS configuration file and link it from the resulting system + # (/run/current-system/configuration.nix). This is useful in case you + # accidentally delete configuration.nix. + # system.copySystemConfiguration = true; + + # This option allows you to use some features (flakes and the new Nix CLI) which have not yet been stabilized. + # Although they aren't yet stabilized, many Nix users use them and simple workflows are unlikely to break + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; + + nix.registry.nixpkgs = { + from = { + id = "nixpkgs"; + type = "indirect"; + }; + to = { + owner = "auxolotl"; + repo = "nixpkgs"; + type = "github"; + }; + }; + + nix.gc.automatic = true; + + # This option defines the first version of NixOS you have installed on this particular machine, + # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions. + # + # Most users should NEVER change this value after the initial install, for any reason, + # even if you've upgraded your system to a new NixOS release. + # + # This value does NOT affect the Nixpkgs version your packages and OS are pulled from, + # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how + # to actually do that. + # + # This value being lower than the current NixOS release does NOT mean your system is + # out of date, out of support, or vulnerable. + # + # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration, + # and migrated your data accordingly. + # + # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . + system.stateVersion = "24.05"; # Did you read the comment? +} diff --git a/system/flake.nix b/system/flake.nix new file mode 100644 index 0000000..60d0e63 --- /dev/null +++ b/system/flake.nix @@ -0,0 +1,23 @@ +{ + description = "A simple system flake using some Aux defaults"; + + inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixpkgs-unstable"; + + outputs = + { 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 ]; + specialArgs = { + inherit inputs; + }; + }; + }; +} diff --git a/system/hardware-configuration.nix b/system/hardware-configuration.nix new file mode 100644 index 0000000..f2cd324 --- /dev/null +++ b/system/hardware-configuration.nix @@ -0,0 +1 @@ +builtins.abort "Please run 'nixos-generate-config --show-hardware-config' and copy the output into hardware-configuration.nix"