mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
Compare commits
5
Commits
v1.4.0
..
images-doc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31787cd754 | ||
|
|
714768a174 | ||
|
|
d389901567 | ||
|
|
72818e54ec | ||
|
|
a2009bc2b4 |
No files matched your search
+55
-3
@@ -51,12 +51,49 @@ generate disk images:
|
||||
|
||||
### Generating the `.raw` VM Image
|
||||
|
||||
1. **Build the disko image script:** Replace `mySystem` in the command below with your
|
||||
1. **Create a NixOS configuration that includes the disko and the disk configuration of your choice**
|
||||
|
||||
In the this example we create a flake containing a nixos configuration for `myhost`.
|
||||
|
||||
```nix
|
||||
# save this as flake.nix
|
||||
{
|
||||
description = "A disko images example";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
disko.url = "github:nix-community/disko";
|
||||
disko.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, disko, nixpkgs }: {
|
||||
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
# You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
|
||||
./simple-efi.nix
|
||||
disko.nixosModules.disko
|
||||
({ config, ... }: {
|
||||
# shut up state version warning
|
||||
system.stateVersion = config.system.nixos.version;
|
||||
# Adjust this to your liking.
|
||||
# WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
|
||||
disko.devices.disk.vdb.imageSize = "10G";
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
2. **Build the disko image script:** Replace `myhost` in the command below with your
|
||||
specific system configuration name:
|
||||
|
||||
```console
|
||||
nix build .#nixosConfigurations.mySystem.config.system.build.diskoImagesScript
|
||||
nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript
|
||||
```
|
||||
2. **Execute the result file:** Execute the generated result file. Running
|
||||
|
||||
3. **Execute the disko image script:** Execute the generated disko image script. Running
|
||||
`./result --help` will output the available options:
|
||||
|
||||
```console
|
||||
@@ -81,6 +118,21 @@ generate disk images:
|
||||
There is no check if the specified path is actually a disk so you can also write to another file
|
||||
```
|
||||
|
||||
An example run may look like this:
|
||||
|
||||
```
|
||||
sudo ./result --build-memory 2048
|
||||
```
|
||||
|
||||
The script will generate the actual image outside of the nix store in the current working directory.
|
||||
The create image names depend on the names used in `disko.disks` attrset in the NixOS configuration.
|
||||
In our code example it will produce the following image:
|
||||
|
||||
```
|
||||
$ ls -la vdb.raw
|
||||
.rw-r--r-- root root 10 GB 2 minutes ago vdb.raw
|
||||
```
|
||||
|
||||
### Additional Configuration
|
||||
|
||||
- For virtual drive use, define the image size in your Disko configuration:
|
||||
|
||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1709386671,
|
||||
"narHash": "sha256-VPqfBnIJ+cfa78pd4Y5Cr6sOWVW8GYHRVucxJGmRf8Q=",
|
||||
"lastModified": 1710097495,
|
||||
"narHash": "sha256-B7Ea7q7hU7SE8wOPJ9oXEBjvB89yl2csaLjf5v/7jr8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fa9a51752f1b5de583ad5213eb621be071806663",
|
||||
"rev": "d40e866b1f98698d454dad8f592fe7616ff705a4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -28,7 +28,10 @@
|
||||
in
|
||||
{
|
||||
disko = pkgs.callPackage ./package.nix { };
|
||||
disko-install = pkgs.callPackage ./disko-install.nix { };
|
||||
# alias to make `nix run` more convenient
|
||||
disko-install = self.packages.${system}.disko.overrideAttrs (old: {
|
||||
name = "disko-install";
|
||||
});
|
||||
default = self.packages.${system}.disko;
|
||||
} // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64) {
|
||||
disko-doc = pkgs.callPackage ./doc.nix { };
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ let
|
||||
machine.succeed("echo -n 'additionalSecret' > /tmp/additionalSecret.key")
|
||||
machine.succeed("echo -n 'secretsecret' > /tmp/secret.key")
|
||||
${lib.optionalString (testMode == "direct") ''
|
||||
# running direct mode
|
||||
# running direct mode
|
||||
machine.succeed("${tsp-format}")
|
||||
machine.succeed("${tsp-mount}")
|
||||
machine.succeed("${tsp-mount}") # verify that the command is idempotent
|
||||
|
||||
+13
-10
@@ -1,6 +1,6 @@
|
||||
{ stdenvNoCC, makeWrapper, lib, path }:
|
||||
{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils }:
|
||||
|
||||
stdenvNoCC.mkDerivation rec {
|
||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
name = "disko";
|
||||
src = ./.;
|
||||
nativeBuildInputs = [
|
||||
@@ -8,13 +8,15 @@ stdenvNoCC.mkDerivation rec {
|
||||
];
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/disko
|
||||
cp -r cli.nix default.nix disk-deactivate lib $out/share/disko
|
||||
sed \
|
||||
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
|
||||
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
|
||||
disko > $out/bin/disko
|
||||
chmod 755 $out/bin/disko
|
||||
wrapProgram $out/bin/disko --prefix NIX_PATH : "nixpkgs=${path}"
|
||||
cp -r install-cli.nix cli.nix default.nix disk-deactivate lib $out/share/disko
|
||||
|
||||
for i in disko disko-install; do
|
||||
sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i"
|
||||
chmod 755 "$out/bin/$i"
|
||||
wrapProgram "$out/bin/$i" \
|
||||
--prefix PATH : ${lib.makeBinPath [ nix coreutils ]} \
|
||||
--prefix NIX_PATH : "nixpkgs=${path}"
|
||||
done
|
||||
'';
|
||||
meta = with lib; {
|
||||
description = "Format disks with nix-config";
|
||||
@@ -22,5 +24,6 @@ stdenvNoCC.mkDerivation rec {
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ lassulus ];
|
||||
platforms = platforms.linux;
|
||||
mainProgram = finalAttrs.name;
|
||||
};
|
||||
}
|
||||
})
|
||||
@@ -1,11 +1,10 @@
|
||||
{ pkgs ? import <nixpkgs> { }, self }:
|
||||
let
|
||||
disko-install = pkgs.callPackage ../../disko-install.nix { };
|
||||
toplevel = self.nixosConfigurations.testmachine.config.system.build.toplevel;
|
||||
|
||||
dependencies = [
|
||||
pkgs.stdenv.drvPath
|
||||
toplevel
|
||||
self.nixosConfigurations.testmachine.config.system.build.toplevel
|
||||
self.nixosConfigurations.testmachine.config.system.build.diskoScript
|
||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||
|
||||
|
||||
Reference in new issue
Block a user