Skip to content

Commit

Permalink
Cleanup (nix-community#17)
Browse files Browse the repository at this point in the history
* rename eval-format.nix to nixos-generate.nix

Make it clear that it's meant to be used by the nixos-generate script

* rename config.nix to configuration.nix

Bring the name closer to /etc/nixos/configuration.nix

* fix the NIXOS_CONFIG

this is the env name that nixos-rebuild uses

* use -I to load the configuration and format

This has a nice side-effect of allowing URLs as configuration

* add Travis CI

* cleanSource

* gitignore nix result files

* use modulesPath everywhere

this makes sure that the passed pkgs in nixos-generate.nix is the same
one we use to load these other modules

* use toString to avoid evaluation error
  • Loading branch information
zimbatm authored and Lassulus committed Jan 31, 2019
1 parent 65ca979 commit 0cce792
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.qcow2
result
result-*
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: nix

sudo: false

script:
- nix-build
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ install:
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
nixos-generate > $(PREFIX)/bin/nixos-generate
chmod 755 $(PREFIX)/bin/nixos-generate
cp -r formats config.nix eval-format.nix $(SHARE)
cp -r formats configuration.nix nixos-generate.nix $(SHARE)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The nixos-generators project allows to take the same NixOS configuration, and
generate outputs for different target formats.

Just put your stuff into the config.nix and then call one of the image builders.
Just put your stuff into the configuration.nix and then call one of the image builders.

for example:
```
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with pkgs;
stdenv.mkDerivation {
name = "nixos-generators";
src = ./.;
src = lib.cleanSource ./.;
nativeBuildInputs = [ makeWrapper ];
installFlags = [ "PREFIX=$(out)" ];
postFixup = ''
Expand Down
4 changes: 2 additions & 2 deletions formats/install-iso.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib , ... }:
{ config, lib, modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-base.nix>
"${toString modulesPath}/installer/cd-dvd/installation-cd-base.nix"
];

# for installer
Expand Down
4 changes: 2 additions & 2 deletions formats/iso.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, ... }:
{ config, modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/iso-image.nix>
"${toString modulesPath}/installer/cd-dvd/iso-image.nix"
];

# EFI booting
Expand Down
6 changes: 3 additions & 3 deletions formats/kexec.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{ config, pkgs, lib, ... }: let
{ config, pkgs, lib, modulesPath, ... }: let

clever-tests = builtins.fetchGit {
url = https://github.com/cleverca22/nix-tests;
rev = "4761ec62c4056f2b1df4d468a1e129b808734221"; #master on 2018-05-20
};
in {
imports = [
<nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix>
"${toString modulesPath}/installer/netboot/netboot-minimal.nix"
"${clever-tests}/kexec/autoreboot.nix"
"${clever-tests}/kexec/kexec.nix"
"${clever-tests}/kexec/justdoit.nix"
];

system.build = rec {
kexec_tarball = pkgs.callPackage <nixpkgs/nixos/lib/make-system-tarball.nix> {
kexec_tarball = pkgs.callPackage "${toString modulesPath}/../lib/make-system-tarball.nix" {
storeContents = [
{ object = config.system.build.kexec_script; symlink = "/kexec_nixos"; }
];
Expand Down
4 changes: 2 additions & 2 deletions formats/openstack.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/maintainers/scripts/openstack/nova-image.nix>
"${toString modulesPath}/../maintainers/scripts/openstack/nova-image.nix"
];

formatAttr = "novaImage";
Expand Down
4 changes: 2 additions & 2 deletions formats/qcow.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, modulesPath, ... }:
{
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
Expand All @@ -11,7 +11,7 @@
boot.loader.timeout = 0;


system.build.qcow = import <nixpkgs/nixos/lib/make-disk-image.nix> {
system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" {
inherit lib config pkgs;
diskSize = 8192;
format = "qcow2";
Expand Down
4 changes: 2 additions & 2 deletions formats/raw.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, modulesPath, ... }:
{
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
Expand All @@ -11,7 +11,7 @@
boot.loader.timeout = 0;


system.build.raw = import <nixpkgs/nixos/lib/make-disk-image.nix> {
system.build.raw = import "${toString modulesPath}/../lib/make-disk-image.nix" {
inherit lib config pkgs;
diskSize = 2048;
format = "raw";
Expand Down
4 changes: 2 additions & 2 deletions formats/virtualbox.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/virtualbox-image.nix>
"${toString modulesPath}/virtualisation/virtualbox-image.nix"
];

formatAttr = "virtualBoxOVA";
Expand Down
4 changes: 2 additions & 2 deletions formats/vm.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
"${toString modulesPath}/virtualisation/qemu-vm.nix"
];

virtualisation.qemu.networkingOptions = [
Expand Down
31 changes: 12 additions & 19 deletions nixos-generate
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -euo pipefail
## Configuration

libexec_dir="${0%/*}"
configuration_path=${NIX_CONFIG:-$libexec_dir/config.nix}
configuration=${NIXOS_CONFIG:-$libexec_dir/configuration.nix}
format=
format_dir=$libexec_dir/formats
format_path=
target_system=
run=

Expand All @@ -21,7 +21,7 @@ Options:

* --help: shows this help
* -c, --configuration PATH:
select the nixos configuration to build. Default: $configuration_path
select the nixos configuration to build. Default: $configuration
* -f, --format NAME: select one of the pre-determined formats
* --format-path PATH: pass a custom format
* --list: list the available built-in formats
Expand All @@ -47,15 +47,15 @@ abort() {
while [[ $# -gt 0 ]]; do
case "$1" in
-c | --configuration)
configuration_path=$2
configuration=$2
shift
;;
-f | --format)
format_path=$format_dir/$2.nix
format=$format_dir/$2.nix
shift
;;
--format-path)
format_path=$2
format=$2
shift
;;
--help)
Expand All @@ -69,8 +69,8 @@ while [[ $# -gt 0 ]]; do
--run)
run=1
# default to the VM format
if [[ -z $format_path ]]; then
format_path=$format_dir/vm.nix
if [[ -z $format ]]; then
format=$format_dir/vm.nix
fi
;;
--system)
Expand All @@ -84,21 +84,14 @@ while [[ $# -gt 0 ]]; do
shift
done

if [[ -z $format_path ]]; then
if [[ -z $format ]]; then
abort "missing format. use --help for more details"
fi

if [[ ! -e $format_path ]]; then
abort "format '$format_path' not found"
fi

configuration_path=$(realpath "$configuration_path")
format_path=$(realpath "$format_path")

args=(
"$libexec_dir/eval-format.nix"
--arg configuration "$configuration_path"
--arg formatConfig "$format_path"
"$libexec_dir/nixos-generate.nix"
-I "nixos-config=$configuration"
-I "format-config=$format"
)

if [[ -n $target_system ]]; then
Expand Down
7 changes: 3 additions & 4 deletions eval-format.nix → nixos-generate.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ nixpkgs ? <nixpkgs>
, configuration ?
import "${toString nixpkgs}/nixos/lib/from-env.nix" "NIXOS_CONFIG" <nixos-config>
, formatConfig
, configuration ? <nixos-config>
, format-config ? <format-config>
, system ? builtins.currentSystem
}:
let
Expand All @@ -18,7 +17,7 @@ import "${toString nixpkgs}/nixos/lib/eval-config.nix" {
inherit system;
modules = [
module
formatConfig
format-config
configuration
];
}

0 comments on commit 0cce792

Please sign in to comment.