Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help package leftwm-theme into Nix #16

Open
winston0410 opened this issue Jul 31, 2021 · 4 comments
Open

Help package leftwm-theme into Nix #16

winston0410 opened this issue Jul 31, 2021 · 4 comments

Comments

@winston0410
Copy link

Hi I am using NixOS, and I would love to see this program be packaged into Nix. This is the derivation that I am able to come up right now, yet it needs to patch to Cargo.lock and I am stuck right now.

Hope someone can help with this:

{ config, pkgs, lib, rustPlatform, fetchFromGitHub, ... }:

rustPlatform.buildRustPackage rec {
  pname = "leftwm-theme";
  version = "e6907a663ec56397ccbe4f1226ac0550ec6678f0";

  src = fetchFromGitHub {
    owner = "leftwm";
    repo = pname;
    rev = version;
    sha256 = "12x6a487qzsngr99z39902v7c7f4xkwjximmn3wmzdz8bjddw2d2";
  };

  # How to generate patch for cargo lock?
  cargoPatches = [];

  cargoSha256 = "0g6xp1dn56dfscybvrm1wmq75zi8n2lxcv81xs969a705dj5s1ml";
  meta = with lib; {
    description = "A tool to help manage themes for LeftWM";
    homepage = "https://github.com/leftwm/leftwm-theme";
    license = licenses.bsd3;
    maintainers = [];
  };
}
@mautamu
Copy link
Member

mautamu commented Sep 6, 2021

Thank you for your patience in this, what all do we need for nixos? Unfortunately I haven't played around with nix too much, but will try to help.

Why exactly do we need to patch Cargo.lock? Does this perhaps give any hints?

@water-sucks
Copy link

I was working on this myself today, and came here to see if anyone else was struggling with it. I have an (almost) working derivation, but it seems to be failing at a test where it unwraps an Err and says permission denied, which I don't believe is Nix's fault, but rather something in the source.

Here's the derivation:

{ lib, sources, rustPlatform, fetchFromGitHub, pkg-config, openssl }:

rustPlatform.buildRustPackage rec {
  pname = "leftwm-theme";
  version = "556c8d46a7b743e30ac115dcab9047faf6f962ed";
  src = fetchFromGitHub {
    owner = "leftwm";
    repo = "leftwm-theme";
    rev = "556c8d46a7b743e30ac115dcab9047faf6f962ed";
    fetchSubmodules = false;
    sha256 = "sha256-PHRZviRSFl9696mDJxJwilP3YoM8rrWuDaAwl2/jvTM=";
  };

  cargoLock = {
    lockFile = "${src}/Cargo.lock";
  };

  nativeBuildInputs = [ pkg-config ];

  buildInputs = [ openssl ];

  dontPatchELF = true;

  meta = with lib; {
    description = "Theming engine for LeftWM";
    homepage = "https://github.com/leftwm/leftwm-theme";
    license = licenses.bsd3;
    platforms = platforms.linux;
  };
}

