Skip to content

Commit

Permalink
Add flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkecan committed Sep 28, 2021
1 parent 799041d commit 53610d4
Show file tree
Hide file tree
Showing 11 changed files with 568 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ tools/freetype-tools/FreeType-Emscripten

**/*.eez-project-ui-state
**/*.eez-project-runtime-settings

# nix build
/result*
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,23 @@ Download `eezstudio-mac.zip`, unpack and move `eezstudio.app` to Applications.

Download and start `EEZ_Studio_setup.exe`.

### Nix
There is a Nix flake that provides a derivation for EEZ Studio or an overlay
that provides that derivation. They can be used to install the project using
[Nix package manager](https://nixos.org/).

### Build and run from source (all operating systems)

- Install `Node.JS 8.9.x` or newer
- Install `node-gyp`, more information at https://github.com/nodejs/node-gyp#installation

Only Linux:
#### Only Linux:

```
sudo apt-get install build-essential libudev-dev
```

All platforms:
#### All platforms:

```
git clone https://github.com/eez-open/studio
Expand All @@ -119,6 +124,17 @@ Create distribution packages:
npm run dist
```

#### Nix
To build:
```
nix build 'github:eez-open/studio'
```

To start:
```
nix run 'github:eez-open/studio'
```

## USB TMC

### Windows
Expand Down
109 changes: 109 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
description = "Cross-platform visual development tool and SCPI instrument controller";

inputs = {
nixpkgs.url = "nixpkgs/nixos-21.05";
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
npmlock2nix = {
url = "github:ilkecan/npmlock2nix/";
flake = false;
};
nix-utils.url = "git+https://git.sr.ht/~ilkecan/nix-utils";
};

outputs = { self, nixpkgs, flake-utils, npmlock2nix, ... }@inputs:
let
inherit (builtins)
attrNames
attrValues
;
inherit (nixpkgs.lib)
getAttrs
;
inherit (flake-utils.lib)
defaultSystems
eachSystem
;
nix-filter = inputs.nix-filter.lib;
nix-utils = inputs.nix-utils.lib;
inherit (nix-utils)
createOverlays
getUnstableVersion
;

supportedSystems = defaultSystems;
commonArgs = {
version = getUnstableVersion self.lastModifiedDate;
homepage = "https://github.com/eez-open/studio";
downloadPage = "https://github.com/eez-open/studio/releases";
changelog = null;
maintainers = [
{
name = "ilkecan bozdogan";
email = "[email protected]";
github = "ilkecan";
githubId = "40234257";
}
];
platforms = supportedSystems;
};

derivations = {
eez-studio = import ./nix/eez-studio.nix commonArgs;
};
in
{
overlays = createOverlays derivations {
inherit
nix-filter
nix-utils
;
};
overlay = self.overlays.eez-studio;
} // eachSystem supportedSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = attrValues self.overlays ++ [
(final: prev: { npmlock2nix = import npmlock2nix { pkgs = prev; }; })
];
};

packageNames = attrNames derivations;
in
rec {
checks = packages;

packages = getAttrs packageNames pkgs;
defaultPackage = packages.eez-studio;

hydraJobs = {
build = packages;
};

devShell =
let
packageList = attrValues packages;
in
pkgs.mkShell {
packages = packageList;

shellHook = ''
$(${defaultPackage.preConfigure}) || true
export PATH=./node_modules/.bin:$PATH
'';
};
});
}
137 changes: 137 additions & 0 deletions nix/eez-studio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{ version
, homepage
, downloadPage
, changelog
, maintainers
, platforms
}:
{ lib
, electron
, makeWrapper
, nix-filter
, nix-utils
, nodejs
, npmlock2nix
, stdenv
, symlinkJoin
, ...
}@pkgs:

let
inherit (builtins)
concatStringsSep
map
;
inherit (lib) importJSON;
inherit (nix-utils) getPatches;
inherit (npmlock2nix.internal) add_node_modules_to_cwd;
inherit (nix-filter) inDirectory;
inherit (import ./electron-lib.nix pkgs)
electronBuilderUnpackedDirname
getElectronExecutable
symlinkElectron
;

# Reading the files in the filtered directory is not possible right now.
# Follow up on how https://github.com/NixOS/nix/pull/5163 will be resolved.
src = ./..;
packageJson = importJSON "${toString src}/package.json";
pname = packageJson.name;
mainProgram = pname;

symlinkedElectron = symlinkElectron electron;

nm = import ./node_modules.nix {
inherit src nodejs;
electron = symlinkedElectron;
} pkgs;
in

stdenv.mkDerivation {
inherit pname version;

src = nix-filter {
root = src;
include = [
"gulpfile.js"
"icon.icns"
"icon.ico"
"package-lock.json"
"package.json"
"resources/expression-grammar.pegjs"
"tsconfig.json"
(inDirectory "installation")
(inDirectory "libs")
(inDirectory "packages")
];
name = pname;
};

NO_UPDATE_NOTIFIER = 1;

buildInputs = [ nm.out ];

nativeBuildInputs = [
makeWrapper.out
];

patches = getPatches ./patches;

# couldn't make it work with symlink. may be related to this
# https://github.com/microsoft/TypeScript/issues/29518
# although the error is different
preConfigure = add_node_modules_to_cwd nm "copy";

buildPhase =
let
extraResources = import ./extra-resources { inherit lib; };

createSymlink = target: linkName: "ln -s ${target} ${linkName}";
symlinkEach = files:
let
lines = map ({ filename, storePath }: createSymlink storePath filename) files;
in
concatStringsSep "\n" lines;
in
''
extraResourcesPath="installation/extra-resources"
mkdir -p $extraResourcesPath
pushd $extraResourcesPath
${symlinkEach extraResources}
popd
npm run build
npx --no-install electron-builder \
--config.electronVersion="${electron.version}" \
--config.electronDist="${symlinkedElectron}/lib/electron" \
--dir
'';

installPhase = ''
mkdir -p $out/lib/${pname}
resourcesDir=$out/lib/${pname}/resources
mv ./dist/${electronBuilderUnpackedDirname}/resources $resourcesDir
mkdir -p $out/bin
makeWrapper '${getElectronExecutable electron}' "$out/bin/${mainProgram}" \
--set ELECTRON_RESOURCES_PATH $resourcesDir \
--add-flags "$resourcesDir/app.asar"
'';

meta = {
description = packageJson.description;
longDescription =
"The EEZ Studio is an open source cross-platform modular visual tool" +
"aimed to address various programming and management tasks for EEZ BB3" +
"open source T&M chassis and EEZ H24005 programmable power supply and" +
"other T&M devices that support SCPI from manufacturers such as" +
"Keysight, Rigol, Siglent, etc.";

inherit homepage downloadPage changelog;

license = lib.licenses.gpl3Only;
inherit maintainers mainProgram platforms;
};
}
Loading

0 comments on commit 53610d4

Please sign in to comment.