Class: OsCtld::DistConfig::Distributions::NixOS

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/dist_config/distributions/nixos.rb

Defined Under Namespace

Classes: Configurator

Instance Attribute Summary

Attributes inherited from Base

#configurator, #ct, #ctrc, #distribution, #version

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #apply_hostname, #configurator_class, distribution, #initialize, #log_type, #network, #passwd, #pre_start, #remove_netif, #rename_netif, #start, #stop, #volatile_is_systemd?, #with_rootfs

Methods included from Utils::SwitchUser

#ct_attach, #ct_syscmd

Constructor Details

This class inherits a constructor from OsCtld::DistConfig::Distributions::Base

Instance Method Details

#bin_path(_opts) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 75

def bin_path(_opts)
  with_rootfs do
    File.realpath('/nix/var/nix/profiles/system/sw/bin')
  rescue Errno::ENOENT
    '/bin'
  end
end

#dns_resolvers(_opts = {}) ⇒ Object



71
72
73
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 71

def dns_resolvers(_opts = {})
  super if ct.impermanence.nil? || ct.running?
end

#post_mount(opts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 32

def post_mount(opts)
  super
  return if ct.impermanence.nil?

  ContainerControl::Commands::WithMountns.run!(
    ct,
    ns_pid: opts[:ns_pid],
    chroot: opts[:rootfs_mount],
    block: proc do
      # If /sbin/init already exists, it means we're *not* in impermanence mode
      # right now, even if it is enabled. While in impermanence mode, we start
      # with an empty dataset. Existing /sbin/init suggest custom `osctl ct boot`
      # is active.
      next if File.exist?('/sbin/init')

      begin
        Dir.mkdir('/sbin')
      rescue Errno::EEXIST
        # pass
      end

      File.symlink('/nix/var/nix/profiles/system/init', '/sbin/init')
      true
    end
  )
end

#set_hostname(_opts = {}) ⇒ Object



59
60
61
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 59

def set_hostname(_opts = {})
  log(:warn, 'Unable to apply hostname to NixOS container')
end

#unset_etc_hosts(_opts = {}) ⇒ Object



67
68
69
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 67

def unset_etc_hosts(_opts = {})
  # not supported
end

#update_etc_hosts(_opts = {}) ⇒ Object



63
64
65
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 63

def update_etc_hosts(_opts = {})
  # not supported
end