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, #chpasswd_command, #configurator_class, distribution, #initialize, #log_type, #network, #passwd, #pre_start, #reload_network_manager_dns, #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



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 81

def bin_path(_opts)
  raise "#{ct.ident} not running" unless ct.running?

  ContainerControl::Commands::WithMountns.run!(
    ct,
    ns_pid: ct.init_pid,
    block: proc do
      File.realpath('/nix/var/nix/profiles/system/sw/bin')
    rescue Errno::ENOENT
      '/bin'
    end
  )
end

#dns_resolvers(_opts = {}) ⇒ Object



73
74
75
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 73

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
58
59
# 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],
    mnt_ns: opts[:mnt_ns],
    chroot: opts[:rootfs_mount],
    root_dir: opts[:root_dir],
    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



61
62
63
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 61

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

#unset_dns_resolvers(_opts = {}) ⇒ Object



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

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

#unset_etc_hosts(_opts = {}) ⇒ Object



69
70
71
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 69

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

#update_etc_hosts(_opts = {}) ⇒ Object



65
66
67
# File 'lib/osctld/dist_config/distributions/nixos.rb', line 65

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