feat: nix flake

This commit is contained in:
Nova
2024-04-13 18:11:23 -04:00
parent c582c85a1a
commit 37c3403dbd
27 changed files with 100 additions and 590 deletions

View File

@@ -34,7 +34,7 @@ async fn main() -> Result<()> {
.pretty() .pretty()
.init(); .init();
let (client, event_loop) = Client::connect_with_async_loop().await?; let (client, event_loop) = Client::connect_with_async_loop().await?;
client.set_base_prefixes(&[directory_relative_path!("res")]); client.set_base_prefixes(&[directory_relative_path!("../res")]);
let _root = client.wrap_root(AppGrid::new(&client))?; let _root = client.wrap_root(AppGrid::new(&client))?;

48
flake.lock generated Normal file
View File

@@ -0,0 +1,48 @@
{
"nodes": {
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1712681629,
"narHash": "sha256-bMDXn4AkTXLCpoZbII6pDGoSeSe9gI87jxPsHRXgu/E=",
"owner": "ipetkov",
"repo": "crane",
"rev": "220387ac8e99cbee0ca4c95b621c4bc782b6a235",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1712791164,
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"crane": "crane",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

39
flake.nix Normal file
View File

@@ -0,0 +1,39 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:ipetkov/crane";
};
};
outputs = { self, nixpkgs, crane }:
let supportedSystems = [ "aarch64-linux" "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in {
default = crane.lib.${system}.buildPackage {
pname = "protostar";
version = "0.1.0";
src = ./.;
cargoTestCommand = "echo \"looks good to me\"";
STARDUST_RES_PREFIXES = pkgs.stdenvNoCC.mkDerivation {
name = "resources";
src = ./.;
buildPhase = "cp -r $src/res $out";
};
# for tests
nativeBuildInputs = with pkgs; [
ashpd-demo
];
XDG_CACHE_HOME = "/tmp";
};
});
};
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -1,286 +0,0 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v3.6.6",
"version":"2.0"
},
"extensionsUsed":[
"KHR_materials_unlit"
],
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0,
1
]
}
],
"nodes":[
{
"mesh":0,
"name":"Icon"
},
{
"mesh":1,
"name":"Hex"
}
],
"materials":[
{
"alphaCutoff":0.5,
"alphaMode":"MASK",
"extensions":{
"KHR_materials_unlit":{}
},
"name":"Icon",
"pbrMetallicRoughness":{
"baseColorTexture":{
"index":0,
"texCoord":0
},
"metallicFactor":0,
"roughnessFactor":0.9
}
},
{
"alphaMode":"BLEND",
"extensions":{
"KHR_materials_unlit":{}
},
"name":"Hex",
"pbrMetallicRoughness":{
"baseColorFactor":[
0.9720873236656189,
0.018567396327853203,
0.017742767930030823,
1
],
"baseColorTexture":{
"index":1,
"texCoord":0
},
"metallicFactor":0,
"roughnessFactor":0.9
}
}
],
"meshes":[
{
"name":"Circle",
"primitives":[
{
"attributes":{
"COLOR_0":0,
"POSITION":1,
"TEXCOORD_0":2,
"NORMAL":3
},
"indices":4,
"material":0
}
]
},
{
"name":"Circle.001",
"primitives":[
{
"attributes":{
"COLOR_0":5,
"POSITION":6,
"TEXCOORD_0":7,
"NORMAL":8
},
"indices":9,
"material":1
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
},
{
"sampler":1,
"source":1
}
],
"images":[
{
"mimeType":"image/png",
"name":"icon_test",
"uri":"icon_test.png"
},
{
"mimeType":"image/png",
"name":"hex_atlas",
"uri":"hex_atlas.png"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5123,
"count":4,
"normalized":true,
"type":"VEC4"
},
{
"bufferView":1,
"componentType":5126,
"count":4,
"max":[
0.5853440165519714,
0.05000000074505806,
0.5853440165519714
],
"min":[
-0.5853440165519714,
0.05000000074505806,
-0.5853440165519714
],
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":4,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5126,
"count":4,
"type":"VEC3"
},
{
"bufferView":4,
"componentType":5123,
"count":6,
"type":"SCALAR"
},
{
"bufferView":5,
"componentType":5123,
"count":54,
"normalized":true,
"type":"VEC4"
},
{
"bufferView":6,
"componentType":5126,
"count":54,
"max":[
1.0166369676589966,
0.021040409803390503,
0.8804334998130798
],
"min":[
-1.0166369676589966,
-7.071532309055328e-06,
-0.8804334998130798
],
"type":"VEC3"
},
{
"bufferView":7,
"componentType":5126,
"count":54,
"type":"VEC2"
},
{
"bufferView":8,
"componentType":5126,
"count":54,
"type":"VEC3"
},
{
"bufferView":9,
"componentType":5123,
"count":84,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":32,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":48,
"byteOffset":32,
"target":34962
},
{
"buffer":0,
"byteLength":32,
"byteOffset":80,
"target":34962
},
{
"buffer":0,
"byteLength":48,
"byteOffset":112,
"target":34962
},
{
"buffer":0,
"byteLength":12,
"byteOffset":160,
"target":34963
},
{
"buffer":0,
"byteLength":432,
"byteOffset":172,
"target":34962
},
{
"buffer":0,
"byteLength":648,
"byteOffset":604,
"target":34962
},
{
"buffer":0,
"byteLength":432,
"byteOffset":1252,
"target":34962
},
{
"buffer":0,
"byteLength":648,
"byteOffset":1684,
"target":34962
},
{
"buffer":0,
"byteLength":168,
"byteOffset":2332,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987,
"wrapS":33071,
"wrapT":33071
},
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":2500,
"uri":"hexagon.bin"
}
]
}