And here's the log for building this derivation:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/lq6q3rvdj4n2rhc7smbkkhscqd3as1ih-source
source root is source
Executing cargoSetupPostUnpackHook
unpacking source archive /nix/store/qjipdbr7i4s1fkzw6bxq3samqv8ld00d-cargo-vendor-dir
Finished cargoSetupPostUnpackHook
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
Executing cargoSetupPostPatchHook
Validating consistency between /build/source//Cargo.lock and /build/cargo-vendor-dir/Cargo.lock
Finished cargoSetupPostPatchHook
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Executing cargoBuildHook
++ env CC_x86_64-unknown-linux-gnu=/nix/store/npm4g1zsj5yzygf6bq46pbi9fqhxisha-gcc-wrapper-10.3.0/bin/cc CXX_x86_64-unknown-linux-gnu=/nix/store/npm4g1zsj5yzygf6bq46pbi9fqhxisha-gcc-wrapper-10.3.0/bin/c++ CC_x86_64-unknown-linux-gnu=/nix/store/npm4g1zsj5yzygf6bq46pbi9fqhxisha-gcc-wrapper-10.3.0/bin/cc CXX_x86_64-unknown-linux-gnu=/nix/store/npm4g1zsj5yzygf6bq46pbi9fqhxisha-gcc-wrapper-10.3.0/bin/c++ cargo build -j 16 --target x86_64-unknown-linux-gnu --frozen --release
   Compiling libc v0.2.112
   Compiling autocfg v1.0.1
   Compiling pkg-config v0.3.24
   Compiling cfg-if v1.0.0
   Compiling memchr v2.4.1
   Compiling log v0.4.14
   Compiling pin-project-lite v0.2.8
   Compiling futures-core v0.3.19
   Compiling proc-macro2 v1.0.36
   Compiling bytes v1.1.0
   Compiling lazy_static v1.4.0
   Compiling unicode-xid v0.2.2
   Compiling version_check v0.9.4
   Compiling itoa v1.0.1
   Compiling futures-task v0.3.19
   Compiling once_cell v1.9.0
   Compiling bitflags v1.3.2
   Compiling syn v1.0.85
   Compiling hashbrown v0.11.2
   Compiling serde v1.0.133
   Compiling openssl v0.10.38
   Compiling matches v0.1.9
   Compiling futures-util v0.3.19
   Compiling tinyvec_macros v0.1.0
   Compiling foreign-types-shared v0.1.1
   Compiling fnv v1.0.7
   Compiling native-tls v0.2.8
   Compiling httparse v1.5.1
   Compiling slab v0.4.5
   Compiling pin-utils v0.1.0
   Compiling percent-encoding v2.1.0
   Compiling openssl-probe v0.1.5
   Compiling futures-channel v0.3.19
   Compiling futures-io v0.3.19
   Compiling futures-sink v0.3.19
   Compiling try-lock v0.2.3
   Compiling itoa v0.4.8
   Compiling unicode-bidi v0.3.7
   Compiling quick-error v1.2.3
   Compiling ryu v1.0.9
   Compiling httpdate v1.0.2
   Compiling encoding_rs v0.8.30
   Compiling serde_json v1.0.74
   Compiling tower-service v0.3.1
   Compiling termcolor v1.1.2
   Compiling regex-syntax v0.6.25
   Compiling serde_derive v1.0.133
   Compiling semver v1.0.4
   Compiling heck v0.4.0
   Compiling remove_dir_all v0.5.3
   Compiling ipnet v2.3.1
   Compiling textwrap v0.14.2
   Compiling mime v0.3.16
   Compiling base64 v0.13.0
   Compiling strsim v0.10.0
   Compiling fastrand v1.6.0
   Compiling edit-distance v2.1.0
   Compiling tracing-core v0.1.21
   Compiling thread_local v1.1.3
   Compiling tinyvec v1.5.1
   Compiling foreign-types v0.3.2
   Compiling form_urlencoded v1.0.1
   Compiling indexmap v1.8.0
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling http v0.2.6
   Compiling humantime v1.3.0
   Compiling fuzzy-matcher v0.3.7
   Compiling tracing v0.1.29
   Compiling want v0.3.0
   Compiling unicode-normalization v0.1.19
   Compiling aho-corasick v0.7.18
   Compiling os_str_bytes v6.0.0
   Compiling quote v1.0.14
   Compiling jobserver v0.1.24
   Compiling num_cpus v1.13.1
   Compiling mio v0.7.14
   Compiling atty v0.2.14
   Compiling socket2 v0.4.2
   Compiling dirs-sys v0.3.6
   Compiling dirs-sys-next v0.1.2
   Compiling tempfile v3.3.0
   Compiling cc v1.0.72
   Compiling http-body v0.4.4
   Compiling colored v2.0.0
   Compiling dirs v3.0.2
   Compiling dirs-next v2.0.0
   Compiling tokio v1.15.0
   Compiling regex v1.5.4
   Compiling idna v0.2.3
   Compiling xdg v2.4.0
   Compiling url v2.2.2
   Compiling openssl-sys v0.9.72
   Compiling libz-sys v1.1.3
   Compiling libssh2-sys v0.2.23
   Compiling libgit2-sys v0.12.26+1.3.0
   Compiling env_logger v0.7.1
   Compiling serde_urlencoded v0.7.0
   Compiling toml v0.5.8
   Compiling pretty_env_logger v0.4.0
   Compiling tokio-util v0.6.9
   Compiling h2 v0.3.10
   Compiling clap_derive v3.0.6
   Compiling tokio-native-tls v0.3.0
   Compiling clap v3.0.7
   Compiling hyper v0.14.16
   Compiling hyper-tls v0.5.0
   Compiling reqwest v0.11.9
   Compiling git2 v0.13.25
   Compiling leftwm-theme v0.1.1 (/build/source)
    Finished release [optimized] target(s) in 1m 05s
Executing cargoInstallPostBuildHook
Finished cargoInstallPostBuildHook
Finished cargoBuildHook
@nix { "action": "setPhase", "phase": "checkPhase" }
running tests
Executing cargoCheckHook
++ cargo test -j 16 --release --target x86_64-unknown-linux-gnu --frozen -- --test-threads=16
   Compiling leftwm-theme v0.1.1 (/build/source)
    Finished release [optimized] target(s) in 6.37s
     Running unittests (target/x86_64-unknown-linux-gnu/release/deps/leftwm_theme-476c5e05ff28a653)

running 15 tests
test models::config::test::test_config_default ... ok
test models::config::test::test_config_new ... FAILED
test models::config::test::test_current_theme_no_themes_dir ... ok
test models::config::test::test_current_theme_current_file ... ok
test operations::search::test::test_match ... ok
test models::config::test::test_installed_themes_no_themes_dir ... ok
test models::theme::test::test_apply_change_rename_dir_existing_theme ... ok
test models::theme::test::test_apply_change_rename_dir_no_existing_theme ... ok
test models::config::test::test_current_theme_no_current ... ok
test models::config::test::test_current_theme_unmanaged ... ok
test models::config::test::test_config_update_local_repo ... ok
test models::config::test::test_current_theme ... ok
test models::config::test::test_installed_themes ... ok
test operations::new::test::test_name_validation ... ok
test operations::update::test::test_update_repos ... FAILED

failures:

---- models::config::test::test_config_new stdout ----
thread 'models::config::test::test_config_new' panicked at 'called `Result::unwrap()` on an `Err` value: LeftError { inner: IoError(Os { code: 13, kind: PermissionDenied, message: "Permission denied" }) }', src/models/config.rs:511:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- operations::update::test::test_update_repos stdout ----
Fetching themes . . . 
thread 'operations::update::test::test_update_repos' panicked at 'assertion failed: Update::update_repos(&mut config).is_ok()', src/operations/update.rs:153:9


failures:
    models::config::test::test_config_new
    operations::update::test::test_update_repos

test result: FAILED. 13 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass '--bin leftwm-theme'

I don't know what to make of it, I don't know Rust too well. @mautamu may know better.

@mautamu
Copy link
Member

mautamu commented Jan 23, 2022

Hmm, what are the permissions on ~/.config/leftwm/ in this case? It appears that it's failing to create a themes.toml file there. If you apply this diff, does it work properly?

diff --git a/src/models/config.rs b/src/models/config.rs
index 1c1b73c..3c1c59a 100644
--- a/src/models/config.rs
+++ b/src/models/config.rs
@@ -507,7 +507,7 @@ mod test {

     #[test]
     fn test_config_new() {
-        let config1 = Config::new(None);
+        /*let config1 = Config::new(None);
         assert!(config1.config_dir.is_none());
         assert!(config1
             .get_config_dir()
@@ -515,7 +515,7 @@ mod test {
             .to_str()
             .unwrap()
             .ends_with("/.config/leftwm/"));
-
+        */
         let config2 = Config::new(Some(PathBuf::from("/tmp/foo")));
         assert!(config2.config_dir.is_some());
         assert!(config2

@water-sucks
Copy link

I'm coming back to this issue quite late, sorry about that. I tried building with the latest rev, also with that patch, and ran into one single failed test, test_update_repos. Here's the relevant section (though it looks the same as before):

Executing cargoCheckHook
++ cargo test -j 32 --release --target x86_64-unknown-linux-gnu --frozen -- --test-threads=32
   Compiling leftwm-theme v0.1.1 (/build/source)
    Finished release [optimized] target(s) in 5.81s
     Running unittests src/main.rs (target/x86_64-unknown-linux-gnu/release/deps/leftwm_theme-689f9beb41615369)

running 15 tests
test models::config::test::test_config_new ... ok
test models::config::test::test_config_default ... ok
test models::config::test::test_current_theme_no_themes_dir ... ok
test models::theme::test::test_apply_change_rename_dir_no_existing_theme ... ok
test models::config::test::test_current_theme_current_file ... ok
test models::config::test::test_installed_themes_no_themes_dir ... ok
test operations::search::test::test_match ... ok
test models::theme::test::test_apply_change_rename_dir_existing_theme ... ok
test models::config::test::test_current_theme_no_current ... ok
test models::config::test::test_current_theme_unmanaged ... ok
test models::config::test::test_current_theme ... ok
test models::config::test::test_installed_themes ... ok
test models::config::test::test_config_update_local_repo ... ok
test operations::new::test::test_name_validation ... ok
test operations::update::test::test_update_repos ... FAILED

failures:

---- operations::update::test::test_update_repos stdout ----
Fetching themes . . . 
thread 'operations::update::test::test_update_repos' panicked at 'assertion failed: Update::update_repos(&mut config).is_ok()', src/operations/update.rs:179:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    operations::update::test::test_update_repos

test result: FAILED. 14 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

error: test failed, to rerun pass '--bin leftwm-theme'

After reading the test a bit, I saw this section of code, and I think I know what's going on:

 let mut config: Config = Config {
    repos: vec![
        Repo {
            definitions_version: crate::models::config::CURRENT_DEFINITIONS_VERSION,
            url: String::from(local_file_url.as_str()),
            name: String::from("test-repo"),
            themes: Vec::new(),
        },
        Repo {
            definitions_version: crate::models::config::CURRENT_DEFINITIONS_VERSION,
            url: String::from("https://raw.githubusercontent.com/leftwm/leftwm-community-themes/master/known.toml"),
            name: String::from("community"),
            themes: Vec::new(),
        },
    ],
    config_dir: Some(tmpdir.path().to_path_buf()),
};

While I don't know exactly what the URL parameter is, I do know that most Internet access during testing outside of the specialized builtin fetchers is forbidden by the Nix sandbox, and the test and building succeeds when the sandbox is disabled. If there's a way we can rewrite the test such that it doesn't require access to that raw.githubusercontent.com URL, then I can upstream it to nixpkgs myself, or if that's not possible, then maybe disabling tests is an option (or patching out that test specifically), but I'm not sure how I can rewrite the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants