diff --git a/README.md b/README.md index 09109f3..2eb5721 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,16 @@ nix run - X1 Carbon: https://www.srid.ca/x1c7-install - Windows (via WSL): https://github.com/nix-community/NixOS-WSL - Clone this repo at `/etc/nixos` - - Edit `flake.nix` and add your Linux's hostname in the `nixosConfigurations` set, as well as update `userName`. + - Edit `flake.nix` and + - add your Linux's hostname in the `nixosConfigurations` set, as well as + - update `myUserName`. - Run `nix run`. That's it. Re-open your shell. - macOS: - Install Nix normally (multi-user) - Install [nix-darwin](https://github.com/LnL7/nix-darwin) - This will create a `~/.nixpkgs/darwin-configuration.nix`, but we do not need that. - Clone this repo anywhere - - Edit `flake.nix` to update `userName`. + - Edit `flake.nix` to update `myUserName`. - Run `nix run`.[^cleanup] That's it. Re-open your shell. [^cleanup]: You might have to `rm -rf /etc/nix/nix.conf`, so our flake.nix can do its thing. diff --git a/config.nix b/config.nix new file mode 100644 index 0000000..ce9c0c9 --- /dev/null +++ b/config.nix @@ -0,0 +1,9 @@ +{ config, lib, ... }: +{ + options = { + myUserName = lib.mkOption { + type = lib.types.str; + description = "The canonical (only) user to add to all systems."; + }; + }; +} diff --git a/flake.nix b/flake.nix index 4bf7dc1..67ecc2f 100644 --- a/flake.nix +++ b/flake.nix @@ -33,6 +33,7 @@ inputs.flake-parts.lib.mkFlake { inherit (inputs) self; } { systems = [ "x86_64-linux" "aarch64-darwin" ]; imports = [ + ./config.nix ./home ./nixos ./nix-darwin @@ -44,39 +45,36 @@ }; formatter = pkgs.nixpkgs-fmt; }; - flake = - let - userName = "srid"; - in - { - # Configurations for Linux (NixOS) systems - nixosConfigurations = { - # My Linux development computer (on Hetzner) - pinch = self.lib.mkLinuxSystem userName - [ - ./systems/hetzner/ax41.nix - ./nixos/server/harden.nix + myUserName = "srid"; + flake = { + # Configurations for Linux (NixOS) systems + nixosConfigurations = { + # My Linux development computer (on Hetzner) + pinch = self.lib.mkLinuxSystem + [ + ./systems/hetzner/ax41.nix + ./nixos/server/harden.nix - # Temporarily sharing with Uday. - { - users.users.uday.isNormalUser = true; - home-manager.users."uday" = { - imports = [ - self.homeModules.common-linux - (import ./home/git.nix { - userName = "Uday Kiran"; - userEmail = "udaycruise2903@gmail.com"; - }) - ]; - }; - } - ]; - }; - - # Configurations for macOS systems (using nix-darwin) - darwinConfigurations = { - default = self.lib-darwin.mkMacosSystem userName; - }; + # Temporarily sharing with Uday. + { + users.users.uday.isNormalUser = true; + home-manager.users."uday" = { + imports = [ + self.homeModules.common-linux + (import ./home/git.nix { + userName = "Uday Kiran"; + userEmail = "udaycruise2903@gmail.com"; + }) + ]; + }; + } + ]; }; + + # Configurations for macOS systems (using nix-darwin) + darwinConfigurations = { + default = self.lib-darwin.mkMacosSystem; + }; + }; }; } diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 6b7134b..1247c64 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -1,4 +1,4 @@ -{ self, inputs, ... }: +{ self, inputs, config, ... }: { # Configuration common to all macOS systems flake = { @@ -20,7 +20,7 @@ self.darwinModules.home ]; }; - lib-darwin.mkMacosSystem = userName: inputs.darwin.lib.darwinSystem rec { + lib-darwin.mkMacosSystem = inputs.darwin.lib.darwinSystem rec { system = "aarch64-darwin"; specialArgs = { inherit inputs system; @@ -30,7 +30,7 @@ self.darwinModules.default ../systems/darwin.nix { - home-manager.users.${userName} = { pkgs, ... }: { + home-manager.users.${config.myUserName} = { pkgs, ... }: { imports = [ self.homeModules.common-darwin ../home/shellcommon.nix diff --git a/nixos/default.nix b/nixos/default.nix index e045d34..8e13fcc 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,4 +1,4 @@ -{ self, inputs, ... }: +{ self, inputs, config, ... }: { # Configuration common to all Linux systems flake = { @@ -28,14 +28,14 @@ ]; }; - lib.mkLinuxSystem = userName: extraModules: inputs.nixpkgs.lib.nixosSystem rec { + lib.mkLinuxSystem = extraModules: inputs.nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; modules = [ self.nixosModules.default { - home-manager.users.${userName} = { pkgs, ... }: { + home-manager.users.${config.myUserName} = { pkgs, ... }: { imports = [ self.homeModules.common-linux ../home/shellcommon.nix