* 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
This commit is contained in:
zimbatm 2019-01-31 22:06:29 +00:00 committed by Lassulus
parent 65ca979a13
commit 0cce7924f1
16 changed files with 43 additions and 43 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
*.qcow2
result
result-*

6
.travis.yml Normal file
View File

@ -0,0 +1,6 @@
language: nix
sudo: false
script:
- nix-build

View File

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

View File

@ -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:
```

View File

@ -3,7 +3,7 @@
with pkgs;
stdenv.mkDerivation {
name = "nixos-generators";
src = ./.;
src = lib.cleanSource ./.;
nativeBuildInputs = [ makeWrapper ];
installFlags = [ "PREFIX=$(out)" ];
postFixup = ''

View File

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

View File

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

View File

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: let
{ config, pkgs, lib, modulesPath, ... }: let
clever-tests = builtins.fetchGit {
url = https://github.com/cleverca22/nix-tests;
@ -6,14 +6,14 @@
};
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"; }
];

View File

@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/maintainers/scripts/openstack/nova-image.nix>
"${toString modulesPath}/../maintainers/scripts/openstack/nova-image.nix"
];
formatAttr = "novaImage";

View File

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, modulesPath, ... }:
{
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
@ -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";

View File

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, modulesPath, ... }:
{
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
@ -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";

View File

@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/virtualbox-image.nix>
"${toString modulesPath}/virtualisation/virtualbox-image.nix"
];
formatAttr = "virtualBoxOVA";

View File

@ -1,7 +1,7 @@
{ ... }:
{ modulesPath, ... }:
{
imports = [
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
"${toString modulesPath}/virtualisation/qemu-vm.nix"
];
virtualisation.qemu.networkingOptions = [

View File

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

View File

@ -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
@ -18,7 +17,7 @@ import "${toString nixpkgs}/nixos/lib/eval-config.nix" {
inherit system;
modules = [
module
formatConfig
format-config
configuration
];
}