From 4717c7fb013ab2120b466c490e7ffdab5f56eaa4 Mon Sep 17 00:00:00 2001 From: Ilan Joselevich Date: Wed, 17 May 2023 00:15:23 +0300 Subject: [PATCH] treewide: refactor --- .gitignore | 1 + flake.lock | 21 ------ flake.nix | 29 ++++++--- hosts/tami-mac/configuration.nix | 65 ------------------- hosts/tami-mac/default.nix | 19 ++---- hosts/tami-mac/graphical.nix | 21 ++++++ ...ardware-configuration.nix => hardware.nix} | 4 +- hosts/tami-mac/networking.nix | 8 +++ hosts/tami-mac/packages.nix | 8 +++ hosts/tami-mac/programs.nix | 8 +++ hosts/tami-mac/users.nix | 20 ++++++ 11 files changed, 94 insertions(+), 110 deletions(-) create mode 100644 .gitignore delete mode 100644 hosts/tami-mac/configuration.nix create mode 100644 hosts/tami-mac/graphical.nix rename hosts/tami-mac/{hardware-configuration.nix => hardware.nix} (94%) create mode 100644 hosts/tami-mac/networking.nix create mode 100644 hosts/tami-mac/packages.nix create mode 100644 hosts/tami-mac/programs.nix create mode 100644 hosts/tami-mac/users.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1a6fb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*result* diff --git a/flake.lock b/flake.lock index f45fcd4..6cc1919 100644 --- a/flake.lock +++ b/flake.lock @@ -20,26 +20,6 @@ "type": "github" } }, - "nixinate": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1671116920, - "narHash": "sha256-QmDGsUUmAGn77UTR7eQJmebl8f3IIUCtmbbAdJqKA3s=", - "owner": "MatthewCroughan", - "repo": "nixinate", - "rev": "b4d17b8e2a4abc47e93e1a1c466e0286a63640d8", - "type": "github" - }, - "original": { - "owner": "MatthewCroughan", - "repo": "nixinate", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1684049129, @@ -59,7 +39,6 @@ "root": { "inputs": { "disko": "disko", - "nixinate": "nixinate", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index bc4fa69..e3a871c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,24 @@ { - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - inputs.disko = { url = "github:nix-community/disko"; inputs.nixpkgs.follows = "nixpkgs"; }; - inputs.nixinate = { url = "github:MatthewCroughan/nixinate"; inputs.nixpkgs.follows = "nixpkgs"; }; - - outputs = inputs: { - nixosConfigurations.tami-mac = import ./hosts/tami-mac inputs; - - apps = inputs.nixinate.nixinate.x86_64-linux inputs.self; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + disko = { url = "github:nix-community/disko"; inputs.nixpkgs.follows = "nixpkgs"; }; }; + + outputs = inputs: + let + system = "x86_64-linux"; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + inherit (inputs.nixpkgs) lib; + in + { + nixosConfigurations.tami-mac = import ./hosts/tami-mac inputs; + + apps.${system} = lib.mapAttrs' (n: v: lib.nameValuePair ("deploy-${n}") v) (lib.genAttrs (lib.attrNames inputs.self.nixosConfigurations) (host: { + type = "app"; + program = toString (pkgs.writeShellScript "deploy-${host}" '' + ${lib.getExe pkgs.nixos-rebuild} switch --fast --flake ${inputs.self}#${host} \ + --build-host tami@${host} --target-host tami@${host} + ''); + })); + }; } diff --git a/hosts/tami-mac/configuration.nix b/hosts/tami-mac/configuration.nix deleted file mode 100644 index cde61bd..0000000 --- a/hosts/tami-mac/configuration.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ pkgs, ... }: - -{ - networking = { - hostName = "tami-mac"; - networkmanager.enable = true; - }; - - time.timeZone = "Asia/Jerusalem"; - - services.pipewire = { - enable = true; - pulse.enable = true; - alsa.enable = true; - alsa.support32Bit = true; - }; - hardware.pulseaudio.enable = false; - sound.enable = false; - - system.stateVersion = "23.05"; - - programs.vim.defaultEditor = true; - - users = { - mutableUsers = false; - users."tami" = { - isNormalUser = true; - hashedPassword = "$y$j9T$BUWA7o2/xFFY6g/B9somr1$rveo/ttShW7jd835kf2pE9vAfDIXj/Hii3B5c9GyCjA"; - openssh.authorizedKeys.keys = [ - # Kranzes/Ilan - "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIBF2qWuvMCuJMlc6+ehyU0V/asmfAlT5/GLhUQqbpQ/bAAAABHNzaDo=" - "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIEVpaQ0K0Fzz0Hu48pqKiI25lr9ASwXR1yzYbeErBX/2AAAABHNzaDo=" - ]; - extraGroups = [ "wheel" "networkmanager" ]; - uid = 1000; - packages = with pkgs; [ - firefox - git - wget - ]; - }; - }; - - services.xserver = { - enable = true; - desktopManager.plasma5.enable = true; - displayManager = { - defaultSession = "plasmawayland"; - lightdm.enable = true; - autoLogin.user = "tami"; - }; - }; - - programs.dconf.enable = true; - - programs.xwayland.enable = true; - - hardware.opengl = { - enable = true; - driSupport = true; - driSupport32Bit = true; - }; - - programs.adb.enable = true; -} diff --git a/hosts/tami-mac/default.nix b/hosts/tami-mac/default.nix index 913c861..550d48e 100644 --- a/hosts/tami-mac/default.nix +++ b/hosts/tami-mac/default.nix @@ -1,21 +1,14 @@ inputs: -inputs.nixpkgs.lib.nixosSystem { +let inherit (inputs.nixpkgs) lib; in + +lib.nixosSystem { system = "x86_64-linux"; specialArgs = { inherit inputs; }; - modules = [ - ./configuration.nix - ./hardware-configuration.nix + modules = builtins.filter (x: lib.hasSuffix ".nix" x && baseNameOf x != "default.nix") (lib.filesystem.listFilesRecursive ./.) ++ [ + inputs.disko.nixosModules.disko "${inputs.self}/profiles/nix-nixpkgs.nix" "${inputs.self}/profiles/ssh.nix" - { - _module.args.nixinate = { - host = "tami-mac"; - sshUser = "tami"; - buildOn = "remote"; - substituteOnTarget = true; - hermetic = false; - }; - } + { system.stateVersion = "23.05"; } ]; } diff --git a/hosts/tami-mac/graphical.nix b/hosts/tami-mac/graphical.nix new file mode 100644 index 0000000..57ba063 --- /dev/null +++ b/hosts/tami-mac/graphical.nix @@ -0,0 +1,21 @@ +{ + services.xserver = { + enable = true; + desktopManager.plasma5.enable = true; + displayManager = { + defaultSession = "plasmawayland"; + lightdm.enable = true; + autoLogin.user = "tami"; + }; + }; + + programs.dconf.enable = true; + + programs.xwayland.enable = true; + + hardware.opengl = { + enable = true; + driSupport = true; + driSupport32Bit = true; + }; +} diff --git a/hosts/tami-mac/hardware-configuration.nix b/hosts/tami-mac/hardware.nix similarity index 94% rename from hosts/tami-mac/hardware-configuration.nix rename to hosts/tami-mac/hardware.nix index c49fc84..2293789 100644 --- a/hosts/tami-mac/hardware-configuration.nix +++ b/hosts/tami-mac/hardware.nix @@ -1,11 +1,9 @@ -{ inputs, pkgs, ... }: +{ pkgs, ... }: let device = "/dev/sda"; in { - imports = [ inputs.disko.nixosModules.disko ]; - disko.devices = { disk.${baseNameOf device} = { inherit device; diff --git a/hosts/tami-mac/networking.nix b/hosts/tami-mac/networking.nix new file mode 100644 index 0000000..c1af74b --- /dev/null +++ b/hosts/tami-mac/networking.nix @@ -0,0 +1,8 @@ +{ + networking = { + hostName = "tami-mac"; + networkmanager.enable = true; + }; + + time.timeZone = "Asia/Jerusalem"; +} diff --git a/hosts/tami-mac/packages.nix b/hosts/tami-mac/packages.nix new file mode 100644 index 0000000..2064285 --- /dev/null +++ b/hosts/tami-mac/packages.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + wget + tree + ]; +} diff --git a/hosts/tami-mac/programs.nix b/hosts/tami-mac/programs.nix new file mode 100644 index 0000000..840c6b1 --- /dev/null +++ b/hosts/tami-mac/programs.nix @@ -0,0 +1,8 @@ +{ + programs = { + vim.defaultEditor = true; + firefox.enable = true; + git.enable = true; + adb.enable = true; + }; +} diff --git a/hosts/tami-mac/users.nix b/hosts/tami-mac/users.nix new file mode 100644 index 0000000..7f0ffed --- /dev/null +++ b/hosts/tami-mac/users.nix @@ -0,0 +1,20 @@ +{ lib, config, ... }: + +{ + users = { + mutableUsers = false; + users."tami" = { + isNormalUser = true; + hashedPassword = "$y$j9T$BUWA7o2/xFFY6g/B9somr1$rveo/ttShW7jd835kf2pE9vAfDIXj/Hii3B5c9GyCjA"; + openssh.authorizedKeys.keys = [ + # Kranzes/Ilan + "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIBF2qWuvMCuJMlc6+ehyU0V/asmfAlT5/GLhUQqbpQ/bAAAABHNzaDo=" + "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIEVpaQ0K0Fzz0Hu48pqKiI25lr9ASwXR1yzYbeErBX/2AAAABHNzaDo=" + ]; + extraGroups = [ "wheel" ] + ++ lib.optional config.networking.networkmanager.enable "networkmanager" + ++ lib.optional config.programs.adb.enable "adbusers"; + uid = 1000; + }; + }; +}