Repository navigation
Expand file tree
/
Copy pathnix.elv
More file actions
163 lines (140 loc) · 4.39 KB
/
Copy pathnix.elv
File metadata and controls
163 lines (140 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Copyright (c) 2019-2021, Cody Opel <cwopel@chlorm.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use github.com/chlorm/elvish-stl/env
use github.com/chlorm/elvish-stl/exec
use github.com/chlorm/elvish-stl/io
use github.com/chlorm/elvish-stl/os
use github.com/chlorm/elvish-stl/path
use github.com/chlorm/elvish-stl/re
use github.com/chlorm/elvish-stl/str
use github.com/chlorm/elvish-util-wrappers/su
# Clear environment variables in user environment polluted by makeWrapper.
fn clear-env {
env:unset 'GDK_PIXBUF_MODULE_FILE'
env:unset 'GI_TYPELIB_PATH'
env:unset 'GIO_EXTRA_MODULES'
env:unset 'GRL_PLUGIN_PATH'
env:unset 'GST_PLUGIN_SYSTEM_PATH_1_0'
env:unset 'GSETTINGS_SCHEMAS_PATH'
env:unset 'XDG_DATA_DIRS'
env:unset 'XDG_ICON_DIRS'
}
fn -user-buildenvs {
var envs = [ ]
for line [ (str:to-lines (io:read (path:home)'/.nixpkgs/config.nix')) ] {
var m = (re:find '([0-9a-zA-Z_-]+)(?:[ ]+|)=.*buildEnv)' $line)
if (!=s $m '') {
set envs = [ $@envs $m ]
}
}
put $envs
}
fn find-nixconfig-closures {
var closures = [ ]
for i [ (-user-buildenvs) ] {
set closures = [
$@closures
(exec:cmd-out 'find' '/nix/store' '-name' '*'$i'*')
]
}
put $closures
}
fn find-nixos-closures {
put [ (exec:cmd-out 'find' '/nix/store' '-name' '*'(hostname)'*') ]
}
fn build-iso {|platform|
var nixpkgs = (exec:cmd-out 'nix-instantiate' '--eval' '-E' '<nixpkgs>')
e:nix-build $nixpkgs'/nixos/release.nix' ^
'-A' 'iso_minimal_new_kernel.'$platform
}
fn copy-closures {|target @closures|
for i $closures {
e:nix-copy-closure '--to' 'root@'$target $i
}
}
fn install {|@attrs|
for i $attrs {
e:nix-env '-iA' $i '-f' '<nixpkgs>'
}
}
fn rebuild-envs {|@args|
var exceptions = [ ]
for i [ (-user-buildenvs) ] {
try {
e:nix-env '-iA' $i '-f' '<nixpkgs>' $@args
} catch e {
set exceptions = [ $@exceptions $e ]
continue
}
}
for i $exceptions {
echo $i
}
}
fn remove-references {|path|
if (not (os:is-dir $path)) {
var err = 'Specified path does not exist: '$path
fail $err
}
for i [ (exec:cmd-out 'find' '-L' $path '-xtype' 1 '-name' 'result*') ] {
if (and (os:is-file $path'/.git/config') ^
(re:match 'triton' (io:read $path'/.git/config'))) {
os:remove $path
}
}
}
fn rebuild-system {|target @args|
su:do 'nixos-rebuild' $target $@args ^
'-I' 'nixpkgs='(e:nix-instantiate '--eval' '-E' '<nixpkgs>')
}
fn search {|@attrs|
for i $attrs {
e:nix-env '-qaP' '.*'$i'.*' '-f' '<nixpkgs>'
}
}
# Set up the per-user profile.
fn user-profile-init {
use github.com/chlorm/elvish-stl/env
var home = (path:home)
var nixProfile = $home'/.nix-profile'
# Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs>
# paths work when the user has fetched the Nixpkgs channel.
env:append 'NIXPATH' $home'/.nix-defexpr/channels'
# Set up environment.
env:set 'NIX_PROFILES' '/nix/var/nix/profiles/default '$home'/.nix-profile'
# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
var hasCaCerts = $false
var caCertsPaths = [
# NixOS, Ubuntu, Debian, Gentoo, Arch
'/etc/ssl/certs/ca-certificates.crt'
# openSUSE Tumbleweed
'/etc/ssl/ca-bundle.pem'
# Fedora, CentOS
'/etc/pki/tls/certs/ca-bundle.crt'
# fallback to cacert in Nix profile
'/etc/ssl/certs/ca-bundle.crt'
]
for p $caCertsPaths {
if (os:exists $p) {
env:set 'NIX_SSL_CERT_FILE' $p
set hasCaCerts = $true
break
}
}
if (not $hasCaCerts) {
fail 'ca certs not found'
}
env:prepend 'MANPATH' $nixProfile'/share/man'
env:prepend 'PATH' $nixProfile'/bin'
}