From 0ec0c25238d7802829bb36b149e032c194e968af Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Wed, 3 Feb 2021 23:44:58 -0700 Subject: [PATCH] various refactors * Move extern lists to their own folder * Move unstable package and module imports to their own folder * Create a genPkgs function to avoid using legacyPackages for the whole package set * Move hmActivationPackages to legacyPackages --- README.md | 3 +- extern/default.nix | 12 +++++++ flake.nix | 78 ++++++++++++-------------------------------- hosts/default.nix | 24 +++++++------- lib/default.nix | 35 +++++++++++++++++++- pkgs/override.nix | 20 ------------ shell/default.nix | 7 +--- unstable/default.nix | 31 ++++++++++++++++++ 8 files changed, 114 insertions(+), 96 deletions(-) create mode 100644 extern/default.nix delete mode 100644 pkgs/override.nix create mode 100644 unstable/default.nix diff --git a/README.md b/README.md index 99a862f..a9c463a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ Some key advantages include: * Defined [packages](./pkgs/default.nix) and [modules](./modules/list.nix), are automatically wired and available from anywhere. They are _also_ sharable via their respective flake outputs. -* Easily [override](./pkgs/override.nix) packages from different nixpkgs versions. +* Easily [override](./unstable/default.nix) packages from different nixpkgs + versions. * Keep [user](./users) configuration isolated and easily reusable by taking advantage of [user profiles](./users/profiles) and [home-manager][home-manager]. * [Overlay](./overlays) files are automatically available and sharable. diff --git a/extern/default.nix b/extern/default.nix new file mode 100644 index 0000000..b3fcb5e --- /dev/null +++ b/extern/default.nix @@ -0,0 +1,12 @@ +{ inputs }: with inputs; +{ + modules = [ + home.nixosModules.home-manager + ci-agent.nixosModules.agent-profile + ]; + + overlays = [ + nur.overlay + devshell.overlay + ]; +} diff --git a/flake.nix b/flake.nix index cbd4e9b..7775366 100644 --- a/flake.nix +++ b/flake.nix @@ -26,37 +26,28 @@ , nixos-hardware }: let - inherit (builtins) attrValues; inherit (flake-utils.lib) eachDefaultSystem flattenTreeSystem; inherit (nixos.lib) recursiveUpdate; - inherit (self.lib) overlays nixosModules genPackages pkgImport + inherit (self.lib) overlays nixosModules genPackages genPkgs genHomeActivationPackages; - externOverlays = [ nur.overlay devshell.overlay ]; - externModules = [ - home.nixosModules.home-manager - ci-agent.nixosModules.agent-profile - ]; + extern = import ./extern { inherit inputs; }; + + pkgs' = genPkgs { inherit self; }; outputs = let system = "x86_64-linux"; - pkgs = self.legacyPackages.${system}; + pkgs = pkgs'.${system}; in { inherit nixosModules overlays; nixosConfigurations = - import ./hosts - (recursiveUpdate inputs { - inherit pkgs externModules system; - inherit (pkgs) lib; - }); - - homeConfigurations = - builtins.mapAttrs - (_: config: config.config.home-manager.users) - self.nixosConfigurations; + import ./hosts (recursiveUpdate inputs { + inherit pkgs system extern; + inherit (pkgs) lib; + }); overlay = import ./pkgs; @@ -68,50 +59,23 @@ defaultTemplate = self.templates.flk; }; - in - recursiveUpdate - (eachDefaultSystem - (system: - let - unstable = pkgImport master [ ] system; - pkgs = - let - override = import ./pkgs/override.nix; - overlays = [ - (override unstable) - self.overlay - (final: prev: { - lib = (prev.lib or { }) // { - inherit (nixos.lib) nixosSystem; - flk = self.lib; - utils = flake-utils.lib; - }; - }) - ] - ++ (attrValues self.overlays) - ++ externOverlays; - in - pkgImport nixos overlays system; - - packages = - flattenTreeSystem system - (genPackages { - inherit self pkgs; - }); - - in + systemOutputs = eachDefaultSystem (system: + let pkgs = pkgs'.${system}; in { - inherit packages; - hmActivationPackages = genHomeActivationPackages - self.homeConfigurations; + packages = flattenTreeSystem system + (genPackages { + inherit self pkgs; + }); devShell = import ./shell { inherit pkgs nixos; }; - legacyPackages = pkgs; - }) - ) - outputs; + legacyPackages.hmActivationPackages = + genHomeActivationPackages { inherit self; }; + } + ); + in + recursiveUpdate outputs systemOutputs; } diff --git a/hosts/default.nix b/hosts/default.nix index aec06e5..77535f6 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -5,7 +5,7 @@ , pkgs , self , system -, externModules +, extern , ... }: let @@ -15,9 +15,6 @@ let profiles = defaultImports (toString ../profiles); suites = import ../profiles/suites.nix { inherit lib profiles; }; - unstableModules = [ ]; - addToDisabledModules = [ ]; - config = hostName: nixosSystemExtended { inherit system; @@ -33,12 +30,17 @@ let let core = profiles.core.default; - modOverrides = { config, unstableModulesPath, ... }: { - disabledModules = unstableModules ++ addToDisabledModules; - imports = map - (path: "${unstableModulesPath}/${path}") - unstableModules; - }; + modOverrides = { config, unstableModulesPath, ... }: + let + unstable = import ../unstable; + inherit (unstable) modules disabledModules; + in + { + disabledModules = modules ++ disabledModules; + imports = map + (path: "${unstableModulesPath}/${path}") + modules; + }; global = { home-manager.useGlobalPkgs = true; @@ -80,7 +82,7 @@ let global local modOverrides - ] ++ externModules; + ] ++ extern.modules; }; diff --git a/lib/default.nix b/lib/default.nix index 584933c..a90b144 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -60,6 +60,34 @@ in overlays = pathsToImportedAttrs overlayPaths; + genPkgs = { self }: + let inherit (self) inputs; + in + (inputs.flake-utils.lib.eachDefaultSystem + (system: + let + extern = import ../extern { inherit inputs; }; + unstable = pkgImport inputs.master [ ] system; + overrides = (import ../unstable).packages; + + overlays = [ + (overrides unstable) + self.overlay + (final: prev: { + lib = (prev.lib or { }) // { + inherit (nixos.lib) nixosSystem; + flk = self.lib; + utils = inputs.flake-utils.lib; + }; + }) + ] + ++ (attrValues self.overlays) + ++ extern.overlays; + in + { pkgs = pkgImport nixos overlays system; } + ) + ).pkgs; + profileMap = map (profile: profile.default); recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: @@ -135,7 +163,12 @@ in in recursiveUpdate cachixAttrs modulesAttrs; - genHomeActivationPackages = hmConfigs: + genHomeActivationPackages = { self }: + let hmConfigs = + builtins.mapAttrs + (_: config: config.config.home-manager.users) + self.nixosConfigurations; + in mapAttrs (_: x: mapAttrs (_: cfg: cfg.home.activationPackage) diff --git a/pkgs/override.nix b/pkgs/override.nix deleted file mode 100644 index 6dbced6..0000000 --- a/pkgs/override.nix +++ /dev/null @@ -1,20 +0,0 @@ -# Packages inherited are imported in hosts/default.nix, and are pulled from -# nixpkgs master instead of the default nixos release. This doesn't actually -# install them, just creates an overlay to pull them from master if they are -# installed by the user elsewhere in the configuration. -pkgs: final: prev: -{ - inherit (pkgs) - manix; - - haskellPackages = prev.haskellPackages.override { - overrides = hfinal: hprev: - let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; - in - { - # same for haskell packages, matching ghc versions - inherit (pkgs.haskell.packages."ghc${version}") - haskell-language-server; - }; - }; -} diff --git a/shell/default.nix b/shell/default.nix index 9f85124..52656e5 100644 --- a/shell/default.nix +++ b/shell/default.nix @@ -11,9 +11,6 @@ let }).config.system.build; flk = pkgs.writeShellScriptBin "flk" '' - system="$(nix eval --impure --expr builtins.currentSystem)" - system="${"\${system//\\\"/"}}" - if [[ -z "$1" ]]; then echo "Usage: $(basename $0) [ up | iso {host} | install {host} | {host} [switch|boot|test] | home {host} {user} [switch] ]" elif [[ "$1" == "up" ]]; then @@ -31,7 +28,7 @@ let elif [[ "$1" == "install" ]]; then sudo nixos-install --flake "$DEVSHELL_ROOT#$2" "${"\${@:3}"}" elif [[ "$1" == "home" ]]; then - nix build "./#hmActivationPackages.$system.$2.$3" "${"\${@:4}"}" + nix build "./#hmActivationPackages.$2.$3" "${"\${@:4}"}" if [[ "$4" == "switch" ]]; then ./result/activate && unlink result fi @@ -50,8 +47,6 @@ pkgs.devshell.mkShell { nixos-install nixos-generate-config nixos-enter - nixos-option - pre-commit ]; env = { inherit name; }; diff --git a/unstable/default.nix b/unstable/default.nix new file mode 100644 index 0000000..ae7858d --- /dev/null +++ b/unstable/default.nix @@ -0,0 +1,31 @@ +{ + # modules to pull from master, stable version is automatically disabled + modules = [ ]; + + # if a modules name changed in master, add the old name here + disabledModules = [ ]; + + # packages pulled from master + packages = pkgs: final: prev: { + inherit (pkgs) + dhall + discord + element-desktop + manix + nixpkgs-fmt + qutebrowser + signal-desktop + starship; + + haskellPackages = prev.haskellPackages.override { + overrides = hfinal: hprev: + let version = prev.lib.replaceChars [ "." ] [ "" ] prev.ghc.version; + in + { + # same for haskell packages, matching ghc versions + inherit (pkgs.haskell.packages."ghc${version}") + haskell-language-server; + }; + }; + }; +}