From eac470013b1545103c64f42f923f19ac110c678c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 7 Aug 2023 22:27:54 +0100 Subject: [PATCH] refactor(flake): re-organise systems and modules --- flake.nix | 32 ++++++------------- system/nixos/{nixedo => }/configuration.nix | 11 +------ system/nixos/default.nix | 21 ++++++++++++ .../{nixedo => }/hardware-configuration.nix | 0 .../nixos/home-manager.nix | 10 +++--- system/wsl2/default.nix | 22 ++++++++----- 6 files changed, 51 insertions(+), 45 deletions(-) rename system/nixos/{nixedo => }/configuration.nix (94%) create mode 100644 system/nixos/default.nix rename system/nixos/{nixedo => }/hardware-configuration.nix (100%) rename home-manager/nixedo.nix => system/nixos/home-manager.nix (79%) diff --git a/flake.nix b/flake.nix index deb2493..dadc2bb 100644 --- a/flake.nix +++ b/flake.nix @@ -6,12 +6,17 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; }; - outputs = - inputs@{ flake-parts, home-manager, nixpkgs, nixpkgs-unstable, self, ... }: + outputs = inputs@{ flake-parts, self, ... }: + let + username = "opdavies"; + + nixos-system = import ./system/nixos { inherit inputs username; }; + wsl-system = import ./system/wsl2 { inherit inputs username; }; + in flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" ]; - perSystem = { pkgs, self', nixpkgs, ... }: { + perSystem = { pkgs, self', ... }: { packages = { opdavies-nvim = pkgs.vimUtils.buildVimPlugin { name = "opdavies-nvim"; @@ -24,28 +29,11 @@ flake = { nixosConfigurations = { - nixedo = nixpkgs.lib.nixosSystem { - modules = [ - ./system/nixos/nixedo/configuration.nix - - home-manager.nixosModules.home-manager - { - home-manager = { - extraSpecialArgs = { inherit inputs; }; - useGlobalPkgs = true; - useUserPackages = true; - users.opdavies = import ./home-manager/nixedo.nix; - }; - } - ]; - }; + nixedo = nixos-system; }; homeConfigurations = { - wsl2 = home-manager.lib.homeManagerConfiguration { - modules = [ ./system/wsl2.nix ]; - pkgs = nixpkgs.legacyPackages.x86_64-linux; - }; + wsl2 = wsl-system; }; }; }; diff --git a/system/nixos/nixedo/configuration.nix b/system/nixos/configuration.nix similarity index 94% rename from system/nixos/nixedo/configuration.nix rename to system/nixos/configuration.nix index 5d3eaad..de0de0b 100644 --- a/system/nixos/nixedo/configuration.nix +++ b/system/nixos/configuration.nix @@ -1,7 +1,3 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running ‘nixos-help’). - { config, lib, pkgs, ... }: let @@ -22,11 +18,6 @@ let }; in { - imports = [ - # Include the results of the hardware scan. - ./hardware-configuration.nix - ]; - nixpkgs = { config = { allowUnfree = true; @@ -42,7 +33,7 @@ in DefaultTimeoutStopSec=10s ''; - networking.hostName = "nixedo"; # Define your hostname. + # networking.hostName = "nixedo"; # Define your hostname. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # Configure network proxy if necessary diff --git a/system/nixos/default.nix b/system/nixos/default.nix new file mode 100644 index 0000000..f1d1361 --- /dev/null +++ b/system/nixos/default.nix @@ -0,0 +1,21 @@ +{ inputs, username }: + +let + configuration = import ./configuration.nix; + hardware-configuration = import ./hardware-configuration.nix; +in +inputs.nixpkgs.lib.nixosSystem { + modules = [ + inputs.home-manager.nixosModules.home-manager { + home-manager = { + extraSpecialArgs = { inherit inputs; }; + useGlobalPkgs = true; + useUserPackages = true; + users."${username}" = import ./home-manager.nix; + }; + } + + configuration + hardware-configuration + ]; +} diff --git a/system/nixos/nixedo/hardware-configuration.nix b/system/nixos/hardware-configuration.nix similarity index 100% rename from system/nixos/nixedo/hardware-configuration.nix rename to system/nixos/hardware-configuration.nix diff --git a/home-manager/nixedo.nix b/system/nixos/home-manager.nix similarity index 79% rename from home-manager/nixedo.nix rename to system/nixos/home-manager.nix index 9c5a579..888f487 100644 --- a/home-manager/nixedo.nix +++ b/system/nixos/home-manager.nix @@ -2,11 +2,11 @@ { imports = [ - ./modules/common.nix - ./modules/git.nix - ./modules/home-manager.nix - ./modules/tmux.nix - ./modules/zsh.nix + ../../home-manager/modules/common.nix + ../../home-manager/modules/git.nix + ../../home-manager/modules/home-manager.nix + ../../home-manager/modules/tmux.nix + ../../home-manager/modules/zsh.nix ]; home.stateVersion = "22.05"; diff --git a/system/wsl2/default.nix b/system/wsl2/default.nix index ff8cddc..e409080 100644 --- a/system/wsl2/default.nix +++ b/system/wsl2/default.nix @@ -1,11 +1,17 @@ -{ config, lib, pkgs, ... }: +{ inputs, username }: -{ - imports = [ - ../home-manager/modules/common.nix - ../home-manager/modules/git.nix - ../home-manager/modules/home-manager.nix - ../home-manager/modules/tmux.nix - ../home-manager/modules/zsh.nix +inputs.home-manager.lib.homeManagerConfiguration { + modules = [ + { + imports = [ + ../home-manager/modules/common.nix + ../home-manager/modules/git.nix + ../home-manager/modules/home-manager.nix + ../home-manager/modules/tmux.nix + ../home-manager/modules/zsh.nix + ]; + } ]; + + pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; }