-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installer: add support for flatpakref. (#80)
Adds support for installing application from a flatpakref uri.
- Loading branch information
Showing
7 changed files
with
252 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# utiliy function to manage flatpakref files | ||
{ lib, ... }: | ||
let | ||
# check if a value is a string | ||
isString = value: builtins.typeOf value == "string"; | ||
|
||
# Check if a package declares a flatpakref | ||
isFlatpakref = { flatpakref ? null, ... }: | ||
flatpakref != null && isString flatpakref; | ||
|
||
# sanitize a URL to be used as a key in an attrset. | ||
sanitizeUrl = url: builtins.replaceStrings [ "https://" "/" "." ":" ] [ "https_" "_" "_" "_" ] url; | ||
|
||
# Extract the remote name from a package that declares a flatpakref: | ||
# 1. if the package sets an origin, use that as label for the remote url. | ||
# 2. if the package does not set an origin, use the remote name suggested by the flatpakref. | ||
# 3. if the package does not set an origin and the flatpakref does not suggest a remote name, sanitize application Name. | ||
getRemoteNameFromFlatpakref = origin: cache: | ||
let | ||
remoteName = origin; | ||
in | ||
if remoteName == null | ||
then | ||
let | ||
flatpakrefdName = | ||
if builtins.hasAttr "SuggestRemoteName" cache | ||
then cache.SuggestRemoteName | ||
else "${lib.toLower cache.Name}-origin"; | ||
in | ||
flatpakrefdName | ||
else | ||
remoteName; | ||
|
||
# Fetch and convert an ini-like flatpakref file into an attrset, and cache it for future use | ||
# within the same activation. | ||
# We piggyback on builtins.fetchurl to fetch and cache flatpakref file. Pure nix evaluations | ||
# requrie a sha256 hash to be provided. | ||
# TODO: extract a generic ini-to-attrset function. | ||
flatpakrefToAttrSet = { flatpakref, sha256, ... }: cache: | ||
let | ||
updatedCache = | ||
if builtins.hasAttr (sanitizeUrl flatpakref) cache then | ||
cache | ||
else | ||
let | ||
fetchurlArgs = | ||
if sha256 != null | ||
then { url = flatpakref; sha256 = sha256; } | ||
else { url = flatpakref; }; | ||
iniContent = builtins.readFile (builtins.fetchurl fetchurlArgs); | ||
lines = builtins.split "\r?\n" iniContent; | ||
parsed = builtins.filter (line: line != null) (map (line: builtins.match "(.*)=(.*)" (builtins.toString line)) lines); | ||
|
||
# Convert the list of key-value pairs into an attrset | ||
attrSet = builtins.listToAttrs (map (pair: { name = builtins.elemAt pair 0; value = builtins.elemAt pair 1; }) parsed); | ||
in | ||
cache // { ${(sanitizeUrl flatpakref)} = attrSet; }; | ||
in | ||
updatedCache; | ||
in | ||
{ | ||
inherit isFlatpakref sanitizeUrl flatpakrefToAttrSet getRemoteNameFromFlatpakref; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Flatpak Ref] | ||
Title=gedit | ||
Name=org.gnome.gedit | ||
Branch=stable | ||
Url=http://sdk.gnome.org/repo-apps/ | ||
IsRuntime=false | ||
GPGKey=REDACTED | ||
DeployCollectionID=org.gnome.Apps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ pkgs ? import <nixpkgs> { } }: | ||
|
||
let | ||
inherit (pkgs) lib; | ||
inherit (lib) runTests; | ||
ref = import ../modules/ref.nix { inherit lib; }; | ||
|
||
pwd = builtins.getEnv "PWD"; | ||
fixturePath = "file://${pwd}/fixtures/package.flatpakref"; | ||
fixtureHash = "040iig2yg2i28s5xc9cvp5syaaqq165idy3nhlpv8xn4f6zh4h1f"; | ||
expectedFixtureAttrSet = { | ||
${ref.sanitizeUrl fixturePath} = { | ||
Title = "gedit"; | ||
Name = "org.gnome.gedit"; | ||
Branch = "stable"; | ||
Url = "http://sdk.gnome.org/repo-apps/"; | ||
IsRuntime = "false"; | ||
GPGKey = "REDACTED"; | ||
DeployCollectionID = "org.gnome.Apps"; | ||
}; | ||
}; | ||
in | ||
runTests { | ||
testSanitizeUrl = { | ||
expr = ref.sanitizeUrl "https://example.local"; | ||
expected = "https_example_local"; | ||
}; | ||
|
||
testIsFlatpakref = { | ||
expr = ref.isFlatpakref { flatpakref = "https://example.local/package.flatpakref"; }; | ||
expected = true; | ||
}; | ||
|
||
testIsFlatpakrefWithNull = { | ||
expr = ref.isFlatpakref { flatpakref = null; }; | ||
expected = false; | ||
}; | ||
|
||
testIsFlatpakrefWithMissing = { | ||
expr = ref.isFlatpakref { appId = "local.example.Package"; }; | ||
expected = false; | ||
}; | ||
|
||
testGetRemoteNameWithOrigin = { | ||
expr = ref.getRemoteNameFromFlatpakref "example" { SuggestRemoteName = "local"; }; | ||
expected = "example"; | ||
}; | ||
|
||
testGetRemoteNameWithSuggestedName = { | ||
expr = ref.getRemoteNameFromFlatpakref null { SuggestRemoteName = "local"; }; | ||
expected = "local"; | ||
}; | ||
|
||
testGetRemoteNameWithPackageName = { | ||
expr = ref.getRemoteNameFromFlatpakref null { Name = "Example"; }; | ||
expected = "example-origin"; | ||
}; | ||
|
||
testFlatpakrefToAttrSet = { | ||
expr = ref.flatpakrefToAttrSet { flatpakref = fixturePath; sha256 = null; } { }; | ||
expected = expectedFixtureAttrSet; | ||
}; | ||
|
||
testFlatpakrefToAttrSetWithSha256 = { | ||
expr = ref.flatpakrefToAttrSet { flatpakref = fixturePath; sha256 = fixtureHash; } { }; | ||
expected = expectedFixtureAttrSet; | ||
}; | ||
} |