keep username in config

This commit is contained in:
Sridhar Ratnakumar 2022-12-03 14:11:42 -05:00
parent 8472de8993
commit bd5cde341a
5 changed files with 49 additions and 40 deletions

View file

@ -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.

9
config.nix Normal file
View file

@ -0,0 +1,9 @@
{ config, lib, ... }:
{
options = {
myUserName = lib.mkOption {
type = lib.types.str;
description = "The canonical (only) user to add to all systems.";
};
};
}

View file

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

View file

@ -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

View file

@ -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