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
This commit is contained in:
Timothy DeHerrera 2021-02-03 23:44:58 -07:00
parent 7b404f587d
commit 0ec0c25238
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
8 changed files with 114 additions and 96 deletions

View File

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

12
extern/default.nix vendored Normal file
View File

@ -0,0 +1,12 @@
{ inputs }: with inputs;
{
modules = [
home.nixosModules.home-manager
ci-agent.nixosModules.agent-profile
];
overlays = [
nur.overlay
devshell.overlay
];
}

View File

@ -26,38 +26,29 @@
, 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;
import ./hosts (recursiveUpdate inputs {
inherit pkgs system extern;
inherit (pkgs) lib;
});
homeConfigurations =
builtins.mapAttrs
(_: config: config.config.home-manager.users)
self.nixosConfigurations;
overlay = import ./pkgs;
lib = import ./lib { inherit nixos; };
@ -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
systemOutputs = eachDefaultSystem (system:
let pkgs = pkgs'.${system}; in
{
packages = flattenTreeSystem system
(genPackages {
inherit self pkgs;
});
in
{
inherit packages;
hmActivationPackages = genHomeActivationPackages
self.homeConfigurations;
devShell = import ./shell {
inherit pkgs nixos;
};
legacyPackages = pkgs;
})
)
outputs;
legacyPackages.hmActivationPackages =
genHomeActivationPackages { inherit self; };
}
);
in
recursiveUpdate outputs systemOutputs;
}

View File

@ -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,11 +30,16 @@ let
let
core = profiles.core.default;
modOverrides = { config, unstableModulesPath, ... }: {
disabledModules = unstableModules ++ addToDisabledModules;
modOverrides = { config, unstableModulesPath, ... }:
let
unstable = import ../unstable;
inherit (unstable) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${unstableModulesPath}/${path}")
unstableModules;
modules;
};
global = {
@ -80,7 +82,7 @@ let
global
local
modOverrides
] ++ externModules;
] ++ extern.modules;
};

View File

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

View File

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

View File

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

31
unstable/default.nix Normal file
View File

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