View File

@@ -37,7 +37,7 @@ async fn main() -> Result<()> {
.pretty() .pretty()
.init(); .init();
let (client, event_loop) = Client::connect_with_async_loop().await?; let (client, event_loop) = Client::connect_with_async_loop().await?;
client.set_base_prefixes(&[directory_relative_path!("res")]); client.set_base_prefixes(&[directory_relative_path!("../res")]);
let _root = client.wrap_root(AppHexGrid::new(&client).await)?; let _root = client.wrap_root(AppHexGrid::new(&client).await)?;

View File

@@ -94,9 +94,10 @@ pub fn get_desktop_files() -> impl Iterator<Item = PathBuf> {
#[test] #[test]
fn test_get_desktop_files() { fn test_get_desktop_files() {
let mut desktop_files = get_desktop_files(); let desktop_files = get_desktop_files().collect::<Vec<_>>();
assert!(desktop_files.any(|file| file.ends_with("gimp.desktop"))); assert!(desktop_files
dbg!(desktop_files.collect::<Vec<PathBuf>>()); .iter()
.any(|file| file.ends_with("com.belmoussaoui.ashpd.demo.desktop")));
} }
pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> { pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
@@ -213,7 +214,9 @@ const ICON_SIZES: [u16; 7] = [512, 256, 128, 64, 48, 32, 24];
impl DesktopFile { impl DesktopFile {
pub fn get_icon(&self, preferred_px_size: u16) -> Option<Icon> { pub fn get_icon(&self, preferred_px_size: u16) -> Option<Icon> {
// Get the name of the icon from the DesktopFile struct // Get the name of the icon from the DesktopFile struct
let Some(icon_name) = self.icon.as_ref() else { return None }; let Some(icon_name) = self.icon.as_ref() else {
return None;
};
let test_icon_path = self.path.join(Path::new(icon_name)); let test_icon_path = self.path.join(Path::new(icon_name));
if test_icon_path.exists() { if test_icon_path.exists() {
if let Some(icon) = Icon::from_path(test_icon_path, preferred_px_size) { if let Some(icon) = Icon::from_path(test_icon_path, preferred_px_size) {
@@ -331,23 +334,15 @@ fn test_get_icon_path() {
name: None, name: None,
command: None, command: None,
categories: vec![], categories: vec![],
icon: Some("krita".into()), icon: Some("com.belmoussaoui.ashpd.demo".into()),
no_display: false, no_display: false,
}; };
// Call the get_icon_path() function with a size argument and store the result // Call the get_icon_path() function with a size argument and store the result
let icon = desktop_file.get_icon(32); let icon = desktop_file.get_icon(32);
dbg!(&icon);
// Assert that the get_icon_path() function returns the expected result // Assert that the get_icon_path() function returns the expected result
assert!( assert!(icon.is_some());
icon.unwrap()
== Icon::from_path(
PathBuf::from("/usr/share/icons/hicolor/32x32/apps/krita.png"),
32
)
.unwrap()
);
} }
pub fn get_image_cache_dir() -> PathBuf { pub fn get_image_cache_dir() -> PathBuf {

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

View File

@@ -26,7 +26,7 @@ async fn main() -> Result<()> {
color_eyre::install()?; color_eyre::install()?;
let args = Args::parse(); let args = Args::parse();
let (client, event_loop) = Client::connect_with_async_loop().await?; let (client, event_loop) = Client::connect_with_async_loop().await?;
client.set_base_prefixes(&[directory_relative_path!("res")]); client.set_base_prefixes(&[directory_relative_path!("../res")]);
let protostar = Single::create_from_desktop_file( let protostar = Single::create_from_desktop_file(
client.get_root(), client.get_root(),

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -1,286 +0,0 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v3.5.30",
"version":"2.0"
},
"extensionsUsed":[
"KHR_materials_unlit"
],
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0,
1
]
}
],
"nodes":[
{
"mesh":0,
"name":"Icon"
},
{
"mesh":1,
"name":"Hex"
}
],
"materials":[
{
"alphaCutoff":0.5,
"alphaMode":"MASK",
"extensions":{
"KHR_materials_unlit":{}
},
"name":"Icon",
"pbrMetallicRoughness":{
"baseColorTexture":{
"index":0,
"texCoord":0
},
"metallicFactor":0,
"roughnessFactor":0.9
}
},
{
"alphaMode":"BLEND",
"extensions":{
"KHR_materials_unlit":{}
},
"name":"Hex",
"pbrMetallicRoughness":{
"baseColorFactor":[
1,
0,
0,
1
],
"baseColorTexture":{
"index":1,
"texCoord":0
},
"metallicFactor":0,
"roughnessFactor":0.9
}
}
],
"meshes":[
{
"name":"Circle",
"primitives":[
{
"attributes":{
"COLOR_0":0,
"POSITION":1,
"TEXCOORD_0":2,
"NORMAL":3
},
"indices":4,
"material":0
}
]
},
{
"name":"Circle.001",
"primitives":[
{
"attributes":{
"COLOR_0":5,
"POSITION":6,
"TEXCOORD_0":7,
"NORMAL":8
},
"indices":9,
"material":1
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
},
{
"sampler":1,
"source":1
}
],
"images":[
{
"mimeType":"image/png",
"name":"icon_test",
"uri":"icon_test.png"
},
{
"mimeType":"image/png",
"name":"hex_atlas",
"uri":"hex_atlas.png"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5123,
"count":4,
"normalized":true,
"type":"VEC4"
},
{
"bufferView":1,
"componentType":5126,
"count":4,
"max":[
0.5853440165519714,
0.05000000074505806,
0.5853440165519714
],
"min":[
-0.5853440165519714,
0.05000000074505806,
-0.5853440165519714
],
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":4,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5126,
"count":4,
"type":"VEC3"
},
{
"bufferView":4,
"componentType":5123,
"count":6,
"type":"SCALAR"
},
{
"bufferView":5,
"componentType":5123,
"count":54,
"normalized":true,
"type":"VEC4"
},
{
"bufferView":6,
"componentType":5126,
"count":54,
"max":[
1.0441828966140747,
0.05000000074505806,
0.9042890667915344
],
"min":[
-1.0441828966140747,
0,
-0.9042890667915344
],
"type":"VEC3"
},
{
"bufferView":7,
"componentType":5126,
"count":54,
"type":"VEC2"
},
{
"bufferView":8,
"componentType":5126,
"count":54,
"type":"VEC3"
},
{
"bufferView":9,
"componentType":5123,
"count":84,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":32,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":48,
"byteOffset":32,
"target":34962
},
{
"buffer":0,
"byteLength":32,
"byteOffset":80,
"target":34962
},
{
"buffer":0,
"byteLength":48,
"byteOffset":112,
"target":34962
},
{
"buffer":0,
"byteLength":12,
"byteOffset":160,
"target":34963
},
{
"buffer":0,
"byteLength":432,
"byteOffset":172,
"target":34962
},
{
"buffer":0,
"byteLength":648,
"byteOffset":604,
"target":34962
},
{
"buffer":0,
"byteLength":432,
"byteOffset":1252,
"target":34962
},
{
"buffer":0,
"byteLength":648,
"byteOffset":1684,
"target":34962
},
{
"buffer":0,
"byteLength":168,
"byteOffset":2332,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987,
"wrapS":33071,
"wrapT":33071
},
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":2500,
"uri":"hexagon.bin"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

View File

@@ -49,7 +49,7 @@ async fn main() -> Result<()> {
} }
let (client, event_loop) = Client::connect_with_async_loop().await?; let (client, event_loop) = Client::connect_with_async_loop().await?;
client.set_base_prefixes(&[directory_relative_path!("res")]); client.set_base_prefixes(&[directory_relative_path!("../res")]);
let _wrapped_root = client.wrap_root(Sirius::new(&client, args)?)?; let _wrapped_root = client.wrap_root(Sirius::new(&client, args)?)?;