From 26e4112aa30f7a3ce86f8c4182634fffd80f7297 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:24:13 -0500 Subject: [PATCH 01/36] Use nixosModules and darwinModules --- flake.nix | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 05de5fc..ad56c6c 100644 --- a/flake.nix +++ b/flake.nix @@ -70,9 +70,6 @@ flake = let userName = "srid"; - platformIndependentModules = [ - ./nixos/caches - ]; platformIndependentHomeModules = [ ./home/tmux.nix ./home/neovim.nix @@ -83,17 +80,26 @@ ]; in { + # Configuration common to all Linux systems + nixosModules.default = { + imports = [ + ./nixos/caches + ./nixos/self-ide.nix + ./nixos/takemessh + ./nixos/current-location.nix + ]; + }; + # Configuration common to macOS Linux systems + darwinModules.default = { + imports = [ + ./nixos/caches + ]; + }; # Configurations for Linux (NixOS) systems nixosConfigurations = let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; - # Configuration common to all Linux systems - commonFeatures = platformIndependentModules ++ [ - ./nixos/self-ide.nix - ./nixos/takemessh - ./nixos/current-location.nix - ]; homeFeatures = [ home-manager.nixosModules.home-manager { @@ -108,7 +114,6 @@ }) ./home/vscode-server.nix ]; - programs.bash = { enable = true; } // (import ./home/shellcommon.nix { inherit pkgs; }); @@ -131,7 +136,7 @@ # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; modules = - commonFeatures ++ homeFeatures ++ extraModules; + [ self.nixosModules.default ] ++ homeFeatures ++ extraModules; }; in { @@ -154,7 +159,8 @@ inherit inputs system; rosettaPkgs = import nixpkgs { system = "x86_64-darwin"; }; }; - modules = platformIndependentModules ++ [ + modules = [ + self.darwinModules.default ./systems/darwin.nix home-manager.darwinModules.home-manager { From df017df0e87dc25e32b1773abeb2b7645821121d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:29:46 -0500 Subject: [PATCH 02/36] rename for clarity --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index ad56c6c..123c517 100644 --- a/flake.nix +++ b/flake.nix @@ -100,7 +100,7 @@ let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; - homeFeatures = [ + homeModules = [ home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; @@ -136,7 +136,7 @@ # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; modules = - [ self.nixosModules.default ] ++ homeFeatures ++ extraModules; + [ self.nixosModules.default ] ++ homeModules ++ extraModules; }; in { From 79265cb479d81d4386d1e89241362c0e3b191e44 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:33:36 -0500 Subject: [PATCH 03/36] put extra user config in its own module resolves #25 --- flake.nix | 25 +++++++++++++++---------- systems/hetzner/ax41.nix | 3 --- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 123c517..a0599bd 100644 --- a/flake.nix +++ b/flake.nix @@ -119,16 +119,6 @@ } // (import ./home/shellcommon.nix { inherit pkgs; }); home.stateVersion = "22.11"; }; - home-manager.users."uday" = { - imports = platformIndependentHomeModules ++ [ - (import ./home/git.nix { - userName = "Uday Kiran"; - userEmail = "udaycruise2903@gmail.com"; - }) - ]; - programs.bash.enable = true; - home.stateVersion = "22.11"; - }; } ]; mkLinuxSystem = extraModules: nixpkgs.lib.nixosSystem { @@ -145,6 +135,21 @@ [ ./systems/hetzner/ax41.nix ./nixos/server/harden.nix + + # Temporarily sharing with Uday. + { + users.users.uday.isNormalUser = true; + home-manager.users."uday" = { + imports = platformIndependentHomeModules ++ [ + (import ./home/git.nix { + userName = "Uday Kiran"; + userEmail = "udaycruise2903@gmail.com"; + }) + ]; + programs.bash.enable = true; + home.stateVersion = "22.11"; + }; + } ]; }; diff --git a/systems/hetzner/ax41.nix b/systems/hetzner/ax41.nix index ba6815b..baf199a 100644 --- a/systems/hetzner/ax41.nix +++ b/systems/hetzner/ax41.nix @@ -118,9 +118,6 @@ isNormalUser = true; extraGroups = [ "wheel" "networkmanager" ]; }; - users.users.uday = { - isNormalUser = true; - }; security.sudo.wheelNeedsPassword = false; system.stateVersion = "20.03"; From a568f38cba900aaf0986bd0bbcdf827b46010b35 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:36:39 -0500 Subject: [PATCH 04/36] reuse common module --- flake.nix | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index a0599bd..4b63407 100644 --- a/flake.nix +++ b/flake.nix @@ -81,19 +81,26 @@ in { # Configuration common to all Linux systems - nixosModules.default = { - imports = [ - ./nixos/caches - ./nixos/self-ide.nix - ./nixos/takemessh - ./nixos/current-location.nix + nixosModules = { + common = { + imports = [ + ./nixos/caches + ]; + }; + default = inputs.nixpkgs.lib.mkMerge [ + self.nixosModules.common + ({ + imports = [ + ./nixos/self-ide.nix + ./nixos/takemessh + ./nixos/current-location.nix + ]; + }) ]; }; # Configuration common to macOS Linux systems - darwinModules.default = { - imports = [ - ./nixos/caches - ]; + darwinModules = { + default = self.nixosModules.common; }; # Configurations for Linux (NixOS) systems nixosConfigurations = From ef17d1b04e7b49cf2f80f8b93d28bf689ab29adf Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:47:37 -0500 Subject: [PATCH 05/36] factor out common hm config --- flake.nix | 57 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 4b63407..0f4c0e1 100644 --- a/flake.nix +++ b/flake.nix @@ -82,25 +82,46 @@ { # Configuration common to all Linux systems nixosModules = { - common = { - imports = [ - ./nixos/caches - ]; - }; - default = inputs.nixpkgs.lib.mkMerge [ - self.nixosModules.common + common.imports = [ + ./nixos/caches + ]; + home.imports = [ + home-manager.nixosModules.home-manager ({ - imports = [ - ./nixos/self-ide.nix - ./nixos/takemessh - ./nixos/current-location.nix - ]; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "x86_64-linux"; + }; }) ]; + default.imports = + self.nixosModules.common.imports ++ + self.nixosModules.home.imports ++ + [ + ./nixos/self-ide.nix + ./nixos/takemessh + ./nixos/current-location.nix + ]; }; - # Configuration common to macOS Linux systems + # Configuration common to all macOS systems darwinModules = { - default = self.nixosModules.common; + common = self.nixosConfig.common; + home.imports = [ + home-manager.darwinModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "aarch64-darwin"; + }; + }) + ]; + default.imports = + self.darwinModules.common ++ + self.darwinModules.home.imports; }; # Configurations for Linux (NixOS) systems nixosConfigurations = @@ -108,11 +129,7 @@ system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; homeModules = [ - home-manager.nixosModules.home-manager { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit system inputs; }; home-manager.users.${userName} = { pkgs, ... }: { imports = platformIndependentHomeModules ++ [ (import ./home/git.nix { @@ -174,11 +191,7 @@ modules = [ self.darwinModules.default ./systems/darwin.nix - home-manager.darwinModules.home-manager { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { inherit system inputs; }; home-manager.users.${userName} = { pkgs, ... }: { imports = platformIndependentHomeModules ++ [ (import ./home/git.nix { From baa4ab9c0cc8cec4105901a6328bcb7b97660980 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:49:06 -0500 Subject: [PATCH 06/36] remove redundant arg --- flake.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 0f4c0e1..0ffa40a 100644 --- a/flake.nix +++ b/flake.nix @@ -127,7 +127,6 @@ nixosConfigurations = let system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; homeModules = [ { home-manager.users.${userName} = { pkgs, ... }: { @@ -146,7 +145,7 @@ } ]; mkLinuxSystem = extraModules: nixpkgs.lib.nixosSystem { - inherit system pkgs; + inherit system; # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; modules = From 1f91866e6ce5b26eb4bbffe4e5a83880a2735b04 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 12:55:45 -0500 Subject: [PATCH 07/36] refactor --- flake.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 0ffa40a..54cc180 100644 --- a/flake.nix +++ b/flake.nix @@ -126,7 +126,6 @@ # Configurations for Linux (NixOS) systems nixosConfigurations = let - system = "x86_64-linux"; homeModules = [ { home-manager.users.${userName} = { pkgs, ... }: { @@ -144,8 +143,8 @@ }; } ]; - mkLinuxSystem = extraModules: nixpkgs.lib.nixosSystem { - inherit system; + mkLinuxSystem = extraModules: nixpkgs.lib.nixosSystem rec { + system = "x86_64-linux"; # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; modules = @@ -179,10 +178,9 @@ # Configurations for macOS systems (using nix-darwin) darwinConfigurations = let - system = "aarch64-darwin"; mkMacosSystem = darwin.lib.darwinSystem; - defaultMacosSystem = mkMacosSystem { - inherit system; + defaultMacosSystem = mkMacosSystem rec { + system = "aarch64-darwin"; specialArgs = { inherit inputs system; rosettaPkgs = import nixpkgs { system = "x86_64-darwin"; }; From be87dcc40f08fb1bb300e3a75e032b2c70d1d86a Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:02:09 -0500 Subject: [PATCH 08/36] introduce flake.homeModules --- flake.nix | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 54cc180..bb4686f 100644 --- a/flake.nix +++ b/flake.nix @@ -70,14 +70,6 @@ flake = let userName = "srid"; - platformIndependentHomeModules = [ - ./home/tmux.nix - ./home/neovim.nix - ./home/emacs.nix - ./home/starship.nix - ./home/terminal.nix - ./home/direnv.nix - ]; in { # Configuration common to all Linux systems @@ -123,13 +115,27 @@ self.darwinModules.common ++ self.darwinModules.home.imports; }; + homeModules = { + common = { + home.stateVersion = "22.11"; + imports = [ + ./home/tmux.nix + ./home/neovim.nix + ./home/emacs.nix + ./home/starship.nix + ./home/terminal.nix + ./home/direnv.nix + ]; + }; + }; # Configurations for Linux (NixOS) systems nixosConfigurations = let homeModules = [ { home-manager.users.${userName} = { pkgs, ... }: { - imports = platformIndependentHomeModules ++ [ + imports = [ + self.homeModules.common (import ./home/git.nix { userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; @@ -139,7 +145,6 @@ programs.bash = { enable = true; } // (import ./home/shellcommon.nix { inherit pkgs; }); - home.stateVersion = "22.11"; }; } ]; @@ -162,14 +167,14 @@ { users.users.uday.isNormalUser = true; home-manager.users."uday" = { - imports = platformIndependentHomeModules ++ [ + imports = [ + self.homeModules.common (import ./home/git.nix { userName = "Uday Kiran"; userEmail = "udaycruise2903@gmail.com"; }) ]; programs.bash.enable = true; - home.stateVersion = "22.11"; }; } ]; @@ -190,7 +195,8 @@ ./systems/darwin.nix { home-manager.users.${userName} = { pkgs, ... }: { - imports = platformIndependentHomeModules ++ [ + imports = [ + self.homeModules.common (import ./home/git.nix { userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; From 4f04e12ba475ea3c09d73aeaf7467239a170ad55 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:05:37 -0500 Subject: [PATCH 09/36] make shellcommon a regular module --- flake.nix | 8 ++++---- home/shellcommon.nix | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index bb4686f..1e98192 100644 --- a/flake.nix +++ b/flake.nix @@ -140,11 +140,10 @@ userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; }) + ./home/shellcommon.nix ./home/vscode-server.nix ]; - programs.bash = { - enable = true; - } // (import ./home/shellcommon.nix { inherit pkgs; }); + programs.bash.enable = true; }; } ]; @@ -201,13 +200,14 @@ userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; }) + ./home/shellcommon.nix ]; programs.zsh = { enable = true; initExtra = '' export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH ''; - } // (import ./home/shellcommon.nix { inherit pkgs; }); + }; home.stateVersion = "21.11"; }; } diff --git a/home/shellcommon.nix b/home/shellcommon.nix index 86ad2cb..54b451a 100644 --- a/home/shellcommon.nix +++ b/home/shellcommon.nix @@ -1,5 +1,5 @@ { pkgs, ... }: -{ +let shellAliases = { e = "nvim"; ee = "nvim \"$(fzf)\""; @@ -15,4 +15,8 @@ # TODO: Gotta specify ~/.todo/config in Nix t = "${pkgs.todo-txt-cli}/bin/todo.sh"; }; +in +{ + programs.bash = { inherit shellAliases; }; + programs.zsh = { inherit shellAliases; }; } From ee398c9016d553c62bf1ed9b1a998d14f25f01a5 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:09:59 -0500 Subject: [PATCH 10/36] more common home modules --- flake.nix | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 1e98192..63c93ed 100644 --- a/flake.nix +++ b/flake.nix @@ -127,6 +127,24 @@ ./home/direnv.nix ]; }; + common-linux = { + imports = [ + self.homeModules.common + ./home/vscode-server.nix + ]; + programs.bash.enable = true; + }; + common-darwin = { + imports = [ + self.homeModules.common + ]; + programs.zsh = { + enable = true; + initExtra = '' + export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH + ''; + }; + }; }; # Configurations for Linux (NixOS) systems nixosConfigurations = @@ -135,15 +153,13 @@ { home-manager.users.${userName} = { pkgs, ... }: { imports = [ - self.homeModules.common + self.homeModules.common-linux (import ./home/git.nix { userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; }) ./home/shellcommon.nix - ./home/vscode-server.nix ]; - programs.bash.enable = true; }; } ]; @@ -167,13 +183,12 @@ users.users.uday.isNormalUser = true; home-manager.users."uday" = { imports = [ - self.homeModules.common + self.homeModules.common-linux (import ./home/git.nix { userName = "Uday Kiran"; userEmail = "udaycruise2903@gmail.com"; }) ]; - programs.bash.enable = true; }; } ]; @@ -195,20 +210,13 @@ { home-manager.users.${userName} = { pkgs, ... }: { imports = [ - self.homeModules.common + self.homeModules.common-darwin (import ./home/git.nix { userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; }) ./home/shellcommon.nix ]; - programs.zsh = { - enable = true; - initExtra = '' - export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH - ''; - }; - home.stateVersion = "21.11"; }; } ]; From 63c7ccb2cb7f4016f518addf549efb28f5b0bf58 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:10:54 -0500 Subject: [PATCH 11/36] avoid dup names --- flake.nix | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index 63c93ed..56ef947 100644 --- a/flake.nix +++ b/flake.nix @@ -149,26 +149,25 @@ # Configurations for Linux (NixOS) systems nixosConfigurations = let - homeModules = [ - { - home-manager.users.${userName} = { pkgs, ... }: { - imports = [ - self.homeModules.common-linux - (import ./home/git.nix { - userName = "Sridhar Ratnakumar"; - userEmail = "srid@srid.ca"; - }) - ./home/shellcommon.nix - ]; - }; - } - ]; mkLinuxSystem = extraModules: nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; # Arguments to pass to all modules. specialArgs = { inherit system inputs; }; - modules = - [ self.nixosModules.default ] ++ homeModules ++ extraModules; + modules = [ + self.nixosModules.default + { + home-manager.users.${userName} = { pkgs, ... }: { + imports = [ + self.homeModules.common-linux + ./home/shellcommon.nix + (import ./home/git.nix { + userName = "Sridhar Ratnakumar"; + userEmail = "srid@srid.ca"; + }) + ]; + }; + } + ] ++ extraModules; }; in { From 9ed6a3f16a76b407001e71b70ac1a234e95e9f28 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:12:31 -0500 Subject: [PATCH 12/36] cleanup --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 56ef947..87fc792 100644 --- a/flake.nix +++ b/flake.nix @@ -210,11 +210,11 @@ home-manager.users.${userName} = { pkgs, ... }: { imports = [ self.homeModules.common-darwin + ./home/shellcommon.nix (import ./home/git.nix { userName = "Sridhar Ratnakumar"; userEmail = "srid@srid.ca"; }) - ./home/shellcommon.nix ]; }; } From a0b850b1a62d3a1870863000f204ca7f6dec0206 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:20:47 -0500 Subject: [PATCH 13/36] start splitting --- flake.nix | 83 ++++-------------------------------------- home/default.nix | 29 +++++++++++++++ nix-darwin/default.nix | 21 +++++++++++ nixos/default.nix | 29 +++++++++++++++ 4 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 home/default.nix create mode 100644 nix-darwin/default.nix create mode 100644 nixos/default.nix diff --git a/flake.nix b/flake.nix index 87fc792..c5c6d91 100644 --- a/flake.nix +++ b/flake.nix @@ -32,7 +32,11 @@ outputs = inputs@{ self, home-manager, nixpkgs, darwin, ... }: inputs.flake-parts.lib.mkFlake { inherit (inputs) self; } { systems = [ "x86_64-linux" "aarch64-darwin" ]; - imports = [ ]; + imports = [ + ./home + ./nixos + ./nix-darwin + ]; perSystem = { self', inputs', config, pkgs, lib, system, ... }: { devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ @@ -72,80 +76,6 @@ userName = "srid"; in { - # Configuration common to all Linux systems - nixosModules = { - common.imports = [ - ./nixos/caches - ]; - home.imports = [ - home-manager.nixosModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "x86_64-linux"; - }; - }) - ]; - default.imports = - self.nixosModules.common.imports ++ - self.nixosModules.home.imports ++ - [ - ./nixos/self-ide.nix - ./nixos/takemessh - ./nixos/current-location.nix - ]; - }; - # Configuration common to all macOS systems - darwinModules = { - common = self.nixosConfig.common; - home.imports = [ - home-manager.darwinModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "aarch64-darwin"; - }; - }) - ]; - default.imports = - self.darwinModules.common ++ - self.darwinModules.home.imports; - }; - homeModules = { - common = { - home.stateVersion = "22.11"; - imports = [ - ./home/tmux.nix - ./home/neovim.nix - ./home/emacs.nix - ./home/starship.nix - ./home/terminal.nix - ./home/direnv.nix - ]; - }; - common-linux = { - imports = [ - self.homeModules.common - ./home/vscode-server.nix - ]; - programs.bash.enable = true; - }; - common-darwin = { - imports = [ - self.homeModules.common - ]; - programs.zsh = { - enable = true; - initExtra = '' - export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH - ''; - }; - }; - }; # Configurations for Linux (NixOS) systems nixosConfigurations = let @@ -216,6 +146,9 @@ userEmail = "srid@srid.ca"; }) ]; + programs.zsh.initExtra = '' + export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH + ''; }; } ]; diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..0be1555 --- /dev/null +++ b/home/default.nix @@ -0,0 +1,29 @@ +{ self, inputs, ... }: +{ + flake.homeModules = { + common = { + home.stateVersion = "22.11"; + imports = [ + ./tmux.nix + ./neovim.nix + ./emacs.nix + ./starship.nix + ./terminal.nix + ./direnv.nix + ]; + }; + common-linux = { + imports = [ + self.homeModules.common + ./vscode-server.nix + ]; + programs.bash.enable = true; + }; + common-darwin = { + imports = [ + self.homeModules.common + ]; + programs.zsh.enable = true; + }; + }; +} diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix new file mode 100644 index 0000000..59e0e1e --- /dev/null +++ b/nix-darwin/default.nix @@ -0,0 +1,21 @@ +{ self, inputs, ... }: +{ + # Configuration common to all macOS systems + flake.darwinModules = { + common = self.nixosConfig.common; + home.imports = [ + inputs.home-manager.darwinModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "aarch64-darwin"; + }; + }) + ]; + default.imports = + self.darwinModules.common ++ + self.darwinModules.home.imports; + }; +} diff --git a/nixos/default.nix b/nixos/default.nix new file mode 100644 index 0000000..8c85bf6 --- /dev/null +++ b/nixos/default.nix @@ -0,0 +1,29 @@ +{ self, inputs, ... }: +{ + # Configuration common to all Linux systems + flake.nixosModules = { + # These imports are platform independent. + common.imports = [ + ./caches + ]; + home.imports = [ + inputs.home-manager.nixosModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "x86_64-linux"; + }; + }) + ]; + default.imports = + self.nixosModules.common.imports ++ + self.nixosModules.home.imports ++ + [ + ./self-ide.nix + ./takemessh + ./current-location.nix + ]; + }; +} From 2991d29adb6280ecee752e58e8444b54f422ad63 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:26:13 -0500 Subject: [PATCH 14/36] separate out nixos and nix-darwin toplevel --- flake.nix | 101 ++++++++++------------------------------- nix-darwin/default.nix | 60 +++++++++++++++++------- nixos/default.nix | 69 ++++++++++++++++++---------- 3 files changed, 114 insertions(+), 116 deletions(-) diff --git a/flake.nix b/flake.nix index c5c6d91..286c396 100644 --- a/flake.nix +++ b/flake.nix @@ -77,86 +77,33 @@ in { # Configurations for Linux (NixOS) systems - nixosConfigurations = - let - mkLinuxSystem = extraModules: 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, ... }: { - imports = [ - self.homeModules.common-linux - ./home/shellcommon.nix - (import ./home/git.nix { - userName = "Sridhar Ratnakumar"; - userEmail = "srid@srid.ca"; - }) - ]; - }; - } - ] ++ extraModules; - }; - in - { - # My Linux development computer (on Hetzner) - pinch = mkLinuxSystem - [ - ./systems/hetzner/ax41.nix - ./nixos/server/harden.nix + nixosConfigurations = { + # My Linux development computer (on Hetzner) + pinch = self.lib.mkLinuxSystem userName + [ + ./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"; - }) - ]; - }; - } - ]; - }; + # 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 = - let - mkMacosSystem = darwin.lib.darwinSystem; - defaultMacosSystem = mkMacosSystem rec { - system = "aarch64-darwin"; - specialArgs = { - inherit inputs system; - rosettaPkgs = import nixpkgs { system = "x86_64-darwin"; }; - }; - modules = [ - self.darwinModules.default - ./systems/darwin.nix - { - home-manager.users.${userName} = { pkgs, ... }: { - imports = [ - self.homeModules.common-darwin - ./home/shellcommon.nix - (import ./home/git.nix { - userName = "Sridhar Ratnakumar"; - userEmail = "srid@srid.ca"; - }) - ]; - programs.zsh.initExtra = '' - export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH - ''; - }; - } - ]; - }; - in - { - default = defaultMacosSystem; - }; + darwinConfigurations = { + default = self.lib.mkMacosSystem userName; + }; }; }; } diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 59e0e1e..5bab6cc 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -1,21 +1,49 @@ { self, inputs, ... }: { # Configuration common to all macOS systems - flake.darwinModules = { - common = self.nixosConfig.common; - home.imports = [ - inputs.home-manager.darwinModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "aarch64-darwin"; - }; - }) - ]; - default.imports = - self.darwinModules.common ++ - self.darwinModules.home.imports; + flake = { + darwinModules = { + common = self.nixosConfig.common; + home.imports = [ + inputs.home-manager.darwinModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "aarch64-darwin"; + }; + }) + ]; + default.imports = + self.darwinModules.common ++ + self.darwinModules.home.imports; + }; + mkMacosSystem = userName: inputs.darwin.lib.darwinSystem rec { + system = "aarch64-darwin"; + specialArgs = { + inherit inputs system; + rosettaPkgs = import inputs.nixpkgs { system = "x86_64-darwin"; }; + }; + modules = [ + self.darwinModules.default + ../systems/darwin.nix + { + home-manager.users.${userName} = { pkgs, ... }: { + imports = [ + self.homeModules.common-darwin + ../home/shellcommon.nix + (import ../home/git.nix { + userName = "Sridhar Ratnakumar"; + userEmail = "srid@srid.ca"; + }) + ]; + programs.zsh.initExtra = '' + export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH + ''; + }; + } + ]; + }; }; } diff --git a/nixos/default.nix b/nixos/default.nix index 8c85bf6..e045d34 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,29 +1,52 @@ { self, inputs, ... }: { # Configuration common to all Linux systems - flake.nixosModules = { - # These imports are platform independent. - common.imports = [ - ./caches - ]; - home.imports = [ - inputs.home-manager.nixosModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "x86_64-linux"; - }; - }) - ]; - default.imports = - self.nixosModules.common.imports ++ - self.nixosModules.home.imports ++ - [ - ./self-ide.nix - ./takemessh - ./current-location.nix + flake = { + nixosModules = { + # These imports are platform independent. + common.imports = [ + ./caches ]; + home.imports = [ + inputs.home-manager.nixosModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "x86_64-linux"; + }; + }) + ]; + default.imports = + self.nixosModules.common.imports ++ + self.nixosModules.home.imports ++ + [ + ./self-ide.nix + ./takemessh + ./current-location.nix + ]; + }; + + lib.mkLinuxSystem = userName: 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, ... }: { + imports = [ + self.homeModules.common-linux + ../home/shellcommon.nix + (import ../home/git.nix { + userName = "Sridhar Ratnakumar"; + userEmail = "srid@srid.ca"; + }) + ]; + }; + } + ] ++ extraModules; + }; }; } From 56e2b92633649faaf00672e9fdd333996e438d55 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:28:55 -0500 Subject: [PATCH 15/36] Fix darwin build --- flake.nix | 2 +- nix-darwin/default.nix | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 286c396..f24a034 100644 --- a/flake.nix +++ b/flake.nix @@ -102,7 +102,7 @@ # Configurations for macOS systems (using nix-darwin) darwinConfigurations = { - default = self.lib.mkMacosSystem userName; + default = self.lib-darwin.mkMacosSystem userName; }; }; }; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 5bab6cc..74d7741 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -3,7 +3,7 @@ # Configuration common to all macOS systems flake = { darwinModules = { - common = self.nixosConfig.common; + common = self.nixosModules.common; home.imports = [ inputs.home-manager.darwinModules.home-manager ({ @@ -16,10 +16,12 @@ }) ]; default.imports = - self.darwinModules.common ++ + [ + self.darwinModules.common + ] ++ self.darwinModules.home.imports; }; - mkMacosSystem = userName: inputs.darwin.lib.darwinSystem rec { + lib-darwin.mkMacosSystem = userName: inputs.darwin.lib.darwinSystem rec { system = "aarch64-darwin"; specialArgs = { inherit inputs system; From c3be5b79ce3b4004f8b7448c9f524f7ccd59b581 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 13:32:33 -0500 Subject: [PATCH 16/36] Separate out the app --- activate.nix | 32 ++++++++++++++++++++++++++++++++ flake.nix | 33 +++------------------------------ 2 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 activate.nix diff --git a/activate.nix b/activate.nix new file mode 100644 index 0000000..54f6143 --- /dev/null +++ b/activate.nix @@ -0,0 +1,32 @@ +# A rough flake-parts module for activating the system +# +# TODO: Replace with deploy-rs or (new) nixinate +{ self, inputs, ... }: +{ + perSystem = { system, pkgs, lib, ... }: { + apps.default = + let + # Create a flake app that wraps the given bash CLI. + bashCmdApp = name: cmd: { + type = "app"; + program = + (pkgs.writeShellApplication { + inherit name; + text = '' + set -x + ${cmd} + ''; + }) + "/bin/${name}"; + }; + in + if system == "aarch64-darwin" then + bashCmdApp "darwin" '' + ${self.darwinConfigurations.default.system}/sw/bin/darwin-rebuild \ + switch --flake ${self}#default + '' + else + bashCmdApp "linux" '' + ${lib.getExe pkgs.nixos-rebuild} --use-remote-sudo switch -j auto + ''; + }; +} diff --git a/flake.nix b/flake.nix index f24a034..4bf7dc1 100644 --- a/flake.nix +++ b/flake.nix @@ -36,40 +36,13 @@ ./home ./nixos ./nix-darwin + ./activate.nix ]; - perSystem = { self', inputs', config, pkgs, lib, system, ... }: { + perSystem = { pkgs, ... }: { devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - nixpkgs-fmt - # To enable webhint to analyze source files - nodejs - ]; + buildInputs = [ pkgs.nixpkgs-fmt ]; }; formatter = pkgs.nixpkgs-fmt; - apps.default = - let - # Create a flake app that wraps the given bash CLI. - bashCmdApp = name: cmd: { - type = "app"; - program = - (pkgs.writeShellApplication { - inherit name; - text = '' - set -x - ${cmd} - ''; - }) + "/bin/${name}"; - }; - in - if system == "aarch64-darwin" then - bashCmdApp "darwin" '' - ${self.darwinConfigurations.default.system}/sw/bin/darwin-rebuild \ - switch --flake ${self}#default - '' - else - bashCmdApp "linux" '' - ${lib.getExe pkgs.nixos-rebuild} --use-remote-sudo switch -j auto - ''; }; flake = let From 8472de8993ec181837bfaf068263610ded34e0b0 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:02:54 -0500 Subject: [PATCH 17/36] No need for initExtra --- home/default.nix | 6 ++++++ nix-darwin/default.nix | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/home/default.nix b/home/default.nix index 0be1555..64491cc 100644 --- a/home/default.nix +++ b/home/default.nix @@ -23,7 +23,13 @@ imports = [ self.homeModules.common ]; + programs.zsh.enable = true; + # To put nix and home-manager-installed packages in PATH. + home.sessionPath = [ + "/etc/profiles/per-user/$USER/bin" + "/run/current-system/sw/bin" + ]; }; }; } diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 74d7741..6b7134b 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -15,11 +15,10 @@ }; }) ]; - default.imports = - [ - self.darwinModules.common - ] ++ - self.darwinModules.home.imports; + default.imports = [ + self.darwinModules.common + self.darwinModules.home + ]; }; lib-darwin.mkMacosSystem = userName: inputs.darwin.lib.darwinSystem rec { system = "aarch64-darwin"; @@ -40,9 +39,6 @@ userEmail = "srid@srid.ca"; }) ]; - programs.zsh.initExtra = '' - export PATH=/etc/profiles/per-user/${userName}/bin:/run/current-system/sw/bin/:$PATH - ''; }; } ]; From bd5cde341a3468c3fe06ec5acb4cf4650dfeb851 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:11:42 -0500 Subject: [PATCH 18/36] keep username in config --- README.md | 6 ++-- config.nix | 9 ++++++ flake.nix | 62 ++++++++++++++++++++---------------------- nix-darwin/default.nix | 6 ++-- nixos/default.nix | 6 ++-- 5 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 config.nix 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 From 877677ab59970118dc6c4988b048a039e9e97ba5 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:12:52 -0500 Subject: [PATCH 19/36] reorg --- flake.nix | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 67ecc2f..bf384fa 100644 --- a/flake.nix +++ b/flake.nix @@ -39,12 +39,7 @@ ./nix-darwin ./activate.nix ]; - perSystem = { pkgs, ... }: { - devShells.default = pkgs.mkShell { - buildInputs = [ pkgs.nixpkgs-fmt ]; - }; - formatter = pkgs.nixpkgs-fmt; - }; + myUserName = "srid"; flake = { # Configurations for Linux (NixOS) systems @@ -70,11 +65,17 @@ } ]; }; - # Configurations for macOS systems (using nix-darwin) darwinConfigurations = { default = self.lib-darwin.mkMacosSystem; }; }; + + perSystem = { pkgs, ... }: { + devShells.default = pkgs.mkShell { + buildInputs = [ pkgs.nixpkgs-fmt ]; + }; + formatter = pkgs.nixpkgs-fmt; + }; }; } From 1edb6de8cebca3b918be9b1d70b9ebda71acd26d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:13:39 -0500 Subject: [PATCH 20/36] explain why default --- flake.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index bf384fa..49606c9 100644 --- a/flake.nix +++ b/flake.nix @@ -65,7 +65,9 @@ } ]; }; - # Configurations for macOS systems (using nix-darwin) + # Configurations for my only[^1] macOS machine (using nix-darwin) + # + # [^1]: This is why attr key is 'default'. darwinConfigurations = { default = self.lib-darwin.mkMacosSystem; }; From 5da95cf5d24959d6c2d6f42b7538a86bbdfbede4 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:17:15 -0500 Subject: [PATCH 21/36] move uday oow --- flake.nix | 14 +------------- uday.nix | 13 +++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 uday.nix diff --git a/flake.nix b/flake.nix index 49606c9..c0cfaf4 100644 --- a/flake.nix +++ b/flake.nix @@ -49,20 +49,8 @@ [ ./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"; - }) - ]; - }; - } + (import ./uday.nix { inherit self; }) ]; }; # Configurations for my only[^1] macOS machine (using nix-darwin) diff --git a/uday.nix b/uday.nix new file mode 100644 index 0000000..c2d9c63 --- /dev/null +++ b/uday.nix @@ -0,0 +1,13 @@ +{ self }: +{ + 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"; + }) + ]; + }; +} From 3fc619bae128ea26476224a255dde39a9d8bf447 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:40:11 -0500 Subject: [PATCH 22/36] create people module --- README.md | 4 ++-- config.nix | 30 +++++++++++++++++++++++++++--- flake.nix | 18 +++++++++++++++--- home/git.nix | 7 ++++--- nix-darwin/default.nix | 5 ++--- nixos/default.nix | 19 ++++++++++++++++--- uday.nix | 13 ------------- 7 files changed, 66 insertions(+), 30 deletions(-) delete mode 100644 uday.nix diff --git a/README.md b/README.md index 2eb5721..dfcee96 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ nix run - Clone this repo at `/etc/nixos` - Edit `flake.nix` and - add your Linux's hostname in the `nixosConfigurations` set, as well as - - update `myUserName`. + - update `people.myself` to your desired username. - 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 `myUserName`. + - Edit `flake.nix` to update `people.myself` to your desired username. - 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 index ce9c0c9..772e0b7 100644 --- a/config.nix +++ b/config.nix @@ -1,9 +1,33 @@ { config, lib, ... }: +let + userSubmodule = lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + }; + email = lib.mkOption { + type = lib.types.str; + }; + }; + }; + peopleSubmodule = lib.types.submodule { + options = { + users = lib.mkOption { + type = lib.types.attrsOf userSubmodule; + }; + myself = lib.mkOption { + type = lib.types.str; + description = '' + The name of the user that represents myself. + ''; + }; + }; + }; +in { options = { - myUserName = lib.mkOption { - type = lib.types.str; - description = "The canonical (only) user to add to all systems."; + people = lib.mkOption { + type = peopleSubmodule; }; }; } diff --git a/flake.nix b/flake.nix index c0cfaf4..15d942d 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,19 @@ ./activate.nix ]; - myUserName = "srid"; + people = { + myself = "srid"; + users = { + srid = { + name = "Sridhar Ratnakumar"; + email = "srid@srid.ca"; + }; + uday = { + name = "Uday Kiran"; + email = "udaycruise2903@gmail.com"; + }; + }; + }; flake = { # Configurations for Linux (NixOS) systems nixosConfigurations = { @@ -49,8 +61,8 @@ [ ./systems/hetzner/ax41.nix ./nixos/server/harden.nix - # Temporarily sharing with Uday. - (import ./uday.nix { inherit self; }) + # I share my Hetzner server with other people who need it. + self.nixosModules.other-people ]; }; # Configurations for my only[^1] macOS machine (using nix-darwin) diff --git a/home/git.nix b/home/git.nix index b804a03..5cd0427 100644 --- a/home/git.nix +++ b/home/git.nix @@ -1,12 +1,13 @@ -{ userName, userEmail }: -{ pkgs, ... }: +{ user }: +{ pkgs, config, ... }: { home.packages = [ pkgs.git-lfs ]; programs.git = { package = pkgs.gitAndTools.gitFull; enable = true; - inherit userName userEmail; + userName = user.name; + userEmail = user.email; aliases = { co = "checkout"; ci = "commit"; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 1247c64..fd7ad0f 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -30,13 +30,12 @@ self.darwinModules.default ../systems/darwin.nix { - home-manager.users.${config.myUserName} = { pkgs, ... }: { + home-manager.users.${config.people.myself} = { pkgs, ... }: { imports = [ self.homeModules.common-darwin ../home/shellcommon.nix (import ../home/git.nix { - userName = "Sridhar Ratnakumar"; - userEmail = "srid@srid.ca"; + user = config.people.users.${config.people.myself}; }) ]; }; diff --git a/nixos/default.nix b/nixos/default.nix index 8e13fcc..40daf63 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -18,6 +18,20 @@ }; }) ]; + other-people.imports = [ + # Temporarily sharing with Uday. + { + users.users.uday.isNormalUser = true; + home-manager.users."uday" = { + imports = [ + self.homeModules.common-linux + (import ../home/git.nix { + user = config.people.users.uday; + }) + ]; + }; + } + ]; default.imports = self.nixosModules.common.imports ++ self.nixosModules.home.imports ++ @@ -35,13 +49,12 @@ modules = [ self.nixosModules.default { - home-manager.users.${config.myUserName} = { pkgs, ... }: { + home-manager.users.${config.people.myself} = { pkgs, ... }: { imports = [ self.homeModules.common-linux ../home/shellcommon.nix (import ../home/git.nix { - userName = "Sridhar Ratnakumar"; - userEmail = "srid@srid.ca"; + user = config.people.users.${config.people.myself}; }) ]; }; diff --git a/uday.nix b/uday.nix deleted file mode 100644 index c2d9c63..0000000 --- a/uday.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ self }: -{ - 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"; - }) - ]; - }; -} From 19313e9ee82af301c7f2a33225a0c12bc009376c Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:45:02 -0500 Subject: [PATCH 23/36] pass flake-parts config to hm --- home/git.nix | 6 +++--- nix-darwin/default.nix | 3 ++- nixos/default.nix | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/home/git.nix b/home/git.nix index 5cd0427..f5750df 100644 --- a/home/git.nix +++ b/home/git.nix @@ -1,13 +1,13 @@ { user }: -{ pkgs, config, ... }: +{ pkgs, config, flake, ... }: { home.packages = [ pkgs.git-lfs ]; programs.git = { package = pkgs.gitAndTools.gitFull; enable = true; - userName = user.name; - userEmail = user.email; + userName = flake.config.people.users.${user}.name; + userEmail = flake.config.people.users.${user}.email; aliases = { co = "checkout"; ci = "commit"; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index fd7ad0f..dff4db4 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -12,6 +12,7 @@ home-manager.extraSpecialArgs = { inherit inputs; system = "aarch64-darwin"; + flake = { inherit config; }; }; }) ]; @@ -35,7 +36,7 @@ self.homeModules.common-darwin ../home/shellcommon.nix (import ../home/git.nix { - user = config.people.users.${config.people.myself}; + user = config.people.myself; }) ]; }; diff --git a/nixos/default.nix b/nixos/default.nix index 40daf63..86816ad 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -15,6 +15,7 @@ home-manager.extraSpecialArgs = { inherit inputs; system = "x86_64-linux"; + flake = { inherit config; }; }; }) ]; @@ -26,7 +27,7 @@ imports = [ self.homeModules.common-linux (import ../home/git.nix { - user = config.people.users.uday; + user = "uday"; }) ]; }; @@ -54,7 +55,7 @@ self.homeModules.common-linux ../home/shellcommon.nix (import ../home/git.nix { - user = config.people.users.${config.people.myself}; + user = config.people.myself; }) ]; }; From 8a9041b9bf0e5dc698a03f9f1f4c1f5ef887d5be Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:47:57 -0500 Subject: [PATCH 24/36] make git a normal module --- home/git.nix | 5 ++--- nix-darwin/default.nix | 4 +--- nixos/default.nix | 8 ++------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/home/git.nix b/home/git.nix index f5750df..8e2f358 100644 --- a/home/git.nix +++ b/home/git.nix @@ -1,4 +1,3 @@ -{ user }: { pkgs, config, flake, ... }: { home.packages = [ pkgs.git-lfs ]; @@ -6,8 +5,8 @@ programs.git = { package = pkgs.gitAndTools.gitFull; enable = true; - userName = flake.config.people.users.${user}.name; - userEmail = flake.config.people.users.${user}.email; + userName = flake.config.people.users.${config.home.username}.name; + userEmail = flake.config.people.users.${config.home.username}.email; aliases = { co = "checkout"; ci = "commit"; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index dff4db4..8a4f968 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -35,9 +35,7 @@ imports = [ self.homeModules.common-darwin ../home/shellcommon.nix - (import ../home/git.nix { - user = config.people.myself; - }) + ../home/git.nix ]; }; } diff --git a/nixos/default.nix b/nixos/default.nix index 86816ad..f3414d7 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -26,9 +26,7 @@ home-manager.users."uday" = { imports = [ self.homeModules.common-linux - (import ../home/git.nix { - user = "uday"; - }) + ../home/git.nix ]; }; } @@ -54,9 +52,7 @@ imports = [ self.homeModules.common-linux ../home/shellcommon.nix - (import ../home/git.nix { - user = config.people.myself; - }) + ../home/git.nix ]; }; } From b65c92fdbc46008c0afbc85f4033a32258f989e2 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:51:19 -0500 Subject: [PATCH 25/36] refactor --- nixos/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nixos/default.nix b/nixos/default.nix index f3414d7..5fbf658 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -31,14 +31,13 @@ }; } ]; - default.imports = - self.nixosModules.common.imports ++ - self.nixosModules.home.imports ++ - [ - ./self-ide.nix - ./takemessh - ./current-location.nix - ]; + default.imports = [ + self.nixosModules.common + self.nixosModules.home + ./self-ide.nix + ./takemessh + ./current-location.nix + ]; }; lib.mkLinuxSystem = extraModules: inputs.nixpkgs.lib.nixosSystem rec { From 350641dd14fcb579450965554e2586f0cd19edfd Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:53:18 -0500 Subject: [PATCH 26/36] expose myuser --- nix-darwin/default.nix | 19 ++++++++++--------- nixos/default.nix | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 8a4f968..ff803c1 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -16,9 +16,19 @@ }; }) ]; + myself = { + home-manager.users.${config.people.myself} = { pkgs, ... }: { + imports = [ + self.homeModules.common-darwin + ../home/shellcommon.nix + ../home/git.nix + ]; + }; + }; default.imports = [ self.darwinModules.common self.darwinModules.home + self.darwinModules.myself ]; }; lib-darwin.mkMacosSystem = inputs.darwin.lib.darwinSystem rec { @@ -30,15 +40,6 @@ modules = [ self.darwinModules.default ../systems/darwin.nix - { - home-manager.users.${config.people.myself} = { pkgs, ... }: { - imports = [ - self.homeModules.common-darwin - ../home/shellcommon.nix - ../home/git.nix - ]; - }; - } ]; }; }; diff --git a/nixos/default.nix b/nixos/default.nix index 5fbf658..0e1079b 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -31,9 +31,19 @@ }; } ]; + myself = { + home-manager.users.${config.people.myself} = { pkgs, ... }: { + imports = [ + self.homeModules.common-linux + ../home/shellcommon.nix + ../home/git.nix + ]; + }; + }; default.imports = [ self.nixosModules.common self.nixosModules.home + self.nixosModules.myself ./self-ide.nix ./takemessh ./current-location.nix @@ -46,15 +56,6 @@ specialArgs = { inherit system inputs; }; modules = [ self.nixosModules.default - { - home-manager.users.${config.people.myself} = { pkgs, ... }: { - imports = [ - self.homeModules.common-linux - ../home/shellcommon.nix - ../home/git.nix - ]; - }; - } ] ++ extraModules; }; }; From faa9878038ab1524d3a6c7d60a13854adb2a150e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:54:03 -0500 Subject: [PATCH 27/36] Refactor for consistency --- flake.nix | 17 +++++++++-------- nix-darwin/default.nix | 5 ++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index 15d942d..0398e7c 100644 --- a/flake.nix +++ b/flake.nix @@ -57,19 +57,20 @@ # Configurations for Linux (NixOS) systems nixosConfigurations = { # My Linux development computer (on Hetzner) - pinch = self.lib.mkLinuxSystem - [ - ./systems/hetzner/ax41.nix - ./nixos/server/harden.nix - # I share my Hetzner server with other people who need it. - self.nixosModules.other-people - ]; + pinch = self.lib.mkLinuxSystem [ + ./systems/hetzner/ax41.nix + ./nixos/server/harden.nix + # I share my Hetzner server with other people who need it. + self.nixosModules.other-people + ]; }; # Configurations for my only[^1] macOS machine (using nix-darwin) # # [^1]: This is why attr key is 'default'. darwinConfigurations = { - default = self.lib-darwin.mkMacosSystem; + default = self.lib-darwin.mkMacosSystem [ + ./systems/darwin.nix + ]; }; }; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index ff803c1..eaf1b35 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -31,7 +31,7 @@ self.darwinModules.myself ]; }; - lib-darwin.mkMacosSystem = inputs.darwin.lib.darwinSystem rec { + lib-darwin.mkMacosSystem = extraModules: inputs.darwin.lib.darwinSystem rec { system = "aarch64-darwin"; specialArgs = { inherit inputs system; @@ -39,8 +39,7 @@ }; modules = [ self.darwinModules.default - ../systems/darwin.nix - ]; + ] ++ extraModules; }; }; } From 027e07427bbac08cd324273909e63f70c6145658 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 14:54:53 -0500 Subject: [PATCH 28/36] more refactor --- nixos/default.nix | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/nixos/default.nix b/nixos/default.nix index 0e1079b..f249724 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -19,18 +19,16 @@ }; }) ]; - other-people.imports = [ + other-people = { # Temporarily sharing with Uday. - { - users.users.uday.isNormalUser = true; - home-manager.users."uday" = { - imports = [ - self.homeModules.common-linux - ../home/git.nix - ]; - }; - } - ]; + users.users.uday.isNormalUser = true; + home-manager.users."uday" = { + imports = [ + self.homeModules.common-linux + ../home/git.nix + ]; + }; + }; myself = { home-manager.users.${config.people.myself} = { pkgs, ... }: { imports = [ From 5e3f4fd77d02239754b0c80eed90de9a01affa14 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:00:43 -0500 Subject: [PATCH 29/36] belongs here more --- home/default.nix | 88 ++++++++++++++++++++++++++++-------------- nix-darwin/default.nix | 14 +------ nixos/default.nix | 14 +------ 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/home/default.nix b/home/default.nix index 64491cc..2baede9 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,34 +1,64 @@ -{ self, inputs, ... }: +{ self, inputs, config, ... }: { - flake.homeModules = { - common = { - home.stateVersion = "22.11"; - imports = [ - ./tmux.nix - ./neovim.nix - ./emacs.nix - ./starship.nix - ./terminal.nix - ./direnv.nix - ]; - }; - common-linux = { - imports = [ - self.homeModules.common - ./vscode-server.nix - ]; - programs.bash.enable = true; - }; - common-darwin = { - imports = [ - self.homeModules.common - ]; + flake = { + homeModules = { + common = { + home.stateVersion = "22.11"; + imports = [ + ./tmux.nix + ./neovim.nix + ./emacs.nix + ./starship.nix + ./terminal.nix + ./direnv.nix + ]; + }; + common-linux = { + imports = [ + self.homeModules.common + ./vscode-server.nix + ]; + programs.bash.enable = true; + }; + common-darwin = { + imports = [ + self.homeModules.common + ]; - programs.zsh.enable = true; - # To put nix and home-manager-installed packages in PATH. - home.sessionPath = [ - "/etc/profiles/per-user/$USER/bin" - "/run/current-system/sw/bin" + programs.zsh.enable = true; + # To put nix and home-manager-installed packages in PATH. + home.sessionPath = [ + "/etc/profiles/per-user/$USER/bin" + "/run/current-system/sw/bin" + ]; + }; + }; + nixosModules.home-manager = { + imports = [ + inputs.home-manager.nixosModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "x86_64-linux"; + flake = { inherit config; }; + }; + }) + ]; + }; + darwinModules.home-manager = { + imports = [ + inputs.home-manager.darwinModules.home-manager + ({ + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = { + inherit inputs; + system = "aarch64-darwin"; + flake = { inherit config; }; + }; + }) ]; }; }; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index eaf1b35..a1804e8 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -4,18 +4,6 @@ flake = { darwinModules = { common = self.nixosModules.common; - home.imports = [ - inputs.home-manager.darwinModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "aarch64-darwin"; - flake = { inherit config; }; - }; - }) - ]; myself = { home-manager.users.${config.people.myself} = { pkgs, ... }: { imports = [ @@ -27,7 +15,7 @@ }; default.imports = [ self.darwinModules.common - self.darwinModules.home + self.darwinModules.home-manager self.darwinModules.myself ]; }; diff --git a/nixos/default.nix b/nixos/default.nix index f249724..db2474a 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -7,18 +7,6 @@ common.imports = [ ./caches ]; - home.imports = [ - inputs.home-manager.nixosModules.home-manager - ({ - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = { - inherit inputs; - system = "x86_64-linux"; - flake = { inherit config; }; - }; - }) - ]; other-people = { # Temporarily sharing with Uday. users.users.uday.isNormalUser = true; @@ -40,7 +28,7 @@ }; default.imports = [ self.nixosModules.common - self.nixosModules.home + self.nixosModules.home-manager self.nixosModules.myself ./self-ide.nix ./takemessh From ff61cd7cc1ed8ebdcb88209341fea4dea923aa52 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:05:25 -0500 Subject: [PATCH 30/36] decomplect common --- nix-darwin/default.nix | 3 +-- nixos/default.nix | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index a1804e8..3e69e29 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -3,7 +3,6 @@ # Configuration common to all macOS systems flake = { darwinModules = { - common = self.nixosModules.common; myself = { home-manager.users.${config.people.myself} = { pkgs, ... }: { imports = [ @@ -14,9 +13,9 @@ }; }; default.imports = [ - self.darwinModules.common self.darwinModules.home-manager self.darwinModules.myself + ../nixos/caches ]; }; lib-darwin.mkMacosSystem = extraModules: inputs.darwin.lib.darwinSystem rec { diff --git a/nixos/default.nix b/nixos/default.nix index db2474a..ba197ba 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -3,10 +3,6 @@ # Configuration common to all Linux systems flake = { nixosModules = { - # These imports are platform independent. - common.imports = [ - ./caches - ]; other-people = { # Temporarily sharing with Uday. users.users.uday.isNormalUser = true; @@ -27,9 +23,9 @@ }; }; default.imports = [ - self.nixosModules.common self.nixosModules.home-manager self.nixosModules.myself + ./caches ./self-ide.nix ./takemessh ./current-location.nix From ff3313e030c1f3988c620715b140b6c71fbd825e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:09:37 -0500 Subject: [PATCH 31/36] Refactor mkHomeModule --- flake.nix | 2 +- nixos/default.nix | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 0398e7c..9382d88 100644 --- a/flake.nix +++ b/flake.nix @@ -61,7 +61,7 @@ ./systems/hetzner/ax41.nix ./nixos/server/harden.nix # I share my Hetzner server with other people who need it. - self.nixosModules.other-people + self.nixosModules.guests ]; }; # Configurations for my only[^1] macOS machine (using nix-darwin) diff --git a/nixos/default.nix b/nixos/default.nix index ba197ba..7d2a068 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -1,27 +1,26 @@ { self, inputs, config, ... }: +let + mkHomeModule = name: extraModules: { + users.users.${name}.isNormalUser = true; + home-manager.users.${name} = { + imports = [ + self.homeModules.common-linux + ../home/git.nix + ] ++ extraModules; + }; + }; +in { # Configuration common to all Linux systems flake = { nixosModules = { - other-people = { - # Temporarily sharing with Uday. - users.users.uday.isNormalUser = true; - home-manager.users."uday" = { - imports = [ - self.homeModules.common-linux - ../home/git.nix - ]; - }; - }; - myself = { - home-manager.users.${config.people.myself} = { pkgs, ... }: { - imports = [ - self.homeModules.common-linux - ../home/shellcommon.nix - ../home/git.nix - ]; - }; - }; + guests.imports = [ + # Temporarily sharing with Uday, until he gets better machine. + (mkHomeModule "uday" [ ]) + ]; + myself = mkHomeModule "srid" [ + ../home/shellcommon.nix + ]; default.imports = [ self.nixosModules.home-manager self.nixosModules.myself From dd0bf0c9a1d4ca342a213b94aabdc747834ec343 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:13:29 -0500 Subject: [PATCH 32/36] Don't hardcode --- nixos/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/default.nix b/nixos/default.nix index 7d2a068..b284a9d 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -18,7 +18,7 @@ in # Temporarily sharing with Uday, until he gets better machine. (mkHomeModule "uday" [ ]) ]; - myself = mkHomeModule "srid" [ + myself = mkHomeModule config.people.myself [ ../home/shellcommon.nix ]; default.imports = [ From 0a8d28db1a5fac2c8e0956f9261a3ce0c9010e6b Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:19:06 -0500 Subject: [PATCH 33/36] Stop hardcoding my user name --- README.md | 1 + config.nix | 2 ++ nix-darwin/default.nix | 1 + nixos/default.nix | 5 ++++- nixos/docker.nix | 4 ++-- nixos/ema/emanote.nix | 6 +++--- nixos/lxd.nix | 4 ++-- nixos/monitor-brightness.nix | 6 +++--- nixos/protonvpn.nix | 4 ++-- nixos/self-ide.nix | 4 ++-- nixos/server/harden.nix | 4 ++-- nixos/takemessh/default.nix | 4 ++-- nixos/virtualbox.nix | 4 ++-- systems/darwin.nix | 8 ++++---- systems/hetzner/ax41.nix | 4 ++-- 15 files changed, 34 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index dfcee96..4a9d3bb 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ nix run - Edit `flake.nix` and - add your Linux's hostname in the `nixosConfigurations` set, as well as - update `people.myself` to your desired username. + - put your SSH keys in `./nixos/takemessh` - Run `nix run`. That's it. Re-open your shell. - macOS: - Install Nix normally (multi-user) diff --git a/config.nix b/config.nix index 772e0b7..8368415 100644 --- a/config.nix +++ b/config.nix @@ -19,6 +19,8 @@ let type = lib.types.str; description = '' The name of the user that represents myself. + + Admin user in all contexts. ''; }; }; diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 3e69e29..9077145 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -22,6 +22,7 @@ system = "aarch64-darwin"; specialArgs = { inherit inputs system; + flake = { inherit config; }; rosettaPkgs = import inputs.nixpkgs { system = "x86_64-darwin"; }; }; modules = [ diff --git a/nixos/default.nix b/nixos/default.nix index b284a9d..8343b72 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -34,7 +34,10 @@ in lib.mkLinuxSystem = extraModules: inputs.nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; # Arguments to pass to all modules. - specialArgs = { inherit system inputs; }; + specialArgs = { + inherit system inputs; + flake = { inherit config; }; + }; modules = [ self.nixosModules.default ] ++ extraModules; diff --git a/nixos/docker.nix b/nixos/docker.nix index eecc6d9..08950dc 100644 --- a/nixos/docker.nix +++ b/nixos/docker.nix @@ -1,7 +1,7 @@ -{ pkgs, ... }: { +{ pkgs, config, ... }: { virtualisation.docker.enable = true; - users.users.srid = { + users.users.${config.people.myself} = { extraGroups = [ "docker" ]; }; } diff --git a/nixos/ema/emanote.nix b/nixos/ema/emanote.nix index f154d2d..63d4711 100644 --- a/nixos/ema/emanote.nix +++ b/nixos/ema/emanote.nix @@ -1,4 +1,4 @@ -{ pkgs, inputs, system, ... }: +{ pkgs, inputs, system, flake, ... }: let emanote = inputs.emanote.outputs.defaultPackage.${system}; in @@ -12,9 +12,9 @@ in PORT = "7000"; }; serviceConfig = { - User = "srid"; + User = flake.config.people.myself; Restart = "always"; - ExecStart = "${emanote}/bin/emanote -L /home/srid/Documents/Notes"; + ExecStart = "${emanote}/bin/emanote -L /home/${flake.config.people.myself}/Documents/Notes"; }; }; } diff --git a/nixos/lxd.nix b/nixos/lxd.nix index 0c0c06d..560b12c 100644 --- a/nixos/lxd.nix +++ b/nixos/lxd.nix @@ -1,7 +1,7 @@ -{ pkgs, ... }: { +{ pkgs, flake, ... }: { virtualisation.lxd.enable = true; - users.users.srid = { + users.users.${flake.config.people.myself} = { extraGroups = [ "lxd" ]; }; } diff --git a/nixos/monitor-brightness.nix b/nixos/monitor-brightness.nix index 5ab66cf..2d18403 100644 --- a/nixos/monitor-brightness.nix +++ b/nixos/monitor-brightness.nix @@ -1,6 +1,6 @@ # TODO: GNOME support via https://extensions.gnome.org/extension/2645/brightness-control-using-ddcutil/ -{ pkgs, ... }: { +{ pkgs, flake, ... }: { # ddcutils requires i2c hardware.i2c.enable = true; @@ -15,7 +15,7 @@ security.sudo.extraRules = [ { - users = [ "srid" ]; + users = [ flake.config.people.myself ]; commands = [ { command = "${pkgs.ddcutil}/bin/ddcutil"; @@ -25,7 +25,7 @@ } ]; - users.users.srid = { + users.users.${flake.config.people.myself} = { extraGroups = [ "i2c" ]; }; diff --git a/nixos/protonvpn.nix b/nixos/protonvpn.nix index 5f6edf7..6bb46c6 100644 --- a/nixos/protonvpn.nix +++ b/nixos/protonvpn.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, flake, ... }: { environment.systemPackages = with pkgs; [ @@ -8,7 +8,7 @@ security.sudo.extraRules = [ { - users = [ "srid" ]; + users = [ flake.config.people.myself ]; commands = [ { command = "${pkgs.protonvpn-cli}/bin/protonvpn"; diff --git a/nixos/self-ide.nix b/nixos/self-ide.nix index f85b295..4f9414e 100644 --- a/nixos/self-ide.nix +++ b/nixos/self-ide.nix @@ -1,8 +1,8 @@ -{ pkgs, inputs, ... }: { +{ pkgs, inputs, flake, ... }: { # For no-prompt Ctrl+Shift+B in VSCode security.sudo.extraRules = [ { - users = [ "srid" ]; + users = [ flake.config.people.myself ]; commands = [ { command = "/run/current-system/sw/bin/nixos-rebuild"; diff --git a/nixos/server/harden.nix b/nixos/server/harden.nix index f218e77..81a3d4c 100644 --- a/nixos/server/harden.nix +++ b/nixos/server/harden.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: { +{ pkgs, flake, ... }: { # Firewall networking.firewall.enable = true; @@ -22,5 +22,5 @@ }; }; nix.settings.allowed-users = [ "root" "@users" ]; - nix.settings.trusted-users = [ "root" "srid" ]; + nix.settings.trusted-users = [ "root" flake.config.people.myself ]; } diff --git a/nixos/takemessh/default.nix b/nixos/takemessh/default.nix index e13addb..abbcdf0 100644 --- a/nixos/takemessh/default.nix +++ b/nixos/takemessh/default.nix @@ -1,9 +1,9 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, flake, ... }: { # Let me login users.users = { root.openssh.authorizedKeys.keys = [ (builtins.readFile ./id_rsa.pub) ]; - srid.openssh.authorizedKeys.keys = [ (builtins.readFile ./id_rsa.pub) ]; + ${flake.config.people.myself}.openssh.authorizedKeys.keys = [ (builtins.readFile ./id_rsa.pub) ]; }; } diff --git a/nixos/virtualbox.nix b/nixos/virtualbox.nix index 674d188..5e8b4fb 100644 --- a/nixos/virtualbox.nix +++ b/nixos/virtualbox.nix @@ -1,7 +1,7 @@ -{ pkgs, ... }: { +{ pkgs, flake, ... }: { virtualisation.virtualbox.host = { enable = true; enableExtensionPack = true; }; - users.extraGroups.vboxusers.members = [ "srid" ]; + users.extraGroups.vboxusers.members = [ flake.config.people.myself ]; } diff --git a/systems/darwin.nix b/systems/darwin.nix index fc3216e..5cd70be 100644 --- a/systems/darwin.nix +++ b/systems/darwin.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, inputs, system, rosettaPkgs, ... }: +{ config, pkgs, lib, inputs, system, flake, rosettaPkgs, ... }: { # List packages installed in system profile. To search by name, run: @@ -63,7 +63,7 @@ serviceConfig.ProgramArguments = [ (lib.getExe inputs.emanote.packages.${system}.default) "-L" - "/Users/srid/Keybase/Notes" + "/Users/${flake.config.people.myself}/Keybase/Notes" "run" "-p" "7000" @@ -74,8 +74,8 @@ security.pam.enableSudoTouchIdAuth = true; # For home-manager to work. - users.users.srid.name = "srid"; - users.users.srid.home = "/Users/srid"; + users.users.${flake.config.people.myself}.name = flake.config.people.myself; + users.users.${flake.config.people.myself}.home = "/Users/${flake.config.people.myself}"; # Use a custom configuration.nix location. # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix diff --git a/systems/hetzner/ax41.nix b/systems/hetzner/ax41.nix index baf199a..b2ce0c9 100644 --- a/systems/hetzner/ax41.nix +++ b/systems/hetzner/ax41.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, inputs, modulesPath, ... }: +{ config, pkgs, lib, inputs, modulesPath, flake, ... }: { imports = @@ -114,7 +114,7 @@ networking.firewall.checkReversePath = "loose"; # Tailscale recommends this # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.srid = { + users.users.${flake.config.people.myself} = { isNormalUser = true; extraGroups = [ "wheel" "networkmanager" ]; }; From fd20961376cfcf72ac6da1f5bbbdc709c039f36f Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:19:23 -0500 Subject: [PATCH 34/36] Remove unused systems --- systems/hetzner/ax101.nix | 148 -------------------------------------- systems/laptops/p71.nix | 103 -------------------------- 2 files changed, 251 deletions(-) delete mode 100644 systems/hetzner/ax101.nix delete mode 100644 systems/laptops/p71.nix diff --git a/systems/hetzner/ax101.nix b/systems/hetzner/ax101.nix deleted file mode 100644 index 34c5680..0000000 --- a/systems/hetzner/ax101.nix +++ /dev/null @@ -1,148 +0,0 @@ -{ config, pkgs, lib, inputs, modulesPath, ... }: - -{ - imports = - [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; - - boot.initrd.availableKernelModules = [ "nvme" "ahci" ]; - boot.initrd.kernelModules = [ "dm-snapshot" ]; - boot.kernelModules = [ "kvm-amd" ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = - { - device = "/dev/disk/by-uuid/480156e1-b229-4f5b-883a-34b7e5a9e0e9"; - fsType = "ext4"; - }; - - swapDevices = [ ]; - - nix.settings.max-jobs = lib.mkDefault 32; - powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand"; - hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; - - # Use GRUB2 as the boot loader. - # We don't use systemd-boot because Hetzner uses BIOS legacy boot. - boot.loader.systemd-boot.enable = false; - boot.loader.grub = { - enable = true; - efiSupport = false; - devices = [ "/dev/nvme1n1" "/dev/nvme0n1" ]; - }; - - # The madm RAID was created with a certain hostname, which madm will consider - # the "home hostname". Changing the system hostname will result in the array - # being considered "foregin" as opposed to "local", and showing it as - # '/dev/md/:root0' instead of '/dev/md/root0'. - - # This is mdadm's protection against accidentally putting a RAID disk - # into the wrong machine and corrupting data by accidental sync, see - # https://bugzilla.redhat.com/show_bug.cgi?id=606481#c14 and onward. - # We set the HOMEHOST manually go get the short '/dev/md' names, - # and so that things look and are configured the same on all such - # machines irrespective of host names. - # We do not worry about plugging disks into the wrong machine because - # we will never exchange disks between machines. - environment.etc."mdadm.conf".text = '' - HOMEHOST now - ''; - - # The RAIDs are assembled in stage1, so we need to make the config - # available there. - boot.initrd.services.swraid.mdadmConf = config.environment.etc."mdadm.conf".text; - - # Network (Hetzner uses static IP assignments, and we don't use DHCP here) - networking.useDHCP = false; - - networking.interfaces."enp7s0" = { - ipv4 = { - addresses = [{ - # Server main IPv4 address - address = "136.243.12.116"; - prefixLength = 24; - }]; - - routes = [ - # Default IPv4 gateway route - { - address = "0.0.0.0"; - prefixLength = 0; - via = "136.243.12.65"; - } - ]; - }; - - ipv6 = { - addresses = [{ - address = "2a01:4f8:211:25c9::1"; - prefixLength = 64; - }]; - - # Default IPv6 route - routes = [{ - address = "::"; - prefixLength = 0; - via = "fe80::1"; - }]; - }; - }; - - networking = { - nameservers = [ "8.8.8.8" "8.8.4.4" ]; - hostName = "now"; - }; - - nix = { - # package = pkgs.nixUnstable; - extraOptions = '' - experimental-features = nix-command flakes repl-flake - ''; - }; - - services.netdata.enable = true; - - environment.systemPackages = with pkgs; [ - lsof - inputs.nixos-shell.defaultPackage.${system} - - # Encrypted private directory stuff - # See https://srid.ca/vf.enc - cryptsetup - (pkgs.writeShellApplication { - name = "now-mount-priv"; - runtimeInputs = [ cryptsetup ]; - text = '' - set -x - sudo cryptsetup luksOpen /dev/nvme0n1p3 crypted0 - sudo mount /dev/mapper/crypted0 /extra0 - ''; - }) - ]; - - services.openssh.permitRootLogin = "prohibit-password"; - services.openssh.enable = true; - services.syncthing = { - enable = true; - user = "srid"; - dataDir = "/home/srid/priv/syncthing"; - }; - services.tailscale.enable = true; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.srid = { - isNormalUser = true; - extraGroups = [ "wheel" "networkmanager" ]; - }; - security.sudo.wheelNeedsPassword = false; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "21.11"; # Did you read the comment? - -} diff --git a/systems/laptops/p71.nix b/systems/laptops/p71.nix deleted file mode 100644 index 56a7208..0000000 --- a/systems/laptops/p71.nix +++ /dev/null @@ -1,103 +0,0 @@ -{ config, pkgs, lib, modulesPath, inputs, ... }: - -{ - imports = - [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; - - boot.initrd.availableKernelModules = [ "xhci_pci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.kernelPackages = pkgs.linuxPackages_latest; - # Kernel w/ clear linux like patches: https://github.com/NixOS/nixpkgs/issues/63708#issuecomment-1003875463 - # boot.kernelPackages = pkgs.linuxPackages_xanmod; - boot.supportedFilesystems = [ "ntfs" ]; - # https://notes.srid.ca/rtl8821cu - # boot.extraModulePackages = [ config.boot.kernelPackages.rtl8821cu ]; - - # Use the systemd-boot EFI boot loader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - fileSystems."/" = - { - device = "/dev/disk/by-uuid/25d3748c-b6fc-43d6-819a-e916821bd06e"; - fsType = "ext4"; - }; - boot.initrd.luks.devices."crypted".device = "/dev/disk/by-uuid/ccc661bc-c59f-4172-b6e0-2ba54d34de5c"; - fileSystems."/boot" = - { - device = "/dev/disk/by-uuid/A782-D559"; - fsType = "vfat"; - }; - - swapDevices = [ ]; - - # high-resolution display - hardware.video.hidpi.enable = lib.mkDefault true; - - hardware.pulseaudio.enable = true; - hardware.pulseaudio.support32Bit = true; ## If compatibility with 32-bit applications is desired. - - # services.xserver.videoDrivers = [ "nvidia" "intel" ]; - services.xserver.videoDrivers = [ "intel" ]; - #hardware.nvidia.modesetting.enable = true; # Required for Wayland+GDM, apparently. - # On KDE+nvidia, display scaling can only be set here. - services.xserver.dpi = 170; - # Not sure how to merge two screens in KDE - # cf. https://github.com/srid/nix-config/blob/master/device/p71/graphics.nix - # These are the default. - #services.xserver.deviceSection = '' - # Option "Twinview" - #''; - #services.xserver.serverLayoutSection = '' - # Option "Xinerama" "off" - #''; - - nix = { - package = pkgs.nixFlakes; - extraOptions = '' - experimental-features = nix-command flakes repl-flake - ''; - }; - - networking.hostName = "thick"; # Define your hostname. - networking.networkmanager.enable = true; - - services.openssh.enable = true; - services = { - syncthing = { - enable = true; - user = "srid"; - dataDir = "/home/srid"; - }; - neo4j = { - enable = false; - }; - }; - services.ipfs = { - enable = false; # 8080 conflicts with playground-server - autoMigrate = true; - }; - - programs = { - mosh.enable = true; - ssh.startAgent = true; - }; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.srid = { - isNormalUser = true; - extraGroups = [ "wheel" "networkmanager" "audio" ]; - }; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "21.11"; # Did you read the comment? - -} From e5ad850eb87c30627b48fe7f32e5dfdb0ce2ca12 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:20:26 -0500 Subject: [PATCH 35/36] Remove unused email.nix --- home/email.nix | 55 -------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 home/email.nix diff --git a/home/email.nix b/home/email.nix deleted file mode 100644 index bfe591e..0000000 --- a/home/email.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ pkgs, ... }: -let - realName = "Sridhar Ratnakumar"; - # IMAP/SMTP settings for standard email servers - servers = { - icloud = { - imap = { - host = "imap.mail.me.com"; - port = 993; - tls.enable = true; - }; - smtp = { - host = "smtp.mail.me.com"; - port = 587; - tls.enable = true; - }; - }; - protonmail = { - imap = { - host = "127.0.0.1"; - port = 1143; - tls.enable = true; - tls.useStartTls = true; - }; - smtp = { - host = "127.0.0.1"; - port = 1025; - tls.enable = true; - }; - }; - }; -in -{ - programs.himalaya = { - enable = true; - settings = { }; - }; - accounts.email.accounts = { - proton = servers.protonmail // { - inherit realName; - primary = true; - himalaya.enable = true; - address = "srid@srid.ca"; - userName = "hey@srid.ca"; - passwordCommand = "cat /Users/srid/.protonmail.password"; # Temporary password from ProtonMail Bridge, so I don't care - }; - icloud = servers.icloud // { - inherit realName; - address = "happyandharmless@icloud.com"; - userName = "happyandharmless"; - passwordCommand = "op item get iCloud --fields label=himalaya"; - }; - }; -} - From 2662c8167960c54812a40db761ac863db65d2e41 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 3 Dec 2022 15:22:01 -0500 Subject: [PATCH 36/36] Fix darwin build --- systems/darwin.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/systems/darwin.nix b/systems/darwin.nix index 5cd70be..83b8173 100644 --- a/systems/darwin.nix +++ b/systems/darwin.nix @@ -74,8 +74,10 @@ security.pam.enableSudoTouchIdAuth = true; # For home-manager to work. - users.users.${flake.config.people.myself}.name = flake.config.people.myself; - users.users.${flake.config.people.myself}.home = "/Users/${flake.config.people.myself}"; + users.users.${flake.config.people.myself} = { + name = flake.config.people.myself; + home = "/Users/${flake.config.people.myself}"; + }; # Use a custom configuration.nix location. # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix