From cf94e26b804bb30e407488e3fa77c1a3f2f4ef9c Mon Sep 17 00:00:00 2001 From: winston Date: Sat, 24 Jun 2023 21:24:20 +0200 Subject: [PATCH] feat: rework shared/common lib --- machines/bento/default.nix | 23 +++++---------- machines/common/darwin/default.nix | 2 -- machines/common/linux/default.nix | 2 ++ machines/common/shared/default.nix | 2 ++ .../common/{default.nix => shared/nix.nix} | 3 -- machines/common/shared/user.nix | 28 +++++++++++++++++++ machines/futomaki/default.nix | 27 ++++++------------ machines/lib.nix | 27 ++++++++++++++---- machines/sashimi/default.nix | 6 +--- 9 files changed, 70 insertions(+), 50 deletions(-) rename machines/common/{default.nix => shared/nix.nix} (93%) create mode 100644 machines/common/shared/user.nix diff --git a/machines/bento/default.nix b/machines/bento/default.nix index fc8543f..40fa88c 100644 --- a/machines/bento/default.nix +++ b/machines/bento/default.nix @@ -1,10 +1,9 @@ -{pkgs, ...}: let - mainUser = "w"; -in { - imports = [ - ./hardware.nix - ../common/linux - ]; +{ + config, + pkgs, + ... +}: { + imports = [./hardware.nix]; boot = { kernelPackages = pkgs.linuxPackages_latest; @@ -31,13 +30,5 @@ in { }; virtualisation.docker.enable = true; - - users.users."${mainUser}" = { - extraGroups = ["wheel" "docker"]; - isNormalUser = true; - openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILm0O46zW/XfVOSwz0okRWYeOAg+wCVkCtCAoVTpZsOh"]; - shell = pkgs.zsh; - }; - - system.stateVersion = "22.11"; + users.users."${config.dotfiles.username}".extraGroups = ["docker"]; } diff --git a/machines/common/darwin/default.nix b/machines/common/darwin/default.nix index 0ad9da2..e5f163e 100644 --- a/machines/common/darwin/default.nix +++ b/machines/common/darwin/default.nix @@ -2,8 +2,6 @@ # manipulate the global /etc/zshenv for PATH, etc. programs.zsh.enable = true; - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog system.stateVersion = 4; security.pam.enableSudoTouchIdAuth = true; diff --git a/machines/common/linux/default.nix b/machines/common/linux/default.nix index c6bacea..9514f24 100644 --- a/machines/common/linux/default.nix +++ b/machines/common/linux/default.nix @@ -36,4 +36,6 @@ programs.nix-ld.enable = true; programs.zsh.enable = true; + + system.stateVersion = "22.11"; } diff --git a/machines/common/shared/default.nix b/machines/common/shared/default.nix index db6f8b1..590c11c 100644 --- a/machines/common/shared/default.nix +++ b/machines/common/shared/default.nix @@ -1,5 +1,7 @@ { imports = [ + ./nix.nix ./podman.nix + ./user.nix ]; } diff --git a/machines/common/default.nix b/machines/common/shared/nix.nix similarity index 93% rename from machines/common/default.nix rename to machines/common/shared/nix.nix index 94f614a..ade79aa 100644 --- a/machines/common/default.nix +++ b/machines/common/shared/nix.nix @@ -1,7 +1,4 @@ {pkgs, ...}: { - imports = [ - ./shared - ]; nixpkgs.config.allowUnfree = true; nix = { gc.automatic = true; diff --git a/machines/common/shared/user.nix b/machines/common/shared/user.nix new file mode 100644 index 0000000..3b0dd63 --- /dev/null +++ b/machines/common/shared/user.nix @@ -0,0 +1,28 @@ +{ + config, + lib, + pkgs, + ... +}: let + homeRoot = + if pkgs.stdenv.isDarwin + then "/Users" + else if pkgs.stdenv.isLinux + then "/home" + else throw "Unsupported OS"; +in { + users.users."${config.dotfiles.username}" = + { + home = "${homeRoot}/${config.dotfiles.username}"; + openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILm0O46zW/XfVOSwz0okRWYeOAg+wCVkCtCAoVTpZsOh"]; + shell = pkgs.zsh; + } + // ( + if pkgs.stdenv.isLinux + then { + isNormalUser = lib.mkIf pkgs.stdenv.isLinux true; + extraGroups = ["wheel"]; + } + else {} + ); +} diff --git a/machines/futomaki/default.nix b/machines/futomaki/default.nix index 00aeb9b..0018119 100644 --- a/machines/futomaki/default.nix +++ b/machines/futomaki/default.nix @@ -1,10 +1,9 @@ -{pkgs, ...}: let - mainUser = "winston"; -in { - imports = [ - ./hardware.nix - ../common/linux - ]; +{ + config, + pkgs, + ... +}: { + imports = [./hardware.nix]; networking = { hostName = "futomaki"; @@ -19,19 +18,14 @@ in { blueman.enable = true; openssh.enable = true; pcscd.enable = true; + transmission.enable = true; + transmission.openFirewall = true; }; virtualisation.docker.enable = true; virtualisation.libvirtd.enable = true; - users.users."${mainUser}" = { - extraGroups = ["docker" "libvirtd" "wheel" "transmission"]; - isNormalUser = true; - openssh.authorizedKeys.keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILm0O46zW/XfVOSwz0okRWYeOAg+wCVkCtCAoVTpZsOh"]; - shell = pkgs.zsh; - }; - - system.stateVersion = "22.11"; + users.users."${config.dotfiles.username}".extraGroups = ["docker" "libvirtd" "transmission"]; environment.systemPackages = with pkgs; [ (discord.override {withOpenASAR = true;}) @@ -54,7 +48,4 @@ in { }; }; }; - - services.transmission.enable = true; - services.transmission.openFirewall = true; } diff --git a/machines/lib.nix b/machines/lib.nix index a05215f..979d4eb 100644 --- a/machines/lib.nix +++ b/machines/lib.nix @@ -33,10 +33,6 @@ }; }; }); - mkMerge = contents: { - _type = "merge"; - inherit contents; - }; mkSystem = { host, system, @@ -61,17 +57,36 @@ else if isDarwin then "darwinModules" else throw "Unsupported system"; + hostPlatform = + if isLinux + then "linux" + else if isDarwin + then "darwin" + else throw "Unsupported system"; pkgs = inputs.nixpkgs.legacyPackages.${system}; inherit (pkgs.stdenv) isDarwin isLinux; in { ${target}."${host}" = builder { inherit system; modules = with inputs; - [./common ./${host} home-manager.${module}.home-manager] + [ + { + options.dotfiles.username = with pkgs.lib; + mkOption { + description = "Main user of this configuration."; + type = types.str; + default = "${username}"; + }; + } + ./common/shared + ./common/${hostPlatform} + ./${host} + home-manager.${module}.home-manager + ] ++ pkgs.lib.optionals isDarwin [nekowinston-nur.darwinModules.default] ++ [(hmCommonConfig {inherit username;})] ++ extraModules; }; }; - mkSystems = systems: mkMerge (map mkSystem systems); + mkSystems = systems: inputs.nixpkgs.lib.mkMerge (map mkSystem systems); } diff --git a/machines/sashimi/default.nix b/machines/sashimi/default.nix index b783093..6212a85 100644 --- a/machines/sashimi/default.nix +++ b/machines/sashimi/default.nix @@ -1,10 +1,6 @@ { - imports = [ - ./brew.nix - ../common/darwin - ]; + imports = [./brew.nix]; - users.users.winston.home = "/Users/winston"; networking.computerName = "sashimi"; networking.hostName = "sashimi"; }