Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iso: only include the host's dependencies #197

Closed
wants to merge 10 commits into from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

**Documentation:**

- doc: split iso [\#193](https://github.com/divnix/devos/issues/193)
- lib: can depend on pkgs \(a la nixpkgs\#pkgs/pkgs-lib\) [\#147](https://github.com/divnix/devos/pull/147)

**Closed issues:**
Expand All @@ -36,6 +37,8 @@

**Merged pull requests:**

- hosts/devosSystem: pass modules as attrset [\#198](https://github.com/divnix/devos/pull/198)
- doc: enact bootstrapping section [\#196](https://github.com/divnix/devos/pull/196)
- iso: copy input closourse into iso to avoide re-download [\#191](https://github.com/divnix/devos/pull/191)
- add hosts module arg [\#164](https://github.com/divnix/devos/pull/164)

Expand Down
89 changes: 39 additions & 50 deletions hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,46 @@ let

suites = import ../suites { inherit lib; };

modules =
let
core = ../profiles/core;
modOverrides = { config, overrideModulesPath, ... }:
let
overrides = import ../overrides;
inherit (overrides) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};
modules = {
core = ../profiles/core;
modOverrides = { config, overrideModulesPath, ... }:
let
overrides = import ../overrides;
inherit (overrides) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};

global = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
global = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

hardware.enableRedistributableFirmware = lib.mkDefault true;
hardware.enableRedistributableFirmware = lib.mkDefault true;

nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/compat/nixos"
"home-manager=${home}"
];

nixpkgs = { inherit pkgs; };
nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/compat/nixos"
"home-manager=${home}"
];

nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = override;
};
nixpkgs = { inherit pkgs; };

system.configurationRevision = lib.mkIf (self ? rev) self.rev;
nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = override;
};

# Everything in `./modules/list.nix`.
flakeModules =
builtins.attrValues self.nixosModules;
system.configurationRevision = lib.mkIf (self ? rev) self.rev;
};

in
flakeModules ++ [
core
global
modOverrides
] ++ extern.modules;
# Everything in `./modules/list.nix`.
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; };
};

specialArgs = extern.specialArgs // { inherit suites; };

Expand All @@ -79,19 +71,16 @@ let
(removeAttrs hosts [ hostName ]);
};
};
lib = {
lib = { inherit specialArgs; };
lib.testModule = {
imports = builtins.attrValues modules;
};
};
in
dev.os.devosSystem {
inherit system specialArgs;

modules = modules ++ [
local
{
lib = { inherit specialArgs; };
lib.testModule = {
imports = modules;
};
}
];
modules = modules // { inherit local lib; };
};

hosts = dev.os.recImport
Expand Down
14 changes: 11 additions & 3 deletions lib/devos/devosSystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
lib.nixosSystem (args // {
modules =
let
moduleList = builtins.attrValues modules;
modpath = "nixos/modules";
cd = "installer/cd-dvd/installation-cd-minimal-new-kernel.nix";

hostConfig = (lib.nixosSystem (args // { modules = moduleList; })).config;

isoConfig = (lib.nixosSystem
(args // {
modules = modules ++ [
modules = moduleList ++ [
"${nixos}/${modpath}/${cd}"
({ config, ... }: {
({ config, suites, ... }: {
disabledModules = lib.remove modules.core suites.allProfiles;

isoImage.isoBaseName = "nixos-" + config.networking.hostName;
isoImage.contents = [{
source = self;
Expand All @@ -20,7 +25,10 @@ lib.nixosSystem (args // {
nix.registry = lib.mapAttrs (n: v: { flake = v; }) inputs;
isoImage.storeContents = [
self.devShell.${config.nixpkgs.system}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to add drvPath for devshell, as well, fixing #195, shall we?

Not meaning to block this PR, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x-ref: Pacman99#2 (also going to test that)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, merged!, But will that really cache evaluations? I thought evaluation caches were sqlite databases in your home directory. I remember it being a series of sqlite db's with hashe's as names

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @Pacman99 is right about the evaluation cache. I've been struggling with how to clear the dang thing for a while now. Pretty annoying when the error message for a failed derivation just becomes the generic:

failure of cached attribute

I know I found it's exact location once in order to clear it, but now I can't seem to find it. If it is still in the home dir, perhaps we could make some clever use of home-manager to include it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh for me its in ~/.cache/nix/eval-cache-v2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to safely delete that since its just evaluations that can be done again

hostConfig.system.build.toplevel
Copy link
Contributor

@blaggacao blaggacao Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is actually redundant: https://github.com/NixOS/nixpkgs/blob/a6155fc19e31fe0a49b75409d02a2d8b6bb97aa0/nixos/modules/installer/cd-dvd/iso-image.nix#L627-L638

and we need to remove the *.drvPath. Those are the size culprits. I thought you had already removed them ^^ 😸

They are equivalent to isoImage.includeSystemBuildDependencies behemoth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see, fixed in latest commit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does includeSystemBuildDependencies mean? I would assume if you pass the toplevel, that would include all buildInputs for that store path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the .toplevel, it's already included as in the linked default config is shown.

what does includeSystemBuildDependencies mean?

https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/cd-dvd/iso-image.nix#L482-L486

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you talking about this line: https://github.com/NixOS/nixpkgs/blob/a6155fc19e31fe0a49b75409d02a2d8b6bb97aa0/nixos/modules/installer/cd-dvd/iso-image.nix#L630?

That would get the toplevel of the isoConfig. Which won't include the profiles that have been disabled. And the goal is to include the profile's closure, just without including them in the config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just realized that my self and renamed to fullHostConfig and left a comment. That makes the difference clearer.

];
environment.systemPackages = hostConfig.environment.systemPackages;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the rationale (use case) for this again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well by including the hostConfig toplevel, all packages are now in the nix store. So I thought as convenience we could just forward to the environment.

Copy link
Contributor

@blaggacao blaggacao Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure if we can include the toplevel derivation, it takes a lot more time to produce the squashfs, now. Well, maybe we can leave it, but open an issue in search for a better solution (eg. w/o compression?).

So we might just leave this line, as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently attempting to build and I see what you mean. If this PR increases the time to build or the iso size by a lot, it might not be the best solution.

Perhaps we could just forward the systemPackages and not include the toplevel build. Or we could add a separate build that has the entire toplevel. So one for network install and one that includes everything making an offline install possible.


# confilcts with networking.wireless which might be slightly
# more useful on a stick
networking.networkmanager.enable = lib.mkForce false;
Expand Down Expand Up @@ -58,7 +66,7 @@ lib.nixosSystem (args // {
];
})).config;
in
modules ++ [{
moduleList ++ [{
system.build = {
iso = isoConfig.system.build.isoImage;
};
Expand Down