python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / tools / virtualization / cloud-init / 0001-add-nixos-support.patch
blob81ff2ef73ce83af8fd0daefeb13696fc247a84cc
1 diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
2 index 4a468cf8..c60c899b 100644
3 --- a/cloudinit/distros/__init__.py
4 +++ b/cloudinit/distros/__init__.py
5 @@ -55,6 +55,7 @@ OSFAMILIES = {
6 "virtuozzo",
7 ],
8 "suse": ["opensuse", "sles"],
9 + "nixos": ["nixos"],
12 LOG = logging.getLogger(__name__)
13 diff --git a/cloudinit/distros/nixos.py b/cloudinit/distros/nixos.py
14 new file mode 100644
15 index 00000000..d53d2a61
16 --- /dev/null
17 +++ b/cloudinit/distros/nixos.py
18 @@ -0,0 +1,103 @@
19 +# vi: ts=4 expandtab
21 +# Copyright (C) 2012 Canonical Ltd.
22 +# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
23 +# Copyright (C) 2012 Yahoo! Inc.
25 +# Author: Scott Moser <scott.moser@canonical.com>
26 +# Author: Juerg Haefliger <juerg.haefliger@hp.com>
27 +# Author: Joshua Harlow <harlowja@yahoo-inc.com>
29 +# This program is free software: you can redistribute it and/or modify
30 +# it under the terms of the GNU General Public License version 3, as
31 +# published by the Free Software Foundation.
33 +# This program is distributed in the hope that it will be useful,
34 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
35 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 +# GNU General Public License for more details.
38 +# You should have received a copy of the GNU General Public License
39 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
41 +import os
43 +from cloudinit import distros
44 +from cloudinit import helpers
45 +from cloudinit import log as logging
46 +from cloudinit import util
47 +from cloudinit import atomic_helper
49 +from cloudinit.distros.parsers.hostname import HostnameConf
51 +LOG = logging.getLogger(__name__)
53 +class Distro(distros.Distro):
55 + def __init__(self, name, cfg, paths):
56 + distros.Distro.__init__(self, name, cfg, paths)
57 + # This will be used to restrict certain
58 + # calls from repeatly happening (when they
59 + # should only happen say once per instance...)
60 + self._runner = helpers.Runners(paths)
61 + self.usr_lib_exec = os.path.join(os.path.dirname(__file__),
62 + "../../../../../libexec")
63 + self.osfamily = 'nixos'
65 + def _select_hostname(self, hostname, fqdn):
66 + # Prefer the short hostname over the long
67 + # fully qualified domain name
68 + if not hostname:
69 + return fqdn
70 + return hostname
72 + def _write_hostname(self, your_hostname, out_fn):
73 + conf = None
74 + try:
75 + # Try to update the previous one
76 + # so lets see if we can read it first.
77 + conf = self._read_hostname_conf(out_fn)
78 + except IOError:
79 + pass
80 + if not conf:
81 + conf = HostnameConf('')
82 + conf.set_hostname(your_hostname)
83 + atomic_helper.write_file(out_fn, str(conf).encode("utf-8"))
85 + def _read_system_hostname(self):
86 + sys_hostname = self._read_hostname(self.hostname_conf_fn)
87 + return (self.hostname_conf_fn, sys_hostname)
89 + def _read_hostname_conf(self, filename):
90 + conf = HostnameConf(util.load_file(filename))
91 + conf.parse()
92 + return conf
94 + def _read_hostname(self, filename, default=None):
95 + hostname = None
96 + try:
97 + conf = self._read_hostname_conf(filename)
98 + hostname = conf.hostname
99 + except IOError:
100 + pass
101 + if not hostname:
102 + return default
103 + return hostname
105 + def _write_network(self, settings):
106 + raise NotImplementedError()
108 + def apply_locale(self, locale, out_fn=None):
109 + raise NotImplementedError()
111 + def install_packages(self, pkglist):
112 + raise NotImplementedError()
114 + def package_command(self, command, args=None, pkgs=None):
115 + raise NotImplementedError()
117 + def set_timezone(self, tz):
118 + raise NotImplementedError()
120 + def update_package_sources(self):
121 + raise NotImplementedError()