micro SD card image #664
|
I'm trying to get NixOS working on my Raspberry Pi and create a custom SD card image I can boot it from. Normally you would do it like this: flake.nix: {
description = "Build image";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
outputs = { self, nixpkgs }: rec {
nixosConfigurations.rpi2 = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix"
{
nixpkgs.config.allowUnsupportedSystem = true;
nixpkgs.hostPlatform.system = "armv7l-linux";
nixpkgs.buildPlatform.system = "x86_64-linux"; #If you build on x86 other wise changes this.
# ... extra configs as above
}
];
};
images.rpi2 = nixosConfigurations.rpi2.config.system.build.sdImage;
};
}and build like this: but if I wanna reuse my Den config how can I expose the I use Den with flake-file and flake-parts if it matters |
Replies: 2 comments 10 replies
|
Nothing about the sd-image side changes — the installer module, The only part that differs is where you reach the result from. Den exposes the configurations under inherit (den.flake) nixosConfigurations darwinConfigurations;so the image output becomes the same expression you already have, one attribute deeper: images.rpi2 = den.flake.nixosConfigurations.rpi2.config.system.build.sdImage;and If you would rather not have that line in |
|
I've the same approach, but by using some den features. { den, lib, config, inputs, ... }:
{
den.schema.host.options = {
sdImage = lib.mkEnableOption "Set to true if you want to add sdImage to flake.images.<host>";
};
den.schema.host.includes = [
den.policies.sd-image-to-flake
];
den.policies.sd-image-to-flake = { host, ... }:
lib.optional (host.sdImage)
(den.lib.policy.resolve.to "flake" {
sdImage.name = host.name;
sdImage.package = (lib.getAttrFromPath (host.intoAttr) config.flake).config.system.build.sdImage;
});
den.schema.flake.includes = [
({ sdImage, ... }: {
flake.flake.images.${sdImage.name} = sdImage.package;
})
];
# USAGE:
den.hosts.armv7l-linux.rpi2.sdImage = true;
den.aspects.rpi2 = {
nixos.imports = [
"${inputs.nixpkgs}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix"
{
nixpkgs.config.allowUnsupportedSystem = true;
nixpkgs.buildPlatform.system = "x86_64-linux"; #If you build on x86 other wise changes this.
# ... extra configs as above
}
];
};
}There's more code now, but I think it's pretty den-able :) |
Never mind, I did it with flake-parts: