Skip to content

Commit 7584072

Browse files
committed
new way to build rootfs, should correctly merge directories now. Also, garbage collection prevention now working
1 parent 1457070 commit 7584072

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "anysnake2"
3-
version = "0.5.3"
3+
version = "0.6.0"
44
authors = ["Florian Finkernagel <[email protected]>"]
55
edition = "2018"
66

examples/dev/anysnake2.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ packages = [ # use https://search.nixos.org/packages to search
2727
"ripgrep",
2828
"strace",
2929
"which",
30+
"mercurial", # good test case for breaking site-packages
3031
] # optional
3132

3233
[outside_nixpkgs]
@@ -48,12 +49,19 @@ ecosystem_date="2021-10-11" # you get whatever packages the solver would have pr
4849

4950
[python.packages]
5051
# you can use version specifiers from https://www.python.org/dev/peps/pep-0440/#id53
51-
scipy=""
52-
pypipegraph2=">2.1"
53-
mbf_r = "editable/code" # see [clones.code] below
54-
mbf_sampledata = "editable/code"
55-
dppd = "editable/code"
56-
dppd_plotnine = "editable/code"
52+
#scipy=""
53+
#pypipegraph2=">2.1"
54+
##mbf_r = "editable/code" # see [clones.code] below
55+
#mbf_sampledata = "editable/code"
56+
#dppd = "editable/code"
57+
#dppd_plotnine = "editable/code"
58+
#mercurial="5.8"
59+
60+
pypipegraph2=""
61+
jupyter=""
62+
requests=""
63+
dppd_plotnine=""
64+
5765
# pandas="<1.0"
5866

5967
[clones.code] # target directory

src/flake_template.nix

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
in {
3030
script_file = script_file;
3131

32-
derivation = pkgs.runCommand name {
33-
} ''
32+
derivation = pkgs.runCommand name { } ''
3433
set -o pipefail
3534
shopt -s nullglob
3635
mkdir -p $out/rootfs/usr/lib
@@ -50,18 +49,26 @@
5049
done
5150
5251
# the later entries shadow the earlier ones. and the python environment beats everything else
52+
set -x
53+
# python packages beat the others# python packages beat the others..
54+
#${pkgs.xorg.lndir}/bin/lndir $mypy2/bin $out/rootfs/bin/ || true
5355
for path in $(tac ${script_file});
5456
do
55-
ln -s $path/bin/* $out/rootfs/bin/ || true
56-
ln -s $path/etc/* $out/rootfs/etc || true
57-
ln -s $path/lib/* $out/rootfs/usr/lib/ || true
58-
ln -s $path/share/* $out/rootfs/usr/share/ || true
57+
${pkgs.xorg.lndir}/bin/lndir $path/bin $out/rootfs/bin/ || true
58+
${pkgs.xorg.lndir}/bin/lndir $path/etc $out/rootfs/etc || true
59+
${pkgs.xorg.lndir}/bin/lndir $path/lib $out/rootfs/usr/lib/ || true
60+
${pkgs.xorg.lndir}/bin/lndir $path/share $out/rootfs/usr/share/ || true
61+
# fi
5962
done
6063
ln -s $out/rootfs/bin $out/rootfs/usr/bin
64+
#mkdir $out/python_env
65+
#ln -s $mypy2/* $out/python_env
6166
6267
mkdir -p $out/rootfs/etc/profile.d
6368
echo "export SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt" >>$out/rootfs/etc/bashrc # singularity pulls that from the env otherwise apperantly
6469
echo "export SSL_CERT_DIR=/etc/ssl/certs" >>$out/rootfs/etc/bashrc # singularity pulls that from the env otherwise apperantly
70+
#echo "export PATH=/python_env/bin:/bin:/usr/bin/" >>$out/rootfs/etc/bashrc
71+
#echo "export PYTHONPATH=$PYTHONPATH:/python_env/lib/python%PYTHON_MAJOR_DOT_MINOR%/site-packages" >>$out/rootfs/etc/bashrc
6572
6673
'';
6774
};
@@ -146,14 +153,15 @@
146153
defaultPackage = buildSymlinkImage _args;
147154
sif_image = buildSingularityImage _args;
148155
devShell = pkgs.stdenv.mkDerivation {
149-
name="anysnake2-devshell";
150-
shellHook = ''
151-
export PATH=${defaultPackage}/rootfs/bin:$PATH;
152-
'';
153-
nativeBuildInputs = with pkgs; [
154-
#%DEVSHELL_INPUTS%
155-
];
156-
};
156+
name = "anysnake2-devshell";
157+
shellHook = ''
158+
export PATH=${defaultPackage}/rootfs/bin:$PATH;
159+
'';
160+
nativeBuildInputs = with pkgs;
161+
[
162+
#%DEVSHELL_INPUTS%
163+
];
164+
};
157165
});
158166

159167
}

src/flake_writer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub fn write_flake(
125125
bail!(
126126
format!("Python version must be x.y (not x.y.z ,z is given by nixpkgs version). Was '{}'", &python.version));
127127
}
128+
let python_major_dot_minor = &python.version;
128129
let python_major_minor = format!("python{}", python.version.replace(".", ""));
129130

130131
let mut out_python_packages = extract_non_editable_python_packages(python_packages)?;
@@ -155,6 +156,7 @@ pub fn write_flake(
155156
flake_contents
156157
//.replace("%PYTHON_MAJOR_MINOR%", &python_major_minor)
157158
.replace("%PYTHON_PACKAGES%", &out_python_packages)
159+
.replace("%PYTHON_MAJOR_DOT_MINOR%", &python_major_dot_minor)
158160
.replace("%PYPI_DEPS_DB_REV%", &pypi_debs_db_rev)
159161
.replace(
160162
"\"%MACHNIX%\"",

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,10 +1053,11 @@ fn symlink_for_sure<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> Res
10531053
&original.as_ref(),
10541054
&link.as_ref()
10551055
);
1056-
if link.as_ref().exists() {
1056+
if std::fs::read_link(&link).is_ok(){ // ie it existed...
1057+
debug!("removing old symlink {:?}", &link.as_ref());
10571058
std::fs::remove_file(&link)?;
10581059
}
1059-
Ok(std::os::unix::fs::symlink(&original, &link)?)
1060+
Ok(std::os::unix::fs::symlink(&original, &link).with_context(||format!("Failed to symlink {:?} to {:?}", &original.as_ref(), &link.as_ref()))?)
10601061
}
10611062

10621063
pub fn register_nix_gc_root(url: &str, flake_dir: impl AsRef<Path>) -> Result<()> {
@@ -1094,7 +1095,7 @@ pub fn register_nix_gc_root(url: &str, flake_dir: impl AsRef<Path>) -> Result<()
10941095
let j: NixFlakePrefetchOutput = serde_json::from_str(&stdout)?;
10951096
symlink_for_sure(&j.storePath, &flake_symlink_here)?;
10961097
symlink_for_sure(
1097-
&flake_symlink_here,
1098+
&gc_roots.canonicalize()?.join(&without_hash.replace("/", "_")),
10981099
&gc_per_user_base.join(&format!(
10991100
"{}_{}",
11001101
&flake_hash,
@@ -1142,7 +1143,7 @@ pub fn register_nix_gc_root(url: &str, flake_dir: impl AsRef<Path>) -> Result<()
11421143
})?;
11431144
symlink_for_sure(store_path, &out_dir)?;
11441145
symlink_for_sure(
1145-
&out_dir,
1146+
&out_dir.parent().context("parent not found")?.canonicalize()?.join(&url.replace("/", "_")),
11461147
&gc_per_user_base.join(&format!("{}_{}", &flake_hash, &url.replace("/", "_"))),
11471148
)?;
11481149
}

0 commit comments

Comments
 (0)