Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dotfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
dotfiles
Commits
41c3a425
Commit
41c3a425
authored
5 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement 'deploy <machine> iso'
parent
aa07be6e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/deploy
+16
-2
16 additions, 2 deletions
bin/deploy
nixos/configuration.nix
+8
-8
8 additions, 8 deletions
nixos/configuration.nix
nixos/machine-manager.nix
+30
-2
30 additions, 2 deletions
nixos/machine-manager.nix
with
54 additions
and
12 deletions
bin/deploy
+
16
−
2
View file @
41c3a425
...
...
@@ -9,6 +9,7 @@ readonly cmdname=$(basename $0)
nixos_system_file
=
$MACHINES_PATH
/nixos.nix
nixos_iso_file
=
$MACHINES_PATH
/nixos_iso.nix
# This script cannot run without the nixos configuration entry point
if
[[
!
-f
"
$nixos_system_file
"
]]
...
...
@@ -21,7 +22,7 @@ fi
source
$DOTFILES_PATH
/bin/lib/util.zsh
usage
()
{
print
"Usage:
$cmdname
[--via via_hostname] <hostname> [switch|boot|reboot|test|dry-activate|build]"
>
&2
print
"Usage:
$cmdname
[--via via_hostname] <hostname> [switch|boot|reboot|test|dry-activate|build
|iso
]"
>
&2
}
positional
=()
...
...
@@ -77,7 +78,7 @@ then
operation
=
"boot"
set_profile
=
1
reboot
=
1
elif
[[
"
$operation
"
=
"test"
||
"
$operation
"
=
"dry-activate"
||
"
$operation
"
=
"build"
]]
elif
[[
"
$operation
"
=
"test"
||
"
$operation
"
=
"dry-activate"
||
"
$operation
"
=
"build"
||
"
$operation
"
=
"iso"
]]
then
# pass
else
...
...
@@ -97,6 +98,19 @@ fi
readonly
local_temp_dir
=
$(
mktemp
--tmpdir
--directory
phoenix-deploy.XXXXXXXXXX
)
trap
"rm -rf
$local_temp_dir
"
EXIT INT HUP TERM
if
[[
"
$operation
"
=
"iso"
]]
then
print_info
"Building iso image"
nix build
--file
"
$MACHINES_PATH
"
--out-link
"
$local_temp_dir
/nixos-iso-
$hostname
"
"nixosIsoDerivations.
$hostname
"
readonly
nixos_iso_path
=
$(
realpath
"
$local_temp_dir
/nixos-iso-
$hostname
"
)
print_info
"Iso generated"
print
$nixos_iso_path
exit
0
fi
print_info
"Building target system configuration"
nix build
--file
"
$nixos_system_file
"
--argstr
hostname
"
$hostname
"
--out-link
"
$local_temp_dir
/nixos-config-
$hostname
"
readonly
nixos_config_path
=
$(
realpath
"
$local_temp_dir
/nixos-config-
$hostname
"
)
...
...
This diff is collapsed.
Click to expand it.
nixos/configuration.nix
+
8
−
8
View file @
41c3a425
# This is the entry point for my NixOS configuration.
{
name
,
path
,
channel
}:
{
name
,
path
,
channel
,
isIso
}:
{
lib
,
config
,
pkgs
,
...
}:
let
...
...
@@ -7,12 +7,11 @@ let
dotfilesConfig
=
import
(
path
+
"/dotfiles.nix"
);
layerImports
=
map
(
l
:
./layers
+
"/
${
l
}
.nix"
)
dotfilesConfig
.
layers
;
in
{
(
{
imports
=
[
./modules
(
path
+
"/configuration.nix"
)
(
path
+
"/hardware-configuration.nix"
)
]
++
layerImports
;
]
++
layerImports
++
(
lib
.
lists
.
optional
(
!
isIso
)
(
path
+
"/hardware-configuration.nix"
));
nixpkgs
.
config
=
{
packageOverrides
=
(
import
./pkgs
)
{
inherit
lib
config
;
}
;
...
...
@@ -21,19 +20,20 @@ in
# Pin channel in nix path
nix
.
nixPath
=
[
"nixpkgs=
${
channel
}
"
];
# Default hostname ist machine directory name
networking
.
hostName
=
lib
.
mkDefault
name
;
}
//
(
lib
.
attrsets
.
optionalAttrs
(
!
isIso
)
{
# Bootloader
boot
.
loader
.
systemd-boot
.
enable
=
(
installResult
.
bootloader
==
"efi"
);
boot
.
loader
.
efi
.
canTouchEfiVariables
=
(
installResult
.
bootloader
==
"efi"
);
boot
.
loader
.
grub
.
enable
=
(
installResult
.
bootloader
==
"bios"
);
boot
.
loader
.
grub
.
device
=
installResult
.
installedBlockDevice
;
# Default hostname ist machine directory name
networking
.
hostName
=
lib
.
mkDefault
name
;
boot
.
initrd
.
luks
.
devices
=
if
installResult
.
luks
then
{
cryptvol
=
{
device
=
"/dev/disk/by-uuid/"
+
installResult
.
luksPartitionUuid
;
allowDiscards
=
true
;
};
}
else
{};
}
}
))
This diff is collapsed.
Click to expand it.
nixos/machine-manager.nix
+
30
−
2
View file @
41c3a425
...
...
@@ -31,9 +31,9 @@ let
machinesDirContents
=
readDir
machinesDir
;
machineNames
=
filter
(
p
:
machinesDirContents
.
${
p
}
==
"directory"
)
(
attrNames
machinesDirContents
);
withMachines
=
lambda
:
listToAttrs
(
map
(
m
:
{
name
=
m
;
value
=
lambda
{
name
=
m
;
path
=
(
machinesDir
+
"/
${
m
}
"
);
};
})
machineNames
);
mkMachineConfig
=
{
name
,
path
}:
(
mkMachineConfig
=
{
name
,
path
,
isIso
?
false
}:
(
import
./configuration.nix
{
inherit
name
path
;
inherit
name
path
isIso
;
channel
=
machineChannels
.
${
name
};
}
);
...
...
@@ -48,10 +48,38 @@ let
};
in
nixos
.
system
;
mkNixosIsoDerivation
=
{
name
,
path
}:
let
channel
=
machineChannels
.
${
name
};
configuration
=
{
config
,
...
}:
{
imports
=
[
(
mkMachineConfig
{
inherit
name
path
;
isIso
=
true
;
})
<
nixpkgs/nixos/modules/installer/cd-dvd/iso-image.nix
>
<
nixpkgs/nixos/modules/profiles/all-hardware.nix
>
<
nixpkgs/nixos/modules/profiles/base.nix
>
];
isoImage
.
isoName
=
"
${
config
.
isoImage
.
isoBaseName
}
-
${
config
.
system
.
nixos
.
label
}
-isohost-
${
name
}
.iso"
;
isoImage
.
volumeID
=
substring
0
11
"NIXOS_ISO"
;
isoImage
.
makeEfiBootable
=
true
;
isoImage
.
makeUsbBootable
=
true
;
boot
.
loader
.
grub
.
memtest86
.
enable
=
true
;
};
# Importing <nixpkgs/nixos> results in a nixos system closure
nixos
=
import
"
${
channel
}
/nixos"
{
system
=
"x86_64-linux"
;
inherit
configuration
;
};
in
nixos
.
config
.
system
.
build
.
isoImage
;
in
{
configurations
=
withMachines
mkMachineConfig
;
nixosSystemDerivations
=
withMachines
mkNixosSystemDerivation
;
nixosIsoDerivations
=
withMachines
mkNixosIsoDerivation
;
machineTemplates
=
withMachines
({
name
,
path
}:
import
(
path
+
/template.nix
));
channels
=
machineChannels
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